Skip to content

Commit 09a4897

Browse files
aliu39andrewshie-sentry
authored andcommitted
ref(alerts): add issue_type tag to notifications.sent metric (#88063)
In DD, this will allow us to aggregate by the [GroupType](https://github.com/getsentry/sentry/blob/5510957c4ed7d7ad50f60b34d425c618cd15dd08/src/sentry/issues/grouptype.py#L155) of issue alerts. We'll get counts for specific types and can create detectors for them Note: we'll have to enable aggregation for this specific tag in DD, which will add some cost. There's a fixed number of group types defined in grouptype.py.
1 parent be5b229 commit 09a4897

File tree

6 files changed

+56
-8
lines changed

6 files changed

+56
-8
lines changed

src/sentry/integrations/discord/actions/issue_alert/notification.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ def send_notification(event: GroupEvent, futures: Sequence[RuleFuture]) -> None:
8181

8282
key = f"discord:{integration.id}:{channel_id}"
8383

84-
metrics.incr("notifications.sent", instance="discord.notifications", skip_internal=False)
84+
metrics.incr(
85+
"notifications.sent",
86+
instance="discord.notifications",
87+
tags={
88+
"issue_type": event.group.issue_type.slug,
89+
},
90+
skip_internal=False,
91+
)
8592
yield self.future(send_notification, key=key)
8693

8794
def render_label(self) -> str:

src/sentry/integrations/msteams/actions/notification.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ def send_notification(event, futures):
6969

7070
key = f"msteams:{integration.id}:{channel}"
7171

72-
metrics.incr("notifications.sent", instance="msteams.notification", skip_internal=False)
72+
metrics.incr(
73+
"notifications.sent",
74+
instance="msteams.notification",
75+
tags={
76+
"issue_type": event.group.issue_type.slug,
77+
},
78+
skip_internal=False,
79+
)
7380
yield self.future(send_notification, key=key)
7481

7582
def render_label(self):

src/sentry/integrations/slack/actions/notification.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,14 @@ def send_notification_noa(event: GroupEvent, futures: Sequence[RuleFuture]) -> N
464464

465465
key = f"slack:{integration.id}:{channel}"
466466

467-
metrics.incr("notifications.sent", instance="slack.notification", skip_internal=False)
467+
metrics.incr(
468+
"notifications.sent",
469+
instance="slack.notification",
470+
tags={
471+
"issue_type": event.group.issue_type.slug,
472+
},
473+
skip_internal=False,
474+
)
468475
if features.has("organizations:workflow-engine-trigger-actions", self.project.organization):
469476
yield self.future(send_notification_noa, key=key)
470477
else:

src/sentry/mail/actions.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def after(self, event, notification_uuid: str | None = None):
4040
"group_id": group.id,
4141
"notification_uuid": notification_uuid,
4242
}
43-
group = event.group
4443

4544
target_type = ActionTargetType(self.data["targetType"])
4645
target_identifier = self.data.get("targetIdentifier", None)
@@ -59,7 +58,14 @@ def after(self, event, notification_uuid: str | None = None):
5958
self.logger.info("rule.fail.should_notify", extra=extra)
6059
return
6160

62-
metrics.incr("notifications.sent", instance=self.metrics_slug, skip_internal=False)
61+
metrics.incr(
62+
"notifications.sent",
63+
instance=self.metrics_slug,
64+
tags={
65+
"issue_type": group.issue_type.slug,
66+
},
67+
skip_internal=False,
68+
)
6369
yield self.future(
6470
lambda event, futures: mail_adapter.rule_notify(
6571
event,

src/sentry/rules/actions/notify_event.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,12 @@ def after(
3838
if not safe_execute(plugin.should_notify, group=group, event=event):
3939
continue
4040

41-
metrics.incr("notifications.sent", instance=plugin.slug, skip_internal=False)
41+
metrics.incr(
42+
"notifications.sent",
43+
instance=plugin.slug,
44+
tags={
45+
"issue_type": event.group.issue_type.slug,
46+
},
47+
skip_internal=False,
48+
)
4249
yield self.future(plugin.rule_notify)

src/sentry/rules/actions/notify_event_service.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,14 @@ def after(
166166
app = app_service.get_sentry_app_by_slug(slug=service)
167167

168168
if app:
169-
metrics.incr("notifications.sent", instance=app.slug, skip_internal=False)
169+
metrics.incr(
170+
"notifications.sent",
171+
instance=app.slug,
172+
tags={
173+
"issue_type": event.group.issue_type.slug,
174+
},
175+
skip_internal=False,
176+
)
170177
yield self.future(notify_sentry_app, sentry_app=app)
171178

172179
try:
@@ -197,7 +204,14 @@ def after(
197204
extra["project_id"] = self.project.id
198205
self.logger.info("rules.plugin_notification_sent", extra=extra)
199206

200-
metrics.incr("notifications.sent", instance=plugin.slug, skip_internal=False)
207+
metrics.incr(
208+
"notifications.sent",
209+
instance=plugin.slug,
210+
tags={
211+
"issue_type": event.group.issue_type.slug,
212+
},
213+
skip_internal=False,
214+
)
201215
yield self.future(plugin.rule_notify)
202216

203217
def get_sentry_app_services(self) -> Sequence[RpcSentryAppService]:

0 commit comments

Comments
 (0)