Implement B3 propagation#265
Implement B3 propagation#265reyang merged 7 commits intocensus-instrumentation:masterfrom jpoehnelt:feat/b3-propagation
Conversation
|
@songy23 @liyanhui1228 ptal when you have a chance |
| @@ -0,0 +1,89 @@ | |||
| # Copyright 2017, OpenCensus Authors | |||
| @@ -0,0 +1,104 @@ | |||
| # Copyright 2017, OpenCensus Authors | |||
| from opencensus.trace.span_context import SpanContext, INVALID_SPAN_ID | ||
| from opencensus.trace.trace_options import TraceOptions | ||
|
|
||
| _TRACE_ID_KEY = 'x-b3-traceid' |
There was a problem hiding this comment.
A naive question: does the case matter here? I saw the Zipkin specs used "X-B3-TraceId", "X-B3-SpanId", "X-B3-ParentSpanId" and "X-B3-Sampled" here.
There was a problem hiding this comment.
Header names are case-insensitive (and forced lower case in HTTP/2)
There was a problem hiding this comment.
most send X-B3 in the case format you mention even in case sensitive contexts. the new "b3" header should always be lowercase.
There was a problem hiding this comment.
Maybe it'd be worth adding support for the new b3 single header in this PR too?
| _SPAN_ID_KEY = 'x-b3-spanid' | ||
| _PARENT_SPAN_ID_KEY = 'x-b3-parentspanid' | ||
| _SAMPLED_KEY = 'x-b3-sampled' | ||
|
|
There was a problem hiding this comment.
I think there's also a "X-B3-Flags" header.
|
Can we also combine the code in #168 to this PR to let the flask, django, pyramid integrations be able to recognize the B3 format? Or we can put that part in a separate PR. This PR LGTM. |
Just took a look at the Java implementation, looks like ParentSpanId should not be propagated: https://github.com/census-instrumentation/opencensus-java/pull/889/files#r155878293. /cc @adriancole |
|
parent should be propagated definitely if RPC. We have done some work to
lower impact when not set but that doesn't mean it should not be attempted.
messaging can safely leave out parent.
x-b3-flags means force trace and really only ever set to 1 (header left out
otherwise). if there is no force/debug trace feature main thing is just
propagating what if any was incoming
|
It already works because of @reyang's refactoring. Just have to set
Right, the issue here is that our propagators basically act as (de)serializers for |
|
@kornholi regarding "SpanContext currently does not encode that information", would you try putting the info in SpanContext.tracestate (which is an ordered-key-value-pair intended for extensibility)? |
|
the b3 tracestate entry is imho done, but waiting a few more nods
openzipkin/b3-propagation#21
…On Sat, Aug 25, 2018 at 6:04 AM Reiley Yang ***@***.***> wrote:
@kornholi <https://github.com/kornholi> regarding "SpanContext currently
does not encode that information", would you try putting the info in
SpanContext.tracestate
<#259>
(which is an ordered-key-value-pair intended for extensibility
<https://github.com/w3c/distributed-tracing/blob/master/trace_context/HTTP_HEADER_FORMAT.md#tracestate-field>
)?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#265 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAD615LbmKphIj36AbMgvMwkarMZpXXSks5uUHhTgaJpZM4WE0E0>
.
|
|
I think this is ready to be merged. Regarding ParentSpanId and Debug headers, the other implementations strip them away so we should do the same here. See https://github.com/census-instrumentation/opencensus-go/blob/264a2a48d94c062252389fffbc308ba555e35166/plugin/ochttp/propagation/b3/b3.go#L35-L43 etc. It's still unclear to me why we're piggybacking on the B3 name if it's not actually B3 (split client/server spans). |
| """ | ||
|
|
||
| def from_headers(self, headers): | ||
| """Generate a SpanContext object using the trace context headers. |
There was a problem hiding this comment.
The comment has "trace context headers" while the code is using Zipkin headers.
Perhaps we should remove these excessive comments? I don't find them quite useful as I can tell what the function is doing from its name "from_headers".
There was a problem hiding this comment.
I agree. However they are short enough so I just clarified the B3 part. We need to set some guidelines as right now the comment quality/quantity varies greatly.
codefromthecrypt
left a comment
There was a problem hiding this comment.
X-B3-Flags is only valid if set to '1' and when set implied sampled and also should set span.debug=true when sent out of band.
|
|
||
| trace_id = headers.get(_TRACE_ID_KEY) | ||
| span_id = headers.get(_SPAN_ID_KEY) | ||
| sampled = headers.get(_SAMPLED_KEY) == '1' |
There was a problem hiding this comment.
the header can be absent. when it is it should be sampled using whatever your heuristic is not set to unsampled. make sense?
There was a problem hiding this comment.
From what I understand this will work if it's missing, because later we call .enabled or .should_sample here
|
if it is still open (looks the case), then yeah probably worth adding b3 single indeed |
|
Hey, I'd love this to get merged. What is required exactly? |
|
Support for the single-header b3 format has been added, but I have no way to test it in the real world. I think at this point the PR should be good to go. There are some remaining issues, but I don't think this is the place to solve them right now. From the top of my mind:
|
|
@liyanhui1228 how should we move forward? |
|
Hey @kornholi, I'm working with @liyanhui1228 and can take a look at this PR this week. |
|
@c24t ping |
|
Sorry to hold you up here, will take a look soon. |
|
@kornholi would you help to update the branch? Let's get this merged given the major part looks good. We can track issues in case there are open questions, we shouldn't get blocked here entirely. (once the branch got updated, we will wait for 24 hours to see if people have strong objections before I go ahead and merge) Once this got this PR merged, we can close #168 since it is a duplicated effort. @JustinWP |
|
Thanks @reyang, I rebased the branch. I agree on fixing the rest of issues separately, this has been sitting here too long :) |
Supersedes #168.
This works for our usecase (in-app spans for requests in an Istio mesh, exported directly to Stackdriver), but it's not correct since ParentSpanId is not propagated correctly.
See https://github.com/openzipkin/b3-propagation/blob/682d1fc9caa31fa25678674a3a7a1ecd4e9f7813/README.md#why-is-parentspanid-propagated
Should
to_headerstake a parentSpanContext, or should the parent be included inSpanContext?