quarkusio/quarkus · error · IllegalStateException

The Vert.x Context is not set

Error message

The Vert.x Context is not set

What it means

`HttpRequestSpan` pairs an HTTP request with the Vert.x Context and the OTel span context. `getContext()` guards these accesses: if no Vert.x Context was captured when the span was created, calling getContext() throws IllegalStateException. Callers such as `ctx()` rely on the context being present to resume tracing on the event loop.

Source

Thrown at extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/instrumentation/vertx/HttpInstrumenterVertxTracer.java:508

        @Override
        public HttpMethod method() {
            return httpRequest.method();
        }

        @Override
        public MultiMap headers() {
            return headers;
        }

        @Override
        public SocketAddress remoteAddress() {
            return httpRequest.remoteAddress();
        }

        public Context getContext() {
            if (context == null) {
                throw new IllegalStateException("The Vert.x Context is not set");
            }
            return context;
        }

        public io.opentelemetry.context.Context getSpanContext() {
            if (spanContext == null) {
                throw new IllegalStateException("The OpenTelemetry Context is not set");
            }
            return spanContext;
        }

        static HttpRequestSpan request(HttpRequest httpRequest, MultiMap headers, Context context,
                io.opentelemetry.context.Context spanContext) {
            return new HttpRequestSpan(httpRequest, headers, context, spanContext);
        }
    }

    private static class WriteHeadersHttpRequest implements HttpRequest {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Ensure the span is created inside a Vert.x handler where a Context exists (getOrCreateContext)
  2. Pass the Vert.x Context explicitly when constructing `HttpRequestSpan.request(...)`
  3. Only call `ctx()` after verifying the request went through the instrumented Vert.x pipeline
  4. Update Quarkus if you hit this via stock instrumentation alone (may be a known bug)

Example fix

// before
io.vertx.core.Context vctx = span.ctx(); // throws if not set
// after
io.vertx.core.Context vctx = io.vertx.core.Vertx.currentContext(); // or ensure span was built with a context
Defensive patterns

Strategy: type-guard

Validate before calling

io.vertx.core.Context vctx = io.vertx.core.Vertx.currentContext();
if (vctx == null) throw new IllegalStateException("Not on a Vert.x context; span context unavailable");

Type guard

static boolean hasVertxContext(HttpInstrumenterVertxTracer.HttpRequestSpan span) {
    try {
        return span.getContext() != null;
    } catch (IllegalStateException e) {
        return false;
    }
}

Try / catch

try {
    io.vertx.core.Context vctx = span.getContext();
    // proceed with tracing logic
} catch (IllegalStateException e) {
    LOG.warn("Vert.x context missing on request span; skipping context-dependent logic");
}

Prevention

When it happens

Trigger: Calling `ctx()`/`getContext()` on an HttpRequestSpan that was constructed with a null Vert.x Context — typically when the request was instrumented before a Context existed (very early in the request lifecycle) or in tests constructing spans manually.

Common situations: Custom Vert.x instrumentation built on the Quarkus tracer internals; handlers executing outside the normal Vert.x context (worker threads, timers) after a span was created without a context; framework bugs during http instrumentation upgrades.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/d065fee4254689eb. Report an issue: GitHub.