Skip to content

Commit 44b18cb

Browse files
authored
fix(tracing): Fix race condition between finish and start_child (#1203)
1 parent 6397268 commit 44b18cb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

sentry_sdk/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ def finish(self, hub=None):
586586
# recorder -> span -> containing transaction (which is where we started)
587587
# before either the spans or the transaction goes out of scope and has
588588
# to be garbage collected
589-
del self._span_recorder
589+
self._span_recorder = None
590590

591591
return hub.capture_event(
592592
{

tests/tracing/test_integration_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
start_span,
1111
start_transaction,
1212
)
13+
from sentry_sdk.transport import Transport
1314
from sentry_sdk.tracing import Transaction
1415

1516

@@ -147,3 +148,22 @@ def before_send(event, hint):
147148
pass
148149

149150
assert len(events) == 1
151+
152+
153+
def test_start_span_after_finish(sentry_init, capture_events):
154+
class CustomTransport(Transport):
155+
def capture_envelope(self, envelope):
156+
pass
157+
158+
def capture_event(self, event):
159+
start_span(op="toolate", description="justdont")
160+
pass
161+
162+
sentry_init(traces_sample_rate=1, transport=CustomTransport())
163+
events = capture_events()
164+
165+
with start_transaction(name="hi"):
166+
with start_span(op="bar", description="bardesc"):
167+
pass
168+
169+
assert len(events) == 1

0 commit comments

Comments
 (0)