Skip to content

ref(opentelemetry): Remove startSpan overrides from async context strategy - #23198

Open
andreiborza wants to merge 6 commits into
developfrom
ab/remove-acs-startspan-overrides
Open

ref(opentelemetry): Remove startSpan overrides from async context strategy#23198
andreiborza wants to merge 6 commits into
developfrom
ab/remove-acs-startspan-overrides

Conversation

@andreiborza

@andreiborza andreiborza commented Aug 10, 2026

Copy link
Copy Markdown
Member

What

There is now only one implementation of startSpan, startSpanManual and startInactiveSpan: the one in core. The separate OpenTelemetry copies and the ACS overrides for them are removed.

  • Core asks the async context strategy for the current active span and for making the new span active, so Node answers from the OTel context and the browser keeps using the scope
  • Removes _INTERNAL_startInactiveSpan, the SentryTracer now uses the public startInactiveSpan

Why

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.

…ategy

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.35 kB - -
@sentry/browser - with treeshaking flags 28.52 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.85 kB - -
@sentry/browser (incl. Tracing) 48.84 kB +0.48% +232 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 48.86 kB +0.5% +239 B 🔺
@sentry/browser (incl. Tracing, Profiling) 53.71 kB +0.47% +246 B 🔺
@sentry/browser (incl. Tracing, Replay) 88.26 kB +0.25% +218 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.68 kB +0.3% +227 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 92.99 kB +0.25% +226 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 105.66 kB +0.2% +205 B 🔺
@sentry/browser (incl. Feedback) 47.69 kB - -
@sentry/browser (incl. sendFeedback) 35.18 kB - -
@sentry/browser (incl. FeedbackAsync) 40.33 kB - -
@sentry/browser (incl. Metrics) 31.43 kB - -
@sentry/browser (incl. Logs) 31.66 kB - -
@sentry/browser (incl. Metrics & Logs) 32.34 kB - -
@sentry/react 32.14 kB - -
@sentry/react (incl. Tracing) 51.07 kB +0.51% +255 B 🔺
@sentry/vue 35.7 kB +0.71% +251 B 🔺
@sentry/vue (incl. Tracing) 50.84 kB +0.51% +253 B 🔺
@sentry/svelte 30.38 kB - -
CDN Bundle 31.61 kB - -
CDN Bundle (incl. Tracing) 49.12 kB +0.42% +205 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.84 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.09 kB +0.42% +210 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74.38 kB - -
CDN Bundle (incl. Tracing, Replay) 86.7 kB +0.24% +204 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.59 kB +0.22% +190 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 92.42 kB +0.24% +216 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.43 kB +0.26% +243 B 🔺
CDN Bundle - uncompressed 93.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 147.55 kB +0.43% +631 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.42 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 153.41 kB +0.42% +631 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.34 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.8 kB +0.24% +631 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.64 kB +0.24% +631 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.5 kB +0.23% +631 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 286.33 kB +0.23% +631 B 🔺
@sentry/nextjs (client) 53.59 kB +0.41% +214 B 🔺
@sentry/sveltekit (client) 49.27 kB +0.5% +242 B 🔺
@sentry/core/server 65.88 kB +0.35% +229 B 🔺
@sentry/core/browser 52.19 kB +0.42% +216 B 🔺
@sentry/node 118.01 kB -0.39% -454 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 82.02 kB -0.67% -547 B 🔽
@sentry/aws-serverless 91.5 kB -0.49% -445 B 🔽
@sentry/cloudflare (withSentry) - minified 215.46 kB +0.36% +762 B 🔺
@sentry/cloudflare (withSentry) 532.83 kB +0.47% +2.46 kB 🔺

View base workflow run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ 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.

Comment thread packages/core/src/tracing/trace.ts
Comment thread packages/opentelemetry/src/trace.ts Outdated
Comment thread packages/core/src/tracing/trace.ts Outdated
return wrapper(() => {
const scope = getCurrentScope();
const parentSpan = getParentSpan(scope, customParentSpan);
const parentSpan = getParentSpan(customParentSpan, customScope ? scope : undefined);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain (in a comment maybe?) why we pass in scope if there is a customScope?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not needed, this is a bit of an indirection since scope is already the customScope. I simplified this in 920a03b

@andreiborza
andreiborza marked this pull request as ready for review August 10, 2026 13:50
@andreiborza
andreiborza requested a review from a team as a code owner August 10, 2026 13:50
@andreiborza
andreiborza requested review from JPeer264, Lms24, chargome, mydea and nicohrubec and removed request for a team August 10, 2026 13:50
Comment thread packages/core/src/tracing/trace.ts
}): Span {
const isolationScope = getIsolationScope();

// A remote parent (an incoming trace on the ambient OTel context, set by the propagator) cannot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some word(s) are missing here? 😅

Comment on lines +506 to +513
const acs = getAcs();
if (acs.withActiveSpan) {
return acs.withActiveSpan(span, callback);
}

_setSpanForScope(scope, span);
return callback();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can just be:

return withScope(scope, () => {
  return withActiveSpan(span, () => {
    return callback();
  })
});

without using any specific implementations etc?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be "fixed" better by #23222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants