Skip to content

Commit 30686f8

Browse files
gggritsoschew2381
authored andcommitted
fix(perf-issues): Fix subject substitution for Performance issues (#46914)
Closes #46872. Two changes here: 1. When someone puts in `$title`, for a Performance Issue it should use the issue type name (e.g., "Slow DB Query") since each event doesn't have its own title of any kind (except if there's an occurrence, but that's another story) 2. Use the aliased _and_ unaliased form of the tag. I'm not sure what the root cause is, but when users set `${tag:release}`, we look for the `sentry:release` tag, instead of the `release` tag. For Performance issues, this doesn't seem to work, that tag isn't there. I'm honestly not too sure what's going on, but I set it so that it also tries the unaliased tag before giving up
1 parent a62af2c commit 30686f8

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

fixtures/emails/performance.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Tags
2525
* level = info
2626
* runtime = CPython 3.8.9
2727
* runtime.name = CPython
28+
* sentry:release = 0.1
2829
* sentry:user = ip:127.0.0.1
2930
* transaction = /books/
3031
* url = http://127.0.0.1:9007/books/

src/sentry/data/samples/transaction-n-plus-one.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
["device", "Mac"],
1010
["device.family", "Mac"],
1111
["environment", "production"],
12+
["sentry:release", "0.1"],
1213
["http.status_code", "200"],
1314
["level", "info"],
1415
["runtime", "CPython 3.8.9"],

src/sentry/eventstore/models.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,9 @@ def __getitem__(self, name: str) -> str:
778778
if name.startswith("tag:"):
779779
name = name[4:]
780780
value = self.event.get_tag(self.tag_aliases.get(name, name))
781+
if value is None:
782+
value = self.event.get_tag(name)
783+
781784
if value is None:
782785
raise KeyError
783786
return str(value)
@@ -790,11 +793,13 @@ def __getitem__(self, name: str) -> str:
790793
elif name == "orgID":
791794
return cast(str, self.event.organization.slug)
792795
elif name == "title":
793-
return (
794-
self.event.occurrence.issue_title
795-
if getattr(self.event, "occurrence", None)
796-
else self.event.title
797-
)
796+
if getattr(self.event, "occurrence", None):
797+
return self.event.occurrence.issue_title
798+
elif self.event.group and self.event.group.issue_category == GroupCategory.PERFORMANCE:
799+
return self.event.group.issue_type.description
800+
else:
801+
return self.event.title
802+
798803
elif name == "issueType":
799804
return self.event.group.issue_type.description
800805
raise KeyError

tests/sentry/eventstore/test_models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
from sentry.models import Environment
1313
from sentry.snuba.dataset import Dataset
1414
from sentry.testutils import TestCase
15+
from sentry.testutils.cases import PerformanceIssueTestCase
1516
from sentry.testutils.helpers.datetime import before_now, iso_format
1617
from sentry.testutils.silo import region_silo_test
1718
from sentry.utils import snuba
1819
from tests.sentry.issues.test_utils import OccurrenceTestMixin
1920

2021

2122
@region_silo_test
22-
class EventTest(TestCase):
23+
class EventTest(TestCase, PerformanceIssueTestCase):
2324
def test_pickling_compat(self):
2425
event = self.store_event(
2526
data={
@@ -105,6 +106,15 @@ def test_email_subject_with_template(self):
105106

106107
assert event1.get_email_subject() == "BAR-1 - production@0 $ baz ${tag:invalid} $invalid"
107108

109+
def test_transaction_email_subject(self):
110+
self.project.update_option(
111+
"mail:subject_template",
112+
"$shortID - ${tag:environment}@${tag:release} $title",
113+
)
114+
115+
event = self.create_performance_issue()
116+
assert event.get_email_subject() == "BAR-1 - [email protected] N+1 Query"
117+
108118
def test_as_dict_hides_client_ip(self):
109119
event = self.store_event(
110120
data={"sdk": {"name": "foo", "version": "1.0", "client_ip": "127.0.0.1"}},

0 commit comments

Comments
 (0)