-
Notifications
You must be signed in to change notification settings - Fork 54
Closed
Labels
Milestone
Description
The following code does not work with the OtelTracer
. We expect that the span has trace ID equal to the one we specified in the parent context, but it actually ends up using Context.current()
.
@Test
void manualparentContext() {
TraceContext parentCtx =
tracer.traceContextBuilder()
.traceId(TRACE_ID)
.spanId(SPAN_ID)
.sampled(SAMPLING_FLAG)
.build();
Span span =
tracer.spanBuilder().setParent(parentCtx)
.name("test-span").start();
assertThat(span.context().traceId()).isEqualTo(TRACE_ID);
}
This can be achieved using the OTel API in such a way that this repo does not seem to implement:
io.opentelemetry.api.trace.Tracer otelTracer;
@Test
void manualParentContextOtel() {
SpanContext spanCtx = SpanContext
.createFromRemoteParent(
TRACE_ID,
SPAN_ID,
TraceFlags.fromByte((byte)1),
TraceState.getDefault());
Context ctx = Context.current().with(io.opentelemetry.api.trace.Span.wrap(spanCtx));
io.opentelemetry.api.trace.Span span = otelTracer
.spanBuilder("s")
.setParent(ctx)
.startSpan();
try (Scope ignored = span.makeCurrent()) {
doStuff();
} finally {
span.end();
}
}
I believe the problem is in the toOtelContext()
method, and doesn't use the Span.wrap()
method.