quarkus: OpenTelemetry QuarkusContextStorage does not work correctly outside of vert-x duplicated context

Describe the bug

In code running in Quarkus but inside of vert-x but without a duplicated context (e.g. one uses the vert-x web HTTP client), Opentelemetry context calls such as attach() and then current() do not work as expected in that the context passed in attach() is not that when calling current() immediately thereafter.

Expected behavior

Opentelemetry API’s should work outside of a vert-x duplicated context and should fall back to the FALLBACK_CONTEXT_STORAGE

Actual behavior

This code in QuarkusContextStorage results in a call to attach() and then a call to current() both creating a new duplicated context. The state set in attach() is thus not available in the subsequent call to current(). See this:

public static io.vertx.core.Context getVertxContext() {
        io.vertx.core.Context context = Vertx.currentContext();
        if (context != null && VertxContext.isOnDuplicatedContext()) {
            return context;
        } else if (context != null) {
            io.vertx.core.Context dc = VertxContext.createNewDuplicatedContext(context);
            setContextSafe(dc, true);
            return dc;
        }
            return null;
        }
    }

The above code always returns a brand new duplicated context when running within vert-x but outside of a quarkus extension that has set up a duplicated context. This results in the QuarkusContextStorage being unusable as every call looses the prior calls context. I would say it would be better to do this:

public static io.vertx.core.Context getVertxContext() {
        io.vertx.core.Context context = Vertx.currentContext();
        if (context != null && VertxContext.isOnDuplicatedContext()) {
            return context;
        } else {
            return null;
        }
    }

That way the fallback context is used and propagation works as expected.

How to Reproduce?

Use a vert-x plugin directly along with calls to activate a child span and then get the current span

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.3.0

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

No response

Additional information

No response

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Comments: 31 (16 by maintainers)

Most upvoted comments

I’ll try and create a reproducer this afternoon

@geoand You are in a duplicated context in this case. So, I’m surprised the HTTP client does not go back to the duplicated context automatically.

More especially, I would be interested to see on what context this is run: https://github.com/bcluap/quarkus-examples/blob/master/resteasy-reactive/src/main/java/reactive/scenarios/TestRootResource.java#L85