Skip to content

OpenTelemetry: MDC context disappears on ManagedExecutor thread #43134

@kerkhofsd

Description

@kerkhofsd

Describe the bug

Given

  • a Quarkus application with installed extensions: quarkus-rest, quarkus-opentelemetry
  • the ManagedExecutor is used to execute work in the background
  • the background work contains log statements

Simplified code sample:

        managedExecutor.execute(() -> {

            executeWorkOnWorkerThread();

            log.info("hello() from ManagedExecutor");
        });

As per my investigation, the "main" thread is calling OpenTelemetryUtil#clearMDCData(io.vertx.core.Context vertxContext), causing the MDC data to be cleared for the "worker" thread as well.

Expected behavior

The tracing specific MDC context is available for log statements of the background work/thread.

Actual behavior

The tracing specific MDC context is not available for log statements.

Sample logging (assuming quarkus.log.console.format is configured to include MDC.traceId)

2024-09-09 10:12:50,788 INFO  traceId= [org.acm.GreetingResource] (executor-thread-1) hello() from ManagedExecutor

How to Reproduce?

Reproducer: https://github.com/kerkhofsd/quarkus-issue-otel-clears-mdc

Output of uname -a or ver

WSL Ubuntu 24.04.1 LTS

Output of java -version

openjdk version "21.0.4" 2024-07-16

Quarkus version or git rev

3.14.2

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)

Additional information

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions