fix(core): Fork scope if custom scope is passed to startSpan
#14900
+161
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes unexpected behaviour that would emerge when starting multiple spans in sequence with
startSpan
when passing on the same scope. Prior to this change, the second span would be started as the child span of the first one, because the span set active on the custom scope was not re-set to the parent span of the first span. The reason is that we didn't clean up or restore the previously active span because the custom scope is not forked in contrast to the current scope.In very niche scenarios, this could furthermore lead to only the first span being sent and subsequent spans being discarded because they were being incorrectly considered a child span. Examples for this are the Sentry and CodeCov bundler plugins where we solely rely on
@sentry/core
and a custom client setup. In more conventional setups, using the Node (POTEL) or browser SDKs this probably would have gone unnoticed.This PR fixes this edge case by also forking the custom scope if it is passed into
startSpan
. Since this has implications on the lifetime of other span modifications like setting tags, we consider this a behaviourally breaking change and will not backport it to v8. I adjusted tests to reflect the scope data lifetime. It's worth noting though, that in POTEL SDKs we already forked custom scope, so this PR further aligns behaviour.This came up while reviewing codecov/codecov-javascript-bundler-plugins#224