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

fix: propagate the b3 parentspanid. fixes regression of (#1338) #1608

Closed
wants to merge 1 commit into from
Closed

Conversation

dblackhall-tyro
Copy link

Signed-off-by: dblackhall-tyro 39076155+dblackhall-tyro@users.noreply.github.com

Which problem is this PR solving?

There is a regression in 0.12 with the B3Propagator not propagating the parent span id.

Short description of the changes

Created a B3_PARENT_SPAN_ID_KEY which is used to inject and extract the parent span id.

Signed-off-by: dblackhall-tyro <39076155+dblackhall-tyro@users.noreply.github.com>
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 21, 2020

CLA Check
The committers are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Oct 21, 2020

Codecov Report

Merging #1608 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1608      +/-   ##
==========================================
+ Coverage   91.18%   91.21%   +0.02%     
==========================================
  Files         164      164              
  Lines        5024     5040      +16     
  Branches     1026     1033       +7     
==========================================
+ Hits         4581     4597      +16     
  Misses        443      443              
Impacted Files Coverage Δ
...-core/src/context/propagation/B3MultiPropagator.ts 100.00% <100.00%> (ø)
...elemetry-core/src/context/propagation/b3-common.ts 100.00% <100.00%> (ø)

@dyladan dyladan added the bug Something isn't working label Oct 21, 2020
Copy link
Member

@mwear mwear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comments below. I don't think the parentSpanId being propagated in this PR is correct, and I don't think this can be fixed without a specification change because it is not possible to read a parent span id given the current span API. The code that previously propagated parent span id was intentionally removed as a result.

@@ -95,11 +107,24 @@ function getTraceFlags(
export class B3MultiPropagator implements TextMapPropagator {
inject(context: Context, carrier: unknown, setter: TextMapSetter) {
const spanContext = getParentSpanContext(context);
if (!spanContext || !isSpanContextValid(spanContext)) return;
const parentSpanId = context.getValue(B3_PARENT_SPAN_ID_KEY) as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the parent span id of the extracted request, which is incorrect unless no other in-process spans have been created. Unfortunately, I don't see a way to propagate the parent span id for in-process spans using OpenTelemetry. While parentSpanId is available on ReadableSpan in the export pipeline, it's not part of the Span API.

For B3, the parentSpanId is propagated so that both sides of a request can share the same span id. OpenTelemetry does not support span id sharing. By omitting parentSpanId, a downstream service should generate a new span id for the inbound request.

See the b3 spec (https://github.com/openzipkin/b3-propagation):

Some propagation formats look similar to B3, but don't propagate a field named parent. Instead, they propagate a span ID field which serves the same purpose as ParentSpanId. Unlike B3, these systems use a different span ID for the client and server side of an RPC. When a server reads headers like this, it is expected to provision a new span ID for itself, and use the one it extracted as its parent.

...

In both B3 and the above example, incoming headers contain the parent's span ID, and three IDs (trace, parent, span) end up in the trace context. The difference is that B3 uses the same span ID for the client and server side of an RPC, where the latter does not.

See also this spec PR: open-telemetry/opentelemetry-specification#1045

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw your comment here: open-telemetry/opentelemetry-specification#1045 (comment)
Thanks for taking this into consideration :) I will close this PR, and keep following the progress with B3.
And thanks for taking the time to explain why parentSpanId propagation was intentionally removed.

pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants