{"record":{"id":"d065fee4254689eb","repo":"quarkusio/quarkus","slug":"the-vert-x-context-is-not-set","errorCode":null,"errorMessage":"The Vert.x Context is not set","messagePattern":"The Vert\\.x Context is not set","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/instrumentation/vertx/HttpInstrumenterVertxTracer.java","lineNumber":508,"sourceCode":"\n        @Override\n        public HttpMethod method() {\n            return httpRequest.method();\n        }\n\n        @Override\n        public MultiMap headers() {\n            return headers;\n        }\n\n        @Override\n        public SocketAddress remoteAddress() {\n            return httpRequest.remoteAddress();\n        }\n\n        public Context getContext() {\n            if (context == null) {\n                throw new IllegalStateException(\"The Vert.x Context is not set\");\n            }\n            return context;\n        }\n\n        public io.opentelemetry.context.Context getSpanContext() {\n            if (spanContext == null) {\n                throw new IllegalStateException(\"The OpenTelemetry Context is not set\");\n            }\n            return spanContext;\n        }\n\n        static HttpRequestSpan request(HttpRequest httpRequest, MultiMap headers, Context context,\n                io.opentelemetry.context.Context spanContext) {\n            return new HttpRequestSpan(httpRequest, headers, context, spanContext);\n        }\n    }\n\n    private static class WriteHeadersHttpRequest implements HttpRequest {","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/instrumentation/vertx/HttpInstrumenterVertxTracer.java#L490-L526","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the span is created inside a Vert.x handler where a Context exists (getOrCreateContext)","Pass the Vert.x Context explicitly when constructing `HttpRequestSpan.request(...)`","Only call `ctx()` after verifying the request went through the instrumented Vert.x pipeline","Update Quarkus if you hit this via stock instrumentation alone (may be a known bug)"],"exampleFix":"// before\nio.vertx.core.Context vctx = span.ctx(); // throws if not set\n// after\nio.vertx.core.Context vctx = io.vertx.core.Vertx.currentContext(); // or ensure span was built with a context","handlingStrategy":"type-guard","validationCode":"io.vertx.core.Context vctx = io.vertx.core.Vertx.currentContext();\nif (vctx == null) throw new IllegalStateException(\"Not on a Vert.x context; span context unavailable\");","typeGuard":"static boolean hasVertxContext(HttpInstrumenterVertxTracer.HttpRequestSpan span) {\n    try {\n        return span.getContext() != null;\n    } catch (IllegalStateException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    io.vertx.core.Context vctx = span.getContext();\n    // proceed with tracing logic\n} catch (IllegalStateException e) {\n    LOG.warn(\"Vert.x context missing on request span; skipping context-dependent logic\");\n}","preventionTips":["Create spans only inside Vert.x handlers where a Context exists","Don't construct HttpRequestSpan manually with a null context in tests","Keep custom Vert.x instrumentation aligned with the Quarkus tracer API version"],"tags":["opentelemetry","vertx","tracing","context"],"backgroundTag":"missing-context-state","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}