Skip to content

Commit 9395202

Browse files
record lost events
1 parent 88c84f4 commit 9395202

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

sentry_sdk/tracing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,16 @@ def finish(
10641064
],
10651065
)
10661066
)
1067+
if client.transport:
1068+
client.transport.record_lost_event(
1069+
"event_processor", data_category="transaction"
1070+
)
1071+
1072+
num_spans = len(self._span_recorder.spans) + 1
1073+
client.transport.record_lost_event(
1074+
"event_processor", data_category="span", quantity=num_spans
1075+
)
1076+
10671077
self.sampled = False
10681078

10691079
if not self.sampled:

tests/tracing/test_ignore_status_codes.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import pytest
55

6+
from collections import Counter
7+
68

79
def test_no_ignored_codes(sentry_init, capture_events):
810
sentry_init(
@@ -110,3 +112,28 @@ def test_transaction_not_ignored_when_status_code_has_invalid_type(
110112
span_or_tx.set_data("http.response.status_code", "404")
111113

112114
assert len(events) == 1
115+
116+
117+
def test_records_lost_events(sentry_init, capture_record_lost_event_calls):
118+
sentry_init(
119+
traces_sample_rate=1.0,
120+
trace_ignore_status_codes={
121+
404,
122+
},
123+
)
124+
record_lost_event_calls = capture_record_lost_event_calls()
125+
126+
with start_transaction(op="http", name="GET /"):
127+
span_or_tx = sentry_sdk.get_current_span()
128+
span_or_tx.set_data("http.response.status_code", 404)
129+
130+
with start_span(op="child-span"):
131+
with start_span(op="child-child-span"):
132+
pass
133+
134+
assert Counter(record_lost_event_calls) == Counter(
135+
[
136+
("event_processor", "transaction", None, 1),
137+
("event_processor", "span", None, 3),
138+
]
139+
)

0 commit comments

Comments
 (0)