ref(opentelemetry): Remove startSpan overrides from async context strategy - #23198
ref(opentelemetry): Remove startSpan overrides from async context strategy#23198andreiborza wants to merge 6 commits into
Conversation
…ategy Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
size-limit report 📦
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e11c4b7. Configure here.
| return wrapper(() => { | ||
| const scope = getCurrentScope(); | ||
| const parentSpan = getParentSpan(scope, customParentSpan); | ||
| const parentSpan = getParentSpan(customParentSpan, customScope ? scope : undefined); |
There was a problem hiding this comment.
can you explain (in a comment maybe?) why we pass in scope if there is a customScope?
There was a problem hiding this comment.
Actually not needed, this is a bit of an indirection since scope is already the customScope. I simplified this in 920a03b
| }): Span { | ||
| const isolationScope = getIsolationScope(); | ||
|
|
||
| // A remote parent (an incoming trace on the ambient OTel context, set by the propagator) cannot |
There was a problem hiding this comment.
I think some word(s) are missing here? 😅
| const acs = getAcs(); | ||
| if (acs.withActiveSpan) { | ||
| return acs.withActiveSpan(span, callback); | ||
| } | ||
|
|
||
| _setSpanForScope(scope, span); | ||
| return callback(); | ||
| } |
There was a problem hiding this comment.
I think this can just be:
return withScope(scope, () => {
return withActiveSpan(span, () => {
return callback();
})
});without using any specific implementations etc?
There was a problem hiding this comment.
Hm, this doesn't quite work on the browser side because there withActiveSpan also runs withScope and we end up double-forking which messes things up.
Any idea how to get around that?
| * created from it picks up the incoming trace id, parent span id, and sampling decision. Mirrors | ||
| * `SentryTracer._startRootSpanWithRemoteParent` in `@sentry/opentelemetry`. | ||
| */ | ||
| function scopeWithRemoteParentPropagation(scope: Scope, remoteParentSpan: SentrySpan): Scope { |
There was a problem hiding this comment.
puh, any way we can get rid of this? how/when does this fail if we do not have this special handling in this depth? 🤔
| } | ||
|
|
||
| const span = _getSpanForScope(scope) as SentrySpan | undefined; | ||
| const span = (explicitScope ? _getSpanForScope(explicitScope) : getActiveSpan()) as SentrySpan | undefined; |

What
There is now only one implementation of
startSpan,startSpanManualandstartInactiveSpan: the one in core. The separate OpenTelemetry copies and the ACS overrides for them are removed._INTERNAL_startInactiveSpan, theSentryTracernow uses the publicstartInactiveSpanWhy
The OpenTelemetry copies created spans through core anyway and only added context bookkeeping around it. One shared code path removes the double indirection and a lot of duplicated code.