The purpose of this repo is to reproduce the issue described here: open-telemetry/opentelemetry-java-instrumentation#7344
./gradlew build
- download OpenTelemetry java agent
- start the application with the following instructions, replacing path to point to the agent downloaded
./gradlew bootRun -PjvmArgs="-javaagent:path/to/opentelemetry-javaagent.jar"
Use cURL or the test.http
script (IntelliJ IDEA).
curl -i -H "traceparent: 00-12345678901234567890123456789012-1234567890123456-01" http://localhost:8080/hello-world
The traceId
and spanId
MDC values are populated and the trace id is 12345678901234567890123456789012
,
as received via W3C Trace Context header. Those values are visible in the logs, in the ExtractBySpringBoot
section.
This logic relies on a ContextStorage wrapper
, implemented here:
https://github.com/spring-projects/spring-boot/blob/b37295936ec46985d2a90dc185bf17d52580117b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/OpenTelemetryAutoConfiguration.java#L157
And the copy of OpenTelemetry Span
trace id/span id into MDC is performed here:
https://github.com/micrometer-metrics/tracing/blob/main/micrometer-tracing-bridges/micrometer-tracing-bridge-otel/src/main/java/io/micrometer/tracing/otel/bridge/Slf4JEventListener.java#L32-L39
The trace id should also be visible in the log in:
- a custom MDC value (
myTraceId
) extracted from the W3C header inCustomMdcW3cTraceFilter
defined in this project - in the logs generated by OpenTelemetry due to
otel.traces.exporter=logging
configuration (env variable)
The traceId
and spanId
MDC values are not set.
This is because the wrapper defined in Spring Boot Actuator Autoconfiguration has been bypassed by OpenTelemetry
Javaagent logic to for the ContextStorage
to always be AgentContextStorage
with no wrapping:
https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/context/AgentContextStorage.java#L112-L114