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

Issue 6037 - Wrapping "invalid" SpanContexts in Span does not preserve SpanContext #6044

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,13 @@ static Span getInvalid() {
/**
* Returns a non-recording {@link Span} that holds the provided {@link SpanContext} but has no
* functionality. It will not be exported and all tracing operations are no-op, but it can be used
* to propagate a valid {@link SpanContext} downstream.
* to propagate a {@link SpanContext} downstream.
*/
static Span wrap(SpanContext spanContext) {
if (spanContext == null) {
ApiUsageLogger.log("context is null");
return getInvalid();
}
if (!spanContext.isValid()) {
Copy link
Member

Choose a reason for hiding this comment

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

This seems to make sense to me, but the javadoc above somewhat implies that this behavior:

It will not be exported and all tracing operations are no-op, but it can be used to propagate a valid {@link SpanContext} downstream.

Can we remove the word "valid"?

Also, you could argue this is breaking behavior change, but I don't think so. If you provide an invalid span context (i.e. invalid span id / trace id) but useful TraceFlags / TraceState, you'll still get a Span with an invalid span context back. It would be odd for someone to be relying on the behavior of Span.wrap(SpanContext clearing effectively clearing TraceFlags / TraceState when span id and trace id are invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I fully agree. Furthermore, I think that using valid or invalid with respect to the SpanContext is a bit misleading. The context represents an empty trace (i.e. with no spans yet), and every trace starts from such a context.

return getInvalid();
}
return PropagatedSpan.create(spanContext);
}

Expand Down