-
Notifications
You must be signed in to change notification settings - Fork 345
Add SELF reference #212
base: master
Are you sure you want to change the base?
Add SELF reference #212
Conversation
I think this change revealed an issue with the SELF reference - one cannot create a proper parent reference unless the parent ID is propagated on the wire, which many systems do not do, and it's not considered as part of https://github.com/TraceContext/tracecontext-spec |
Could you explaint that a bit more? If the parent id is not propagated how would you then create a parent reference? How is this any different when the tracer impl creates the SpanContext? For me, it sounds like TraceContext does include the parentId: https://github.com/TraceContext/tracecontext-spec/blob/master/trace_context/HTTP_HEADER_FORMAT.md#span-id |
I can explain using Jaeger spans as example. When Jaeger span is created, we always record in it trace ID, (new) span ID, and the ID of the parent span. Let's give some values:
Note the parentID=5 part, it establishes the link to the span from the caller service. However, if we serialize that context, we'd only get Again, in Jaeger today it so happens that SELF will work because we actually send parentID over the wire too, but not if we were to use the TraceContext spec, which only sends two IDs, traceID and spanID. It also won't work with the MockTracer in your current PR - you added parentID to the context, but not to the serialization format, so if you marshal and unmarshal the context and create a SELF span, it will be missing the parent. |
That's not the quite use case for the But indeed, when using a TraceContext |
I am not sure why it didn't occur to me earlier, but I think there is a simple solution here. For tracers like MockTracer that do not store parent span id in the SpanContext (and by extension for any generic instrumentation using SELF reference), one just needs to construct another instance of SpanContext and pass it as CHILD_OF. For example, assume we want to create SELF span with traceID=1, spanID=2, parentID=1 (using Python for shorter syntax): tracer.start_span(
"operation name",
references=[
opentracing.self(createVendorContext(traceID=1, spanID=2)),
opentracing.child_of(createVendorContext(traceID=1, spanID=1)),
],
) |
5da56c8
to
b779a02
Compare
I have incorporated @yurishkuro's suggestions and rebased against master. |
if (parent == null) { | ||
// We're a root Span. | ||
this.context = new MockContext(nextId(), nextId(), new HashMap<String, String>()); | ||
this.context = new MockContext(self != null ? self.traceId : nextId(), self != null ? self.spanId : nextId(), | ||
new HashMap<String, String>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't baggage come from self
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/** | ||
* The self reference class can be used to construct a {@link Span} instance with a specific {@link SpanContext}. | ||
*/ | ||
public static final String SELF = "self"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tedsuo should this go through Specification RFC first?
If we are making this a new required reference type, there needs to be more details about the expected tracer behavior and/or description of the use case. For example, what happens to startTime
field in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just seeing this! Yes, @felixbarny an RFC would be appreciated, you can find the template here: https://github.com/opentracing/specification/blob/master/rfc_template.md
As discussed in opentracing/specification#81