Fix StartSpan to clear Activity.Current when previous activity is stopped#6991
Merged
rajkumar-rangaraj merged 7 commits intoopen-telemetry:mainfrom Mar 26, 2026
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6991 +/- ##
==========================================
+ Coverage 88.74% 88.76% +0.01%
==========================================
Files 263 263
Lines 12420 12423 +3
==========================================
+ Hits 11022 11027 +5
+ Misses 1398 1396 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Kielek
reviewed
Mar 25, 2026
| && Activity.Current != previousActivity) | ||
| { | ||
| Activity.Current = previousActivity; | ||
| Activity.Current = previousActivity?.IsStopped == true ? null : previousActivity; |
Member
There was a problem hiding this comment.
What if previousActivity.Parent is non null and not stopped?
The tree can be deeper.
e2de488 to
9dbc981
Compare
… previous activity is stopped
6934a17 to
f2b7f74
Compare
martincostello
approved these changes
Mar 26, 2026
Kielek
approved these changes
Mar 26, 2026
rajkumar-rangaraj
approved these changes
Mar 26, 2026
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #6257
Design discussion issue #
Changes
Tracer.StartSpan() restores Activity.Current to previousActivity after creating the new span. If another thread stops previousActivity during span creation, the restore silently fails and leaves the new span as Activity.Current.
The fix sets Activity.Current to null when previousActivity.IsStopped.
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes