Skip to content
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

W3C propagates the wrong parent spanID #986

Closed
pnerg opened this issue Apr 7, 2021 · 1 comment
Closed

W3C propagates the wrong parent spanID #986

pnerg opened this issue Apr 7, 2021 · 1 comment

Comments

@pnerg
Copy link
Contributor

pnerg commented Apr 7, 2021

Looks like the W3C context propagation uses a new spanID as the parent.

Did a small test app that received a request and forwarded it again to itself just to see what headers are propagated.
So the flow is postman -> app (/forward) -> app (/hello) and response all the way back in the chain

Test 1 - Sent traceparent header to app

Sent the header traceparent: Some(00-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-0000000000000000-01)
The printout is like

Got request for '/forward' with w3c header [Some(00-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb-0000000000000000-01)] and parsed/generated context traceId[bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb], spanId[b4e99c809b29b7fa], parentSpanId[0000000000000000]
Got request for '/hello' with w3c header [Some(00-BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB-A4B5DFB07D82F430-01)] and parsed/generated context traceId[], spanId[230e25c602c0b2bc], parentSpanId[]

We see from the printout that the W3C propagation has read the headers and created a new local spanID (b4e99c809b29b7fa) as expected.
Trace and parent span identifiers are set in the local context.
However when the request is sent to the next part (/hello) we can see that the header is an odd parentSpanID (A4B5DFB07D82F430). This should have been 'b4e99c809b29b7fa'

The "empty" trace/span ids in the log is due to #985

Test 2 - No headers are sent to the app

The printout is like

Got request for '/forward' with w3c header [None] and parsed/generated context traceId[1aaf4ba3617d76f2441f0fc3879a1a3f], spanId[b16fd11b8393437c], parentSpanId[]
Got request for '/hello' with w3c header [Some(00-1AAF4BA3617D76F2441F0FC3879A1A3F-45B2C2A25AE39FB3-00)] and parsed/generated context traceId[], spanId[a547524af1953855], parentSpanId[]

Same situation, we see a new context is created with trace/span identifiers. But again when the context is propagated we see the sent parentId is '45B2C2A25AE39FB3' but the span that sent the request was 'b16fd11b8393437c'

Conclusion

I'm assuming a new spanID has been created before passing the context down to the
writer operation
The code simply writes the header as:

s"$Version-${idToHex(parent.trace.id, 32)}-${idToHex(parent.id, 16)}-${samplingDecision}"

I'm guessing the parent.id is a newly created spanID and not the current one doing the actual HTTP request.
This is the difference between B3 and W3C propagation, the sending side in B3 allocates a new SpanId and sends over.
W3C only sends the parentID and lets the receiving end deal with creating the new SpanID.
Guessing this leaks into the propagation by allocating a new SpanId before providing the context to the writer operation.

SimunKaracic added a commit that referenced this issue Apr 12, 2021
fix for w3c propagation of the proper parentSpanId (#986)
@SimunKaracic
Copy link
Contributor

Fixed in 2.1.16!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants