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

Add support for Trace Context headers #82

Merged
merged 2 commits into from
Dec 5, 2019
Merged

Add support for Trace Context headers #82

merged 2 commits into from
Dec 5, 2019

Conversation

ocelotl
Copy link
Contributor

@ocelotl ocelotl commented Nov 7, 2019

Closes #79

@ocelotl ocelotl force-pushed the trace_context branch 3 times, most recently from 9d1a729 to 3b1a3c0 Compare November 8, 2019 17:25
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Overall looks pretty good! Just minor changes.

# The TRACE_CONTEXT format represents SpanContexts in Trace Context format.
# https://www.w3.org/TR/trace-context/
TRACE_CONTEXT = "trace_context"

Copy link
Contributor

Choose a reason for hiding this comment

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

Not seeing this being used anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, removed!

tracestate_dictionary[key] = value

else:
trace_context_free_carrier["tracestate"] = ",".join(
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor change here: should use _TRACESTATE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

format(span_context.baggage.pop("trace-flags", 0), "02x")
)

carrier.update(span_context.baggage)
Copy link
Contributor

Choose a reason for hiding this comment

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

We are dropping our own baggage here, right? I'm afraid that this will clash with some other fields/data already existing in the carrier. I don't remember this from the W3C, but will double check ;)

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 want this removed now, or should I wait for your double-check?

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets go ahead and keep it like this (open a ticket so we can double verify later ;) )

traceparent = value

else:
raise Exception(
Copy link
Contributor

Choose a reason for hiding this comment

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

What about SpanContextCorruptedException?

Copy link
Contributor

Choose a reason for hiding this comment

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

And same for the errors below (I know you put a FIXME, but I think it should be straightforward to replace almost all of them with SpanContextCorruptedException ;) )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!


trace_context_free_carrier = {}

for key, value in carrier.items():
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to protect here ourselves, in case carrier has no items(), so we report instead an InvalidCarrierException instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But, if there are no items, then the for loop won't be accessed, traceparent will be None and we'll end up here. Isn't it the right flow? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, in case the carrier has no items() method ;) (not super important, so we can also keep it like this with a related Issue and fix later on).

"Unable to parse version from traceparent"
)
return SpanContext(
trace_id=getrandbits(128), span_id=getrandbits(64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we cool here using 128-bits for trace id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The document specifies 16 bytes for trace-id. Am I understanding this wrong? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, we need to use 16 bytes for the format (and propagate 16 bytes ids as well). But I'm not sure we properly handle such a long id in the rest of the code base (SpanContext within lightstep module), nor the backend.

I.e. we should do what we did for B3, where we propagate the 'original' id but internally use only 8 bytes ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@codeboten what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@carlosalberto after discussing this with @codeboten I have submitted a commit that truncates the value of trace_id automatically when exiting a span context. I think this is the right approach, since we should keep the span context attributes as they are for inject and extract and only do truncation for LightStep specific code.

"Received an invalid traceparent: {}".format(traceparent)
)
return SpanContext(
trace_id=getrandbits(128), span_id=getrandbits(64)
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise.

@carlosalberto
Copy link
Contributor

Hey, just reviewed the updated code. Just for reference, in Java/C# we kept the original, long trace id in the SpanContext, so it can be consumed by B3/TraceContext propagators, while internally using the trimmed trace id.

The code here looks right though, and as long as you guys are comfortable with it, I'm fine as well.

@ocelotl ocelotl merged commit 000bce9 into master Dec 5, 2019
@ocelotl ocelotl deleted the trace_context branch December 5, 2019 20:40
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.

Add support for trace-context headers
4 participants