Repository: getsentry/sentry

Issue:
Allow alerting based on `sdk.name`
### Problem Statement

We're in a React Native project and we'd like the ability to have separate reporting rules based on the `sdk.name`. Right now we're looking very closely at any errors which are reported from `sentry.cocoa` and we would like to send them to a channel where the dedicated iOS engineers can look at them without being bothered by the issues that `sentry.javascript` generates (we have a separate team looking closely at any JS errors).

When I went to go set up a reporting rule, I noticed that there's no way to filter based on `sdk.name`:
![Screen Shot 2021-12-03 at 9 00 49 PM](https://user-images.githubusercontent.com/1657142/144693010-72ab4966-6f02-416b-9ab2-85925d6f8032.png)


### Solution Brainstorm

Hopefully it would be pretty easy to add this new option to the dropdown 🤞 


Discussion:
Routing to @getsentry/workflow for [triage](https://develop.sentry.dev/processing-tickets/#3-triage). ⏲️

Thanks for opening this issue @kj800x I believe this is something we can do. I've added it to our team backlog

Resolving patch:
diff --git a/src/sentry/rules/conditions/event_attribute.py b/src/sentry/rules/conditions/event_attribute.py
--- a/src/sentry/rules/conditions/event_attribute.py
+++ b/src/sentry/rules/conditions/event_attribute.py
@@ -46,6 +46,7 @@ class MatchType:
     "user.ip_address",
     "http.method",
     "http.url",
+    "sdk.name",
     "stacktrace.code",
     "stacktrace.module",
     "stacktrace.filename",
@@ -145,6 +146,11 @@ def _get_attribute_values(self, event, attr):
 
             return [getattr(event.interfaces["request"], path[1])]
 
+        elif path[0] == "sdk":
+            if path[1] != "name":
+                return []
+            return [event.data["sdk"].get(path[1])]
+
         elif path[0] == "stacktrace":
             stacks = event.interfaces.get("stacktrace")
             if stacks:


Test patch:
diff --git a/tests/sentry/rules/conditions/test_event_attribute.py b/tests/sentry/rules/conditions/test_event_attribute.py
--- a/tests/sentry/rules/conditions/test_event_attribute.py
+++ b/tests/sentry/rules/conditions/test_event_attribute.py
@@ -36,6 +36,7 @@ def get_event(self, **kwargs):
             "tags": [("environment", "production")],
             "extra": {"foo": {"bar": "baz"}, "biz": ["baz"], "bar": "foo"},
             "platform": "php",
+            "sdk": {"name": "sentry.javascript.react", "version": "6.16.1"},
         }
         data.update(kwargs)
         event = self.store_event(data, project_id=self.project.id)
@@ -298,6 +299,22 @@ def test_exception_value(self):
         )
         self.assertDoesNotPass(rule, event)
 
+    def test_sdk_name(self):
+        event = self.get_event()
+        rule = self.get_rule(
+            data={
+                "match": MatchType.EQUAL,
+                "attribute": "sdk.name",
+                "value": "sentry.javascript.react",
+            }
+        )
+        self.assertPasses(rule, event)
+
+        rule = self.get_rule(
+            data={"match": MatchType.EQUAL, "attribute": "sdk.name", "value": "sentry.python"}
+        )
+        self.assertDoesNotPass(rule, event)
+
     def test_stacktrace_filename(self):
         """Stacktrace.filename should match frames anywhere in the stack."""