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
Auto-forked startSpan broke retroactive tag addition #10122
Call startSpan() again within the first span's callback
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
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:
Store the scope before you call startSpan() and set on it later:
constscope=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 dogetCurrentScope().setTag(...);});
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!
Activity
mydea commentedon Jan 10, 2024
Hey,
the previous behavior was accidental and not the expected behavior - calling
startSpanshould 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:
startSpan()and set on it later: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!