Fix propagate_scope=False
in ThreadingIntegration
#4310
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.
ThreadingIntegration
can optionally NOT propagate scope data to threads (propagate_scope=False
). In that case, in POTel we were wrapping the thread's task in anisolation_scope()
:But as this forks the currently active isolation scope, the thread effectively gets all scope data from the parent isolation scope -- so the scope is actually propagated to the thread, even though it shouldn't be since
propagate_scope=False
.We effectively need some way to give the thread a clear isolation scope instead. In this PR, I'm just clearing the forked iso scope, but I'm not sure if this is good enough and if something doesn't need to be done on the OTel side too.
Another option would be to set the iso/current scopes to the initial, empty iso/current scopes instead, before running the thread's target function.
Another change is that in OTel, the spans in the threads, now without a parent, automatically get promoted to transactions. (On master they'd just be orphaned spans, so they wouldn't be taken into account at all.) We probably need to instruct folks to add
only_if_parent
if they don't want this to happen.