Skip to content

Commit 353bde6

Browse files
committed
fix(profiling): Update active thread for asgi
Ensure the handling thread is set on the transaction for asgi transactions not just main thread.
1 parent 5080c76 commit 353bde6

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

sentry_sdk/integrations/django/asgi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ async def sentry_wrapped_callback(request, *args, **kwargs):
171171
sentry_scope = sentry_sdk.get_isolation_scope()
172172
if sentry_scope.profile is not None:
173173
sentry_scope.profile.update_active_thread_id()
174+
if sentry_scope.transaction is not None:
175+
sentry_scope.transaction.update_active_thread()
174176

175177
with sentry_sdk.start_span(
176178
op=OP.VIEW_RENDER,

sentry_sdk/integrations/django/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def sentry_wrapped_callback(request, *args, **kwargs):
8181
# this isn't necessary for async views since that runs on main
8282
if sentry_scope.profile is not None:
8383
sentry_scope.profile.update_active_thread_id()
84+
if sentry_scope.transaction is not None:
85+
sentry_scope.transaction.update_active_thread()
8486

8587
with sentry_sdk.start_span(
8688
op=OP.VIEW_RENDER,

sentry_sdk/integrations/fastapi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def _sentry_call(*args, **kwargs):
9191
sentry_scope = sentry_sdk.get_isolation_scope()
9292
if sentry_scope.profile is not None:
9393
sentry_scope.profile.update_active_thread_id()
94+
if sentry_scope.transaction is not None:
95+
sentry_scope.transaction.update_active_thread()
9496
return old_call(*args, **kwargs)
9597

9698
dependant.call = _sentry_call

sentry_sdk/integrations/starlette.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ def _sentry_sync_func(*args, **kwargs):
491491

492492
if sentry_scope.profile is not None:
493493
sentry_scope.profile.update_active_thread_id()
494+
if sentry_scope.transaction is not None:
495+
sentry_scope.transaction.update_active_thread()
494496

495497
request = args[0]
496498

sentry_sdk/tracing.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ def __init__(
329329
self._span_recorder = None # type: Optional[_SpanRecorder]
330330
self._local_aggregator = None # type: Optional[LocalAggregator]
331331

332-
thread_id, thread_name = get_current_thread_meta()
333-
self.set_thread(thread_id, thread_name)
332+
self.update_active_thread()
334333
self.set_profiler_id(get_profiler_id())
335334

336335
# TODO this should really live on the Transaction class rather than the Span
@@ -732,6 +731,11 @@ def get_profile_context(self):
732731
"profiler_id": profiler_id,
733732
}
734733

734+
def update_active_thread(self):
735+
# type: () -> None
736+
thread_id, thread_name = get_current_thread_meta()
737+
self.set_thread(thread_id, thread_name)
738+
735739

736740
class Transaction(Span):
737741
"""The Transaction is the root element that holds all the spans

0 commit comments

Comments
 (0)