quarkusio/quarkus · error · IllegalStateException
The OpenTelemetry Context is not set
Error message
The OpenTelemetry Context is not set
What it means
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.
Source
Thrown at extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/instrumentation/vertx/HttpInstrumenterVertxTracer.java:515
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 {
private final HttpRequest httpRequest;
private final BiConsumer<String, String> headers;
WriteHeadersHttpRequest(final HttpRequest httpRequest, final BiConsumer<String, String> headers) {
this.httpRequest = httpRequest;
this.headers = headers;
}View on GitHub (pinned to e1c734241f)
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
Example fix
// before io.opentelemetry.context.Context octx = span.getSpanContext(); // throws if null // after io.opentelemetry.context.Context octx = io.opentelemetry.context.Context.current(); // fallback
Defensive patterns
Strategy: type-guard
Validate before calling
if (io.opentelemetry.context.Context.current() == io.opentelemetry.context.Context.root()) {
LOG.warn("No active OTel context; span context may be unset");
} Type guard
static boolean hasSpanContext(HttpInstrumenterVertxTracer.HttpRequestSpan span) {
try {
return span.getSpanContext() != null;
} catch (IllegalStateException e) {
return false;
}
} Try / catch
try {
io.opentelemetry.context.Context octx = span.getSpanContext();
// use octx for tracing decisions
} catch (IllegalStateException e) {
LOG.warn("OTel context not set on request span; falling back to Context.current()");
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The Vert.x Context is not set
- The Vert.x Context to attach the OpenTelemetry Context must
- Connection.OtelApiNotFound
- OpenTelemetryContextUnwrapper was not found
- No current Vertx context found
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/b14585c905b8c861.
Report an issue: GitHub.