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

Propagate trace_flags from parent span to child span #603

Merged
merged 4 commits into from
Mar 10, 2021

Conversation

ThomsonTan
Copy link
Contributor

Fixes #602

Changes

trace_flags is propagated from parent span to child span at span creation time.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@ThomsonTan ThomsonTan requested a review from a team March 9, 2021 22:47
@codecov
Copy link

codecov bot commented Mar 9, 2021

Codecov Report

Merging #603 (a1dff50) into main (3d71e5e) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #603      +/-   ##
==========================================
+ Coverage   94.40%   94.42%   +0.01%     
==========================================
  Files         191      191              
  Lines        9023     9053      +30     
==========================================
+ Hits         8518     8548      +30     
  Misses        505      505              
Impacted Files Coverage Δ
sdk/src/trace/span.h 100.00% <ø> (ø)
sdk/src/trace/span.cc 89.47% <100.00%> (ø)
sdk/src/trace/tracer.cc 74.28% <100.00%> (ø)
sdk/test/trace/tracer_test.cc 100.00% <100.00%> (ø)

trace_api::SpanId span_id = GenerateRandomSpanId();
bool is_parent_span_valid = false;
trace_api::SpanId span_id = GenerateRandomSpanId();
trace_api::TraceFlags trace_flags = parent_span_context.trace_flags();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about propagating trace_flags only for valid SpanContext, but since we could create a invalid SpanContextwith non-zerotrace_flags`, so I choose to do propagation even for invalid span. Let me know if you prefer the other case.

Copy link

@stevchin stevchin left a comment

Choose a reason for hiding this comment

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

Thanks Tom for the fix. Looks good to me...

@ThomsonTan
Copy link
Contributor Author

Thanks Tom for the fix. Looks good to me...

Thanks @stevchin for trying opentelemetry-cpp, reporting this issue and helping on troubleshooting!

@@ -94,7 +95,7 @@ Span::Span(std::shared_ptr<Tracer> &&tracer,
}

span_context_ = std::unique_ptr<trace_api::SpanContext>(
new trace_api::SpanContext(trace_id, span_id, trace_api::TraceFlags(), false,
new trace_api::SpanContext(trace_id, span_id, trace_flags, false,
Copy link
Member

@lalitb lalitb Mar 10, 2021

Choose a reason for hiding this comment

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

Not sure if I am missing something here - Why do we need to copy the parent's trace_flags to child span. For sampling-bit in child's span trace_flag it should be determined as below -

  • Run sampling algo to decide whether child span should be sampled - the sampling algo may use parent's span trace_flags for decision making.
  • In case the child span should be sampled ( as decided by above sampling algo ) - we should set the sampling-bit in child span trace_flag.

Or is there more information in parent's trace_flag ( other than sampling-bit) which we want to copy from parent ? If that is the case, we should copy that first and then overwrite sampling bit based on decision from above logic.

Though our current implementation is also wrong - as it's assigning 0x00 to trace_flags even if it's is supposed to be sampled. This should be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean we set kIsSampled directly in the above code line because the location implies sampling should be enabled, instead of copying trace_flags from parent SpanContext? If so, I think we could keep the same sampled value as parent to be consistent and leave the decision to sampler, like even the IsSampled is off, some sampler may still sample it anyway. But I am fine to set the sampled bit here too.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Do you mean we set kIsSampled directly in the above code line because the location implies sampling should be enabled, instead of copying trace_flags from parent SpanContext?

Yes, as we are creating the span (and sampling decision happens before that in tracer), that means decision has already been made by sampler to sample it, and we should just be setting sampling-bit in the span's trace_flag irrespective of what is there in parent's trace_flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lalitb thanks for the links. Set sampled based sampler decision makes sense. Updated the PR accordingly.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing it.

@lalitb lalitb merged commit a33bb55 into open-telemetry:main Mar 10, 2021
@ThomsonTan ThomsonTan deleted the FixTraceFlagsPropagation branch November 9, 2022 22:55
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

Successfully merging this pull request may close these issues.

TraceFlags is not propagated from parent span span to child span
4 participants