You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using @sentry_sdk.trace with concurrent futures messes up span hierarchy #4241
I expect the futures to create sibling spans, as they are being "started" in the same caller function.
Actual Result
Instead of the calls ending up with sibling spans, they end up as parent->child spans instead.
As the first async fn has not "finished" yet when I "start" the next one, it is on the top of the span hierarchy.
Actually https://sentry-sdks.sentry.io/discover/trace/a375c59ca7764110aa43973bcade293d is matching the example code, the other trace exhibits the same problem, but with a slightly different code, where I was initializing the SDK within the sync module. Doesn’t really matter, the result is the same unfortunately.
This appears to be a more fundamental problem with how scopes are isolated between async contexts. The problem is not unique to using @sentry_sdk.trace; I can also reproduce it by manually starting spans inside the concurrent tasks
@Swatinem Apparently, this bug is fixed in the potel_base branch, which will be released as version 3.0 of the Python SDK.
Unless we see large demand to fix this bug in version 2.x of the Python SDK, we think fixing in 3.0 should be sufficient (especially because the fix would be non-trivial)
In the Python SDK our workflow typically is that we close issues once all the work is completed (i.e. PR is merged), even if the changes are not released yet. The reasoning here is that it is typically possible to auto-close issues once PRs are merged, but we don't have a workflow which would auto-close issues upon release. It also keeps our issue list clean, since we ensure that open issues are always actionable from our side.
Therefore, I would prefer to keep this issue closed to stay consistent with our existing workflow.
Also, technically, the fix here should already be available in the 3.0.0a1 alpha pre-release.
Activity
Swatinem commentedon Apr 3, 2025
Actually https://sentry-sdks.sentry.io/discover/trace/a375c59ca7764110aa43973bcade293d is matching the example code, the other trace exhibits the same problem, but with a slightly different code, where I was initializing the SDK within the sync module. Doesn’t really matter, the result is the same unfortunately.
szokeasaurusrex commentedon May 20, 2025
Investigation notes
This appears to be a more fundamental problem with how scopes are isolated between async contexts. The problem is not unique to using
@sentry_sdk.trace; I can also reproduce it by manually starting spans inside the concurrent tasksfix(tracing): Fix span nesting concurrency issues
szokeasaurusrex commentedon May 21, 2025
@Swatinem Apparently, this bug is fixed in the
potel_basebranch, which will be released as version 3.0 of the Python SDK.Unless we see large demand to fix this bug in version 2.x of the Python SDK, we think fixing in 3.0 should be sufficient (especially because the fix would be non-trivial)
Swatinem commentedon May 21, 2025
that sounds reasonable. I would still keep this bug report open though until the version with the fix is actually released?
szokeasaurusrex commentedon May 21, 2025
In the Python SDK our workflow typically is that we close issues once all the work is completed (i.e. PR is merged), even if the changes are not released yet. The reasoning here is that it is typically possible to auto-close issues once PRs are merged, but we don't have a workflow which would auto-close issues upon release. It also keeps our issue list clean, since we ensure that open issues are always actionable from our side.
Therefore, I would prefer to keep this issue closed to stay consistent with our existing workflow.
Also, technically, the fix here should already be available in the
3.0.0a1alpha pre-release.