Skip to content
Open
Show file tree
Hide file tree
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 @@ -23,6 +23,8 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.Context;
import java.io.IOException;

/**
Expand Down Expand Up @@ -77,6 +79,10 @@ public void initialize(HttpRequest request) throws IOException {
// No active span to exists, skip instrumentation
return;
}
// propagate the W3C Trace Context (traceID and spanID) from the active span in headers
W3CTraceContextPropagator.getInstance()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IIUC, this is to ensure that the parent span's traceID and SpanID values are injected into the current span?

Or is this doing something different?

Copy link
Copy Markdown
Contributor Author

@ldetmer ldetmer Mar 27, 2026

Choose a reason for hiding this comment

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

no, this is just adding the traceID/spanID into a standard opentelemetry header for tracking purposes. See requirement here. Using the library ensures it pulls the current span from context and creates it following the W3C standard for header label/format.

.inject(Context.current(), request.getHeaders(), HttpHeaders::set);

addInitialHttpAttributesToSpan(span, request);

HttpResponseInterceptor originalInterceptor = request.getResponseInterceptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,23 @@ public void testNoSpanIsCreatedIfNoActiveSpan() throws IOException {
verify(delegateInitializer, times(1)).initialize(any(HttpRequest.class));
}

@Test
public void testTraceContextIsPropagatedInHeaders() throws IOException {
HttpTransport transport = createTransport();
HttpRequest request = buildGetRequest(transport, initializer, BASE_URL);

HttpResponse response = request.execute();
response.disconnect();

assertEquals(
String.format(
"00-%s-%s-%s",
parentSpan.getSpanContext().getTraceId(),
parentSpan.getSpanContext().getSpanId(),
parentSpan.getSpanContext().getTraceFlags().asHex()),
request.getHeaders().get("traceparent"));
}

@Test
public void testDelegateInitializerIsCalled() throws IOException {
HttpRequestInitializer delegateInitializer = mock(HttpRequestInitializer.class);
Expand Down
Loading