Skip to content

Auto-forked startSpan broke retroactive tag addition #10122

Closed as not planned
Closed as not planned

Description

@jonathroth

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

7.92.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

  1. Init sentry SDK with limited info
  2. Call startSpan()
  3. Call startSpan() again within the first span's callback
  4. Within the nested child span, call setTag()

Expected Result

Until now, since a scope wouldn't be created, the setTag would simply apply to the global scope and all events/traces would have those tags

Actual Result

Tags only apply to the child span, since the scope was auto-forked, so the tags were added to the child scope
Relevant change should be this PR - #9955

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 2on Jan 9, 2024
  2. mydea commented on Jan 10, 2024

    @mydea
    Member

    Hey,

    the previous behavior was accidental and not the expected behavior - calling startSpan should fork the scope and set the current span only on this forked scope, but not change the outer scope. I'm sorry for the confusion this caused!

    If you want to add tags to the general outer scope, you have a few options. In the upcoming v8 release, Sentry.setTag() will always set on the isolation scope, which is basically the outer/global scope.

    For now, in v7, if you want that you can either:

    1. Store the scope before you call startSpan() and set on it later:
    const scope = Sentry.getCurrentScope();
    Sentry.startSpan({ name: 'inner' }, span => {
      scope.setTag(...); // will put it on the outer scope, not in the inner scope!
      // if you _also_ want it on the inner scope, you _also_ need to do
      getCurrentScope().setTag(...);
    });
    1. Put it on the isolation scope directly:
    Sentry.startSpan({ name: 'inner' }, span => {
      getIsolationScope().setTag(...);
      // the isolation scope is applied here, but also to anything outside
      // it is merged with the current scope
    });

    Depending on your concrete needs. The isolation scope is not documented well yet, we are working on this - but TLDR this has been designed exactly for this problem, if you want to add scope data that should be applied everywhere, without having to think about where you are calling this from etc.

    I'm closing this, as the new behavior is the expected behavior - sorry again for the confusion our initially incorrect implementation caused here!

  3. ghost added on Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions