Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(contexts): Use newly added computed contexts #80579

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/sentry/interfaces/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ def change_type(self, value: int | float | list | dict) -> Any:
return value


# NOTE:
# If you are adding a new context to tag mapping which creates a tag out of an interpolation
# of multiple context fields, you will most likely have to add the same mapping creation in Relay,
# which should be added directly to the context payload itself, and you should reflect this here.
#
# Current examples of this include the `os`, `runtime` and `browser` fields of their respective context.
#
# Example:
# Suppose you have a new context named "my_context" which has fields:
# - "field_1"
# - "field_2"
#
# And you want to create a tag named "field_3" which is equal to "{field_1}-{field_2}".
#
# If you do this here, on demand metrics will stop working because if a user filters by "field_3" and
# we generate a metrics extraction specification for it, Relay won't know what "field_3" means, it will
# only know "field_1" and "field_2" from the context.
#
# To solve this, you should materialize "field_3" during event normalization in Relay and directly express
# the mapping in Sentry as "field_3" is equal to "field_3" (which was added by Relay during normalization).


# TODO(dcramer): contexts need to document/describe expected (optional) fields
@contexttype
class DefaultContextType(ContextType):
Expand All @@ -168,20 +190,20 @@ class DeviceContextType(ContextType):
@contexttype
class RuntimeContextType(ContextType):
type = "runtime"
context_to_tag_mapping = {"": "{name} {version}", "name": "{name}"}
context_to_tag_mapping = {"": "{runtime}", "name": "{name}"}


@contexttype
class BrowserContextType(ContextType):
type = "browser"
context_to_tag_mapping = {"": "{name} {version}", "name": "{name}"}
context_to_tag_mapping = {"": "{browser}", "name": "{name}"}
# viewport


@contexttype
class OsContextType(ContextType):
type = "os"
context_to_tag_mapping = {"": "{name} {version}", "name": "{name}", "rooted": "{rooted}"}
context_to_tag_mapping = {"": "{os}", "name": "{name}", "rooted": "{rooted}"}
# build, rooted


Expand Down
Loading