{"record":{"id":"b14585c905b8c861","repo":"quarkusio/quarkus","slug":"the-opentelemetry-context-is-not-set","errorCode":null,"errorMessage":"The OpenTelemetry Context is not set","messagePattern":"The OpenTelemetry 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":515,"sourceCode":"        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 {\n        private final HttpRequest httpRequest;\n        private final BiConsumer<String, String> headers;\n\n        WriteHeadersHttpRequest(final HttpRequest httpRequest, final BiConsumer<String, String> headers) {\n            this.httpRequest = httpRequest;\n            this.headers = headers;\n        }","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/instrumentation/vertx/HttpInstrumenterVertxTracer.java#L497-L533","documentation":"Companion to getContext(): `getSpanContext()` throws IllegalStateException when the OpenTelemetry Context was not captured on the HttpRequestSpan. It guarantees downstream code never traces against a null span context. It fires when instrumentation created a request span without an OTel context available.","triggerScenarios":"Accessing `getSpanContext()` on an HttpRequestSpan built with a null `io.opentelemetry.context.Context` — e.g. when span creation was bypassed before the OTel context was activated.","commonSituations":"Custom extensions or filters reading tracer span state before instrumentation ran; async handoffs where the OTel context was not propagated with the request; version mismatch between the tracer and callers built against older internals.","solutions":["Ensure the OTel context is activated before the request span is created (scope propagation through the Vert.x pipeline)","Propagate the `io.opentelemetry.context.Context` explicitly when constructing `HttpRequestSpan.request(...)`","Call `getSpanContext()` only after successful instrumented dispatch","Upgrade Quarkus/OTel if triggered by stock instrumentation"],"exampleFix":"// before\nio.opentelemetry.context.Context octx = span.getSpanContext(); // throws if null\n// after\nio.opentelemetry.context.Context octx = io.opentelemetry.context.Context.current(); // fallback","handlingStrategy":"type-guard","validationCode":"if (io.opentelemetry.context.Context.current() == io.opentelemetry.context.Context.root()) {\n    LOG.warn(\"No active OTel context; span context may be unset\");\n}","typeGuard":"static boolean hasSpanContext(HttpInstrumenterVertxTracer.HttpRequestSpan span) {\n    try {\n        return span.getSpanContext() != null;\n    } catch (IllegalStateException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    io.opentelemetry.context.Context octx = span.getSpanContext();\n    // use octx for tracing decisions\n} catch (IllegalStateException e) {\n    LOG.warn(\"OTel context not set on request span; falling back to Context.current()\");\n}","preventionTips":["Activate the OTel scope before request dispatch so the span captures its context","Propagate the OTel context across async boundaries (Context.makeCurrent / wrapping)","Avoid reading tracer span internals before instrumentation ran"],"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"}