Skip to content

Commit 47054f4

Browse files
JoshuaMoelansandrewshie-sentry
authored andcommitted
fix: flatten searchable os distribution fields (#81297)
<!-- Describe your PR here. --> update to #69865 To search the distribution fields, we cannot have them in a hierarchy `os.distribution.name`, we instead need them flattened to `os.distribution_name` This is part of reworking the following native-SDK PR: getsentry/sentry-native#963 The update is also tracked on the docs side: getsentry/sentry-docs#11936 And on Relay: getsentry/relay#4292
1 parent 0e4cc30 commit 47054f4

File tree

3 files changed

+30
-45
lines changed

3 files changed

+30
-45
lines changed

src/sentry/rules/conditions/event_attribute.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def _handle(cls, path: list[str], event: GroupEvent) -> list[str]:
6363
"stacktrace.package": Columns.STACK_PACKAGE,
6464
"unreal.crashtype": Columns.UNREAL_CRASH_TYPE,
6565
"app.in_foreground": Columns.APP_IN_FOREGROUND,
66-
"os.distribution.name": Columns.OS_DISTRIBUTION_NAME,
67-
"os.distribution.version": Columns.OS_DISTRIBUTION_VERSION,
66+
"os.distribution_name": Columns.OS_DISTRIBUTION_NAME,
67+
"os.distribution_version": Columns.OS_DISTRIBUTION_VERSION,
6868
}
6969

7070

@@ -418,21 +418,14 @@ def _handle(cls, path: list[str], event: GroupEvent) -> list[str]:
418418

419419
@attribute_registry.register("os")
420420
class OsAttributeHandler(AttributeHandler):
421-
minimum_path_length = 3
421+
minimum_path_length = 2
422422

423423
@classmethod
424424
def _handle(cls, path: list[str], event: GroupEvent) -> list[str]:
425-
if path[1] in ("distribution"):
426-
if path[2] in ("name", "version"):
427-
contexts = event.data.get("contexts", {})
428-
os_context = contexts.get("os")
429-
if os_context is None:
430-
os_context = {}
431-
432-
distribution = os_context.get(path[1])
433-
if distribution is None:
434-
distribution = {}
435-
436-
return [distribution.get(path[2])]
437-
return []
425+
if path[1] in ("distribution_name", "distribution_version"):
426+
contexts = event.data.get("contexts", {})
427+
os_context = contexts.get("os")
428+
if os_context is None:
429+
os_context = {}
430+
return [os_context.get(path[1])]
438431
return []

src/sentry/snuba/events.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -601,20 +601,20 @@ class Columns(Enum):
601601
alias="app.in_foreground",
602602
)
603603
OS_DISTRIBUTION_NAME = Column(
604-
group_name="events.contexts[os.distribution.name]",
605-
event_name="contexts[os.distribution.name]",
606-
transaction_name="contexts[os.distribution.name]",
607-
discover_name="contexts[os.distribution.name]",
608-
issue_platform_name="contexts[os.distribution.name]",
609-
alias="os.distribution.name",
604+
group_name="events.contexts[os.distribution_name]",
605+
event_name="contexts[os.distribution_name]",
606+
transaction_name="contexts[os.distribution_name]",
607+
discover_name="contexts[os.distribution_name]",
608+
issue_platform_name="contexts[os.distribution_name]",
609+
alias="os.distribution_name",
610610
)
611611
OS_DISTRIBUTION_VERSION = Column(
612-
group_name="events.contexts[os.distribution.version]",
613-
event_name="contexts[os.distribution.version]",
614-
transaction_name="contexts[os.distribution.version]",
615-
discover_name="contexts[os.distribution.version]",
616-
issue_platform_name="contexts[os.distribution.version]",
617-
alias="os.distribution.version",
612+
group_name="events.contexts[os.distribution_version]",
613+
event_name="contexts[os.distribution_version]",
614+
transaction_name="contexts[os.distribution_version]",
615+
discover_name="contexts[os.distribution_version]",
616+
issue_platform_name="contexts[os.distribution_version]",
617+
alias="os.distribution_version",
618618
)
619619
# Transactions specific columns
620620
TRANSACTION_OP = Column(

tests/sentry/rules/conditions/test_event_attribute.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@ def get_event(self, **kwargs):
6464
"unreal": {
6565
"crash_type": "crash",
6666
},
67-
"os": {
68-
"distribution": {
69-
"name": "ubuntu",
70-
"version": "22.04",
71-
}
72-
},
67+
"os": {"distribution_name": "ubuntu", "distribution_version": "22.04"},
7368
},
7469
"threads": {
7570
"values": [
@@ -824,24 +819,21 @@ def test_app_in_foreground(self):
824819
)
825820
self.assertDoesNotPass(rule, event)
826821

827-
def test_os_distribution_only(self):
828-
event = self.get_event()
829-
rule = self.get_rule(
830-
data={"match": MatchType.EQUAL, "attribute": "os.distribution", "value": "irrelevant"}
831-
)
832-
self.assertDoesNotPass(rule, event)
833-
834822
def test_os_distribution_name_and_version(self):
835823
event = self.get_event()
836824
rule = self.get_rule(
837-
data={"match": MatchType.EQUAL, "attribute": "os.distribution.name", "value": "ubuntu"}
825+
data={
826+
"match": MatchType.EQUAL,
827+
"attribute": "os.distribution_name",
828+
"value": "ubuntu",
829+
}
838830
)
839831
self.assertPasses(rule, event)
840832

841833
rule = self.get_rule(
842834
data={
843835
"match": MatchType.EQUAL,
844-
"attribute": "os.distribution.version",
836+
"attribute": "os.distribution_version",
845837
"value": "22.04",
846838
}
847839
)
@@ -850,7 +842,7 @@ def test_os_distribution_name_and_version(self):
850842
rule = self.get_rule(
851843
data={
852844
"match": MatchType.EQUAL,
853-
"attribute": "os.distribution.name",
845+
"attribute": "os.distribution_name",
854846
"value": "slackware",
855847
}
856848
)
@@ -859,7 +851,7 @@ def test_os_distribution_name_and_version(self):
859851
rule = self.get_rule(
860852
data={
861853
"match": MatchType.EQUAL,
862-
"attribute": "os.distribution.version",
854+
"attribute": "os.distribution_version",
863855
"value": "20.04",
864856
}
865857
)

0 commit comments

Comments
 (0)