Skip to content

Commit 2ca8fba

Browse files
authored
Merge cf80d4d into e11af76
2 parents e11af76 + cf80d4d commit 2ca8fba

File tree

6 files changed

+51
-38
lines changed

6 files changed

+51
-38
lines changed

src/sentry/api/endpoints/organization_events_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def count_performance_issues(
530530
snuba_params=params,
531531
trace_ids=[trace_id],
532532
referrer=Referrer.API_TRACE_VIEW_COUNT_PERFORMANCE_ISSUES.value,
533-
occurrence_category=OccurrenceCategory.GENERIC,
533+
occurrence_category=OccurrenceCategory.ISSUE_PLATFORM,
534534
).get(trace_id, 0)
535535
performance_issues_count = EAPOccurrencesComparator.check_and_choose(
536536
snuba_count,

src/sentry/api/endpoints/organization_traces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def enrich_eap_traces_with_extra_data(
379379
snuba_params=snuba_params,
380380
trace_ids=trace_ids,
381381
referrer=Referrer.API_TRACE_EXPLORER_TRACES_OCCURRENCES.value,
382-
occurrence_category=OccurrenceCategory.GENERIC,
382+
occurrence_category=OccurrenceCategory.ISSUE_PLATFORM,
383383
)
384384
traces_occurrences = EAPOccurrencesComparator.check_and_choose(
385385
traces_occurrences,

src/sentry/snuba/occurrences_rpc.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
import sentry_sdk
66
from sentry_protos.snuba.v1.request_common_pb2 import PageToken
7-
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import AttributeKey, AttributeValue
8-
from sentry_protos.snuba.v1.trace_item_filter_pb2 import ComparisonFilter, TraceItemFilter
7+
from sentry_protos.snuba.v1.trace_item_attribute_pb2 import AttributeKey
8+
from sentry_protos.snuba.v1.trace_item_filter_pb2 import (
9+
ExistsFilter,
10+
NotFilter,
11+
TraceItemFilter,
12+
)
913

1014
from sentry.search.eap.columns import ColumnDefinitions, ResolvedAttribute
1115
from sentry.search.eap.occurrences.definitions import OCCURRENCE_DEFINITIONS
@@ -20,14 +24,14 @@
2024

2125
class OccurrenceCategory(Enum):
2226
"""
23-
Category of occurrence events in EAP.
27+
Category of occurrence trace items in EAP.
2428
25-
In EAP, both error events and issue platform (generic) events are stored as
29+
In EAP, both error events and issue platform events are stored as
2630
TRACE_ITEM_TYPE_OCCURRENCE.
2731
"""
2832

2933
ERROR = "error"
30-
GENERIC = "generic"
34+
ISSUE_PLATFORM = "issue_platform"
3135

3236

3337
class Occurrences(rpc_dataset_common.RPCBase):
@@ -243,21 +247,22 @@ def run_grouped_timeseries_query(
243247

244248
@classmethod
245249
def _build_category_filter(cls, category: OccurrenceCategory | None) -> TraceItemFilter | None:
250+
occurrence_id_key = AttributeKey(name="occurrence_id", type=AttributeKey.TYPE_STRING)
246251
if category == OccurrenceCategory.ERROR:
252+
# Error events: no occurrence attached, so occurrence_id does NOT exist
247253
return TraceItemFilter(
248-
comparison_filter=ComparisonFilter(
249-
key=AttributeKey(name="type", type=AttributeKey.TYPE_STRING),
250-
op=ComparisonFilter.OP_NOT_EQUALS,
251-
value=AttributeValue(val_str="generic"),
254+
not_filter=NotFilter(
255+
filters=[
256+
TraceItemFilter(
257+
exists_filter=ExistsFilter(key=occurrence_id_key),
258+
)
259+
]
252260
)
253261
)
254-
elif category == OccurrenceCategory.GENERIC:
262+
elif category == OccurrenceCategory.ISSUE_PLATFORM:
263+
# Issue platform events: occurrence attached, so occurrence_id EXISTS
255264
return TraceItemFilter(
256-
comparison_filter=ComparisonFilter(
257-
key=AttributeKey(name="type", type=AttributeKey.TYPE_STRING),
258-
op=ComparisonFilter.OP_EQUALS,
259-
value=AttributeValue(val_str="generic"),
260-
)
265+
exists_filter=ExistsFilter(key=occurrence_id_key),
261266
)
262267

263268
return None

src/sentry/tasks/summaries/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def _project_key_performance_issues_eap(
328328
limit=3,
329329
referrer=referrer,
330330
config=SearchResolverConfig(),
331-
occurrence_category=OccurrenceCategory.GENERIC,
331+
occurrence_category=OccurrenceCategory.ISSUE_PLATFORM,
332332
)
333333
except Exception:
334334
logger.exception(

src/sentry/testutils/cases.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,6 +3564,7 @@ def create_eap_occurrence(
35643564
title: str = "some error",
35653565
transaction: str | None = None,
35663566
occurrence_type: str = "error",
3567+
occurrence_id: str | None = None,
35673568
tags: dict[str, str] | None = None,
35683569
attributes: dict[str, Any] | None = None,
35693570
retention_days: int = 90,
@@ -3590,6 +3591,8 @@ def create_eap_occurrence(
35903591
preprocessed: dict[str, Any] = {}
35913592
if group_id is not None:
35923593
preprocessed["group_id"] = group_id
3594+
if occurrence_id is not None:
3595+
preprocessed["occurrence_id"] = occurrence_id
35933596
if environment is not None:
35943597
data["environment"] = environment
35953598
if transaction is not None:

tests/snuba/search/test_eap_occurrences.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,36 @@ def test_create_and_store_occurrence(self) -> None:
6767
assert len(result["data"]) == 1
6868
assert result["data"][0]["count()"] == 1
6969

70-
def test_occurrence_type_filtering(self) -> None:
70+
def test_occurrence_category_filtering(self) -> None:
7171
group_error = self.create_group(project=self.project)
7272
group_generic = self.create_group(project=self.project)
7373

74+
# Error events have no occurrence_id
7475
error_occurrence = self.create_eap_occurrence(
7576
group_id=group_error.id,
76-
occurrence_type="error",
7777
)
78+
# Issue platform events have an occurrence_id
7879
generic_occurrence = self.create_eap_occurrence(
7980
group_id=group_generic.id,
80-
occurrence_type="generic",
81+
occurrence_id=uuid4().hex,
8182
)
8283
self.store_eap_items([error_occurrence, generic_occurrence])
8384

84-
# OccurrenceCategory.ERROR filters for type != "generic"
85+
# OccurrenceCategory.ERROR filters for items without occurrence_id
8586
error_result = self._query_occurrences(
87+
selected_columns=["group_id", "count()"],
8688
occurrence_category=OccurrenceCategory.ERROR,
8789
)
8890
assert error_result["data"][0]["count()"] == 1
91+
assert error_result["data"][0]["group_id"] == group_error.id
8992

90-
# OccurrenceCategory.GENERIC filters for type == "generic"
93+
# OccurrenceCategory.ISSUE_PLATFORM filters for items with occurrence_id
9194
generic_result = self._query_occurrences(
92-
occurrence_category=OccurrenceCategory.GENERIC,
95+
selected_columns=["group_id", "count()"],
96+
occurrence_category=OccurrenceCategory.ISSUE_PLATFORM,
9397
)
9498
assert generic_result["data"][0]["count()"] == 1
99+
assert generic_result["data"][0]["group_id"] == group_generic.id
95100

96101
# No category filter returns both
97102
all_result = self._query_occurrences()
@@ -225,11 +230,13 @@ def test_filters_by_occurrence_category(self) -> None:
225230
group = self.create_group(project=self.project)
226231
self.store_eap_items(
227232
[
228-
self.create_eap_occurrence(group_id=group.id, occurrence_type="error"),
229-
self.create_eap_occurrence(group_id=group.id, occurrence_type="error"),
230-
self.create_eap_occurrence(group_id=group.id, occurrence_type="error"),
231-
self.create_eap_occurrence(group_id=group.id, occurrence_type="generic"),
232-
self.create_eap_occurrence(group_id=group.id, occurrence_type="generic"),
233+
# Error events: no occurrence_id
234+
self.create_eap_occurrence(group_id=group.id),
235+
self.create_eap_occurrence(group_id=group.id),
236+
self.create_eap_occurrence(group_id=group.id),
237+
# Generic events: have occurrence_id
238+
self.create_eap_occurrence(group_id=group.id, occurrence_id=uuid4().hex),
239+
self.create_eap_occurrence(group_id=group.id, occurrence_id=uuid4().hex),
233240
]
234241
)
235242

@@ -247,7 +254,7 @@ def test_filters_by_occurrence_category(self) -> None:
247254
start=self.start,
248255
end=self.end,
249256
referrer=self.referrer,
250-
occurrence_category=OccurrenceCategory.GENERIC,
257+
occurrence_category=OccurrenceCategory.ISSUE_PLATFORM,
251258
)
252259

253260
assert error_count == 3
@@ -282,14 +289,12 @@ def test_counts_grouped_by_trace_ids_with_occurrence_category(self) -> None:
282289
trace_id = uuid4().hex
283290
self.store_eap_items(
284291
[
292+
# Error events: no occurrence_id
293+
self.create_eap_occurrence(group_id=group.id, trace_id=trace_id),
294+
self.create_eap_occurrence(group_id=group.id, trace_id=trace_id),
295+
# Generic event: has occurrence_id
285296
self.create_eap_occurrence(
286-
group_id=group.id, trace_id=trace_id, occurrence_type="error"
287-
),
288-
self.create_eap_occurrence(
289-
group_id=group.id, trace_id=trace_id, occurrence_type="error"
290-
),
291-
self.create_eap_occurrence(
292-
group_id=group.id, trace_id=trace_id, occurrence_type="generic"
297+
group_id=group.id, trace_id=trace_id, occurrence_id=uuid4().hex
293298
),
294299
]
295300
)
@@ -310,7 +315,7 @@ def test_counts_grouped_by_trace_ids_with_occurrence_category(self) -> None:
310315
snuba_params=snuba_params,
311316
trace_ids=[trace_id],
312317
referrer=self.referrer,
313-
occurrence_category=OccurrenceCategory.GENERIC,
318+
occurrence_category=OccurrenceCategory.ISSUE_PLATFORM,
314319
)
315320

316321
assert grouped_errors == {trace_id: 2}

0 commit comments

Comments
 (0)