Skip to content

Commit 2085817

Browse files
committed
Merge branch 'ivana/potel/fix-propagate-scope-false' into ivana/potel/determine-lowest-otel-version
2 parents 3de83dd + 1282884 commit 2085817

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

sentry_sdk/integrations/threading.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ def _run_old_run_func():
115115
with sentry_sdk.use_scope(current_scope_to_use):
116116
return _run_old_run_func()
117117
else:
118-
with sentry_sdk.isolation_scope():
118+
with sentry_sdk.isolation_scope() as scope:
119+
scope.clear()
119120
return _run_old_run_func()
120121

121122
return run # type: ignore

tests/integrations/threading/test_threading.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def do_some_work(number):
232232
threads = []
233233

234234
with sentry_sdk.start_span(op="outer-trx"):
235-
for number in range(5):
235+
for number in range(2):
236236
with sentry_sdk.start_span(
237237
op=f"outer-submit-{number}", name="Thread: main"
238238
):
@@ -243,32 +243,44 @@ def do_some_work(number):
243243
for t in threads:
244244
t.join()
245245

246-
(event,) = events
247246
if propagate_scope:
247+
# The children spans from the threads become parts of the existing span
248+
# tree since we propagated the scope
249+
assert len(events) == 1
250+
(event,) = events
251+
248252
assert render_span_tree(event) == dedent(
249253
"""\
250254
- op="outer-trx": description=null
251255
- op="outer-submit-0": description="Thread: main"
252256
- op="inner-run-0": description="Thread: child-0"
253257
- op="outer-submit-1": description="Thread: main"
254-
- op="inner-run-1": description="Thread: child-1"
255-
- op="outer-submit-2": description="Thread: main"
256-
- op="inner-run-2": description="Thread: child-2"
257-
- op="outer-submit-3": description="Thread: main"
258-
- op="inner-run-3": description="Thread: child-3"
259-
- op="outer-submit-4": description="Thread: main"
260-
- op="inner-run-4": description="Thread: child-4"\
258+
- op="inner-run-1": description="Thread: child-1"\
261259
"""
262260
)
263261

264262
elif not propagate_scope:
265-
assert render_span_tree(event) == dedent(
263+
# The spans from the threads become their own root spans/transactions
264+
# as the connection to the parent span was severed when the scope was
265+
# cleared
266+
assert len(events) == 3
267+
(event1, event2, event3) = events
268+
269+
assert render_span_tree(event1) == dedent(
270+
"""\
271+
- op="inner-run-0": description=null\
272+
"""
273+
)
274+
assert render_span_tree(event2) == dedent(
275+
"""\
276+
- op="inner-run-1": description=null\
277+
"""
278+
)
279+
280+
assert render_span_tree(event3) == dedent(
266281
"""\
267282
- op="outer-trx": description=null
268283
- op="outer-submit-0": description="Thread: main"
269-
- op="outer-submit-1": description="Thread: main"
270-
- op="outer-submit-2": description="Thread: main"
271-
- op="outer-submit-3": description="Thread: main"
272-
- op="outer-submit-4": description="Thread: main"\
284+
- op="outer-submit-1": description="Thread: main"\
273285
"""
274286
)

0 commit comments

Comments
 (0)