APM Agent language and version: Java, 1.50.0
Original install method (e.g. download page, yum, deb, from source, etc.) and version: downloaded from Maven repository
Is there anything special in your setup?: usual Spring application with micrometer-tracing-bridge-otel
Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
When a new Micrometer scope is opened, or a baggage is added, it is expected that the traceId/spanId/custom baggage is also put in the MDC. How the MDC is decorated is an implementation detail of the bridge between Micrometer and the underlying observability system: for example, everything works fine using the APM Agent, Micrometer and Brave.
When using Micrometer and Opentelemetry, a custom io.opentelemetry.context.ContextStorage
is used (io.micrometer.tracing.otel.bridge.EventPublishingContextWrapper$1
, source here, relevant method is attach
); this ContextStorage
has some logic, using Micrometer API, to publish events to registered listeners. Some of such listeners are responsible to update the MDC.
Yet, when also using the APM Agent, a different ContextStorage
is used (co.elastic.apm.agent.opentelemetry.context.OTelContextStorage
, source here); this ContextStorage
does not wrap existing EventPublishingContextWrapper$1
so the events are never published.
Is there a way to use the APM Agent keeping also the Micrometer functionality?
Steps to reproduce:
- Build a minimal Spring web application, using micrometer-tracing-bridge-otel, which logs the content of the MDC.
- Run the application without the APM Agent and perform a HTTP request to the application; in the logs the spanId/traceId/custom baggage should be present.
- Set up the Java agent as usual (as here).
- Run the application with the APM Agent and perform a HTTP request to the application; in the logs the spanId/traceId/custom baggage are not present.