-
Notifications
You must be signed in to change notification settings - Fork 584
fix(integrations): asyncio: continuation trace transactions #5526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,6 +57,12 @@ | |||||||
| coro: "Coroutine[Any, Any, Any]", | ||||||||
| **kwargs: "Any", | ||||||||
| ) -> "asyncio.Future[Any]": | ||||||||
| # we get the current span here, as later it may already be closed | ||||||||
| in_span = sentry_sdk.get_current_span() is not None | ||||||||
| headers = dict( | ||||||||
| sentry_sdk.get_current_scope().iter_trace_propagation_headers() | ||||||||
| ) | ||||||||
|
|
||||||||
| @_wrap_coroutine(coro) | ||||||||
| async def _task_with_sentry_span_creation() -> "Any": | ||||||||
| result = None | ||||||||
|
|
@@ -66,16 +72,16 @@ | |||||||
| ) | ||||||||
| task_spans = integration.task_spans if integration else False | ||||||||
|
|
||||||||
| if task_spans and in_span: | ||||||||
|
Check warning on line 75 in sentry_sdk/integrations/asyncio.py
|
||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed conditional skips span creation when task_spans=True but no active span exists The condition changed from VerificationCompared the original condition Identified by Warden
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably add a new option if we want to go that route |
||||||||
| transaction = sentry_sdk.continue_trace( | ||||||||
| headers, op="task", name="downstream" | ||||||||
|
Check failure on line 77 in sentry_sdk/integrations/asyncio.py
|
||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded transaction name 'downstream' loses coroutine-specific tracing context The new code uses a hardcoded VerificationRead the full asyncio.py file and compared the diff. The original code at line ~65 used Suggested fix: Pass the coroutine name to continue_trace and start_transaction
Suggested change
Identified by Warden |
||||||||
| ) | ||||||||
|
Check warning on line 78 in sentry_sdk/integrations/asyncio.py
|
||||||||
|
Comment on lines
+76
to
+78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Origin attribute not set on new transactions, breaking trace origin tracking The original code set VerificationCompared the diff showing removal of Identified by Warden |
||||||||
| ctx = sentry_sdk.start_transaction(transaction) | ||||||||
| else: | ||||||||
| ctx = nullcontext() | ||||||||
|
|
||||||||
| with sentry_sdk.isolation_scope(): | ||||||||
| with ( | ||||||||
| sentry_sdk.start_span( | ||||||||
| op=OP.FUNCTION, | ||||||||
| name=get_name(coro), | ||||||||
| origin=AsyncioIntegration.origin, | ||||||||
| ) | ||||||||
| if task_spans | ||||||||
| else nullcontext() | ||||||||
| ): | ||||||||
| with ctx: | ||||||||
| try: | ||||||||
| result = await coro | ||||||||
| except StopAsyncIteration as e: | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to get the info whether we are in a transaction straight away before it closes.