Add optional traceFlags to SpanContext for upstream sampling propagation#6576
Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR adds optional traceFlags (W3C trace flags) to SpanContext and InvocationSpanContext, parses them from traceparent, propagates them through the invocation chain, and exposes them on tail worker onset events.
Issues (ranked by severity)
- HIGH —
newChild()silently dropstraceFlags. Child spans created vianewChild()(trace.c++:195-196) will havetraceFlags = kj::nonebecause the constructor call doesn't passtraceFlags. Since trace flags represent an upstream sampling decision that applies to the entire trace, child spans should inherit them. Suggested fix:
return InvocationSpanContext(kj::Badge<InvocationSpanContext>(), otherEntropySource, traceId,
invocationId, SpanId::fromEntropy(otherEntropySource), *this, traceFlags);-
MEDIUM —
InvocationSpanContext::toCapnp()andfromCapnp()don't serializetraceFlags, and the capnpInvocationSpanContextstruct also lacks atraceFlagsfield. Any round-trip through capnp (e.g., cross-process RPC) loses the flags. If this is intentional/deferred, a TODO comment attoCapnp()(line 243) would help. -
MEDIUM — Behavioral change:
tryFromTraceparentnow accepts unsampled traces (flags=0x00). Previously these returnedkj::none. Any caller that relied on a non-null return meaning "sampled" will now see unsampled contexts flow through. This is correct for the PR's goal but is a semantic change worth confirming doesn't break callers outside this repo. -
LOW —
SpanContext::operator==now includestraceFlags, butInvocationSpanContext::operator==does not. This inconsistency could cause subtle issues — twoSpanContextobjects with the same trace+span but different flags will now compare unequal. See inline comment.
|
Review posted successfully on PR #6576. Here's a summary of what I found:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6576 +/- ##
==========================================
- Coverage 66.60% 66.59% -0.01%
==========================================
Files 402 402
Lines 115803 115891 +88
Branches 19395 19425 +30
==========================================
+ Hits 77130 77179 +49
- Misses 27103 27115 +12
- Partials 11570 11597 +27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
Comparing Footnotes
|
|
Review posted successfully on PR #6576. Here's a summary: The two higher-severity issues from my earlier review have been fixed:
One new low-severity issue found:
The two items from the prior review (operator== inconsistency and behavioral note about unsampled traces) still have their existing inline comments and remain relevant. |
a4c6843 to
6d81884
Compare
935c3c7 to
7bded4b
Compare
|
Good, Now let me evaluate what's actionable:
Looking more carefully at the code:
The previous bonk reviews covered the substantive issues well. The remaining open items are:
There are no new actionable issues I can identify beyond what was already flagged. The code is correct, the capnp schemas are wire-compatible, and the propagation logic is sound. LGTM |
6d81884 to
0221517
Compare
94d960c to
50db124
Compare
|
lgtm other than my one comment |
50db124 to
0b079f8
Compare
|
The generated output of |
0b079f8 to
9a389f3
Compare
Uh oh!
There was an error while loading. Please reload this page.