Skip to content

Commit 15b7125

Browse files
supervacuuscmanallen
authored andcommitted
Make os.distribution searchable (#69865)
Users of the Native SDK also want to search for the Linux distributions their events came from: getsentry/sentry-native#943 The corresponding PRs to * develop docs: getsentry/develop#1227 * relay: getsentry/relay#3443 * Native SDK: getsentry/sentry-native#963
1 parent 270de92 commit 15b7125

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

Diff for: src/sentry/rules/conditions/event_attribute.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"stacktrace.package": Columns.STACK_PACKAGE,
4040
"unreal.crashtype": Columns.UNREAL_CRASH_TYPE,
4141
"app.in_foreground": Columns.APP_IN_FOREGROUND,
42+
"os.distribution.name": Columns.OS_DISTRIBUTION_NAME,
43+
"os.distribution.version": Columns.OS_DISTRIBUTION_VERSION,
4244
}
4345

4446

@@ -112,8 +114,8 @@ def _get_attribute_values(self, event: GroupEvent, attr: str) -> Sequence[object
112114
return value
113115
return [value]
114116

115-
elif len(path) != 2:
116-
return []
117+
elif len(path) < 2:
118+
return [] # all attribute paths below have at least 2 elements
117119

118120
elif path[0] == "exception":
119121
if path[1] not in ("type", "value"):
@@ -211,6 +213,23 @@ def _get_attribute_values(self, event: GroupEvent, attr: str) -> Sequence[object
211213
response = {}
212214
return [response.get(path[1])]
213215

216+
elif len(path) < 3:
217+
return [] # all attribute paths below have at least 3 elements
218+
219+
elif path[0] == "os":
220+
if path[1] in ("distribution"):
221+
if path[2] in ("name", "version"):
222+
contexts = event.data["contexts"]
223+
os_context = contexts.get("os")
224+
if os_context is None:
225+
os_context = {}
226+
227+
distribution = os_context.get(path[1])
228+
if distribution is None:
229+
distribution = {}
230+
231+
return [distribution.get(path[2])]
232+
return []
214233
return []
215234

216235
return []

Diff for: src/sentry/snuba/events.py

+16
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,22 @@ class Columns(Enum):
600600
issue_platform_name="contexts[app.in_foreground]",
601601
alias="app.in_foreground",
602602
)
603+
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",
610+
)
611+
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",
618+
)
603619
# Transactions specific columns
604620
TRANSACTION_OP = Column(
605621
group_name=None,

Diff for: tests/sentry/rules/conditions/test_event_attribute.py

+47
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ def get_event(self, **kwargs):
5959
"unreal": {
6060
"crash_type": "crash",
6161
},
62+
"os": {
63+
"distribution": {
64+
"name": "ubuntu",
65+
"version": "22.04",
66+
}
67+
},
6268
},
6369
"threads": {
6470
"values": [
@@ -757,6 +763,47 @@ def test_app_in_foreground(self):
757763
)
758764
self.assertDoesNotPass(rule, event)
759765

766+
def test_os_distribution_only(self):
767+
event = self.get_event()
768+
rule = self.get_rule(
769+
data={"match": MatchType.EQUAL, "attribute": "os.distribution", "value": "irrelevant"}
770+
)
771+
self.assertDoesNotPass(rule, event)
772+
773+
def test_os_distribution_name_and_version(self):
774+
event = self.get_event()
775+
rule = self.get_rule(
776+
data={"match": MatchType.EQUAL, "attribute": "os.distribution.name", "value": "ubuntu"}
777+
)
778+
self.assertPasses(rule, event)
779+
780+
rule = self.get_rule(
781+
data={
782+
"match": MatchType.EQUAL,
783+
"attribute": "os.distribution.version",
784+
"value": "22.04",
785+
}
786+
)
787+
self.assertPasses(rule, event)
788+
789+
rule = self.get_rule(
790+
data={
791+
"match": MatchType.EQUAL,
792+
"attribute": "os.distribution.name",
793+
"value": "slackware",
794+
}
795+
)
796+
self.assertDoesNotPass(rule, event)
797+
798+
rule = self.get_rule(
799+
data={
800+
"match": MatchType.EQUAL,
801+
"attribute": "os.distribution.version",
802+
"value": "20.04",
803+
}
804+
)
805+
self.assertDoesNotPass(rule, event)
806+
760807
def test_unreal_crash_type(self):
761808
event = self.get_event()
762809
rule = self.get_rule(

0 commit comments

Comments
 (0)