-
Notifications
You must be signed in to change notification settings - Fork 523
test : Add test to confirm Context expected behavior #2724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test : Add test to confirm Context expected behavior #2724
Conversation
I used this as an excuse to have a read of the spec 😄 My read is that the A Context is immutable:
Also, A SpanContext is immutable, but this doesn't matter much for the present discussion:
Whereas, Spans are very mutable - "Set Attributes", "Add Events", etc. None of these operations nor the section Context Interaction mention anything about span mutation forcing a corresponding update/replace on the context. This would be in principal quite strange 2-way coupling - the |
@bantonsson @scottgerring Thanks for clearing up the confusion I had. I modified the tests now to test the expected behavior! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2724 +/- ##
=======================================
+ Coverage 79.3% 79.4% +0.1%
=======================================
Files 123 123
Lines 22682 22737 +55
=======================================
+ Hits 17992 18059 +67
+ Misses 4690 4678 -12 ☔ View full report in Codecov by Sentry. |
To assist reviewing https://github.com/open-telemetry/opentelemetry-rust/pull/2378/files I wrote some tests, which left me wondering with a unresolved question.
Context MUST be immutable, so adding value to context (with_value), should result in a new Context, leaving original untouched. A test for this is added and works as expected.
Then I tried this with Spans - Created an empty context, and added a Span to the Context. When I add another random value to that Context, it is cloning the random value, but the Span is stored via Arc, so clone is just pointing to the original span. Updates made to span from the new context updates the original span.
Not sure if this is the intended behavior, opening to discuss.
Edit: The expectation is Context itself is immutable, but the Span inside is mutable. Tests modified to assert this.