Class TraceContext
LogEntryFormatter to populate the optional {traceId} / {spanId} log fields.
Optional / reflective coupling
OpenTelemetry is not a compile-time dependency of juneau-microservice. This class
probes for io.opentelemetry.api.trace.Span via Class.forName(String) at class-load
time — mirroring how MdcAsyncListener reflectively
handles SLF4J. When OTel is absent from the runtime classpath the class gracefully degrades:
isAvailable() returns false and currentTraceId() / currentSpanId()
return the empty string, so the {traceId} / {spanId} placeholders render empty.
Where the id comes from
The id is read from Span.current().getSpanContext() — the OTel context active on the
calling thread. Inside a @RestOp handler (or a custom
observation) wrapped by the OTel
TracerHook, that is the request / observation span. An invalid (no active trace) context
yields the empty string.
- Since:
- 10.0.0
-
Method Summary
-
Method Details
-
isAvailable
Returns whether the OpenTelemetry trace API is available on the runtime classpath.When
false,currentTraceId()andcurrentSpanId()always return the empty string.- Returns:
trueifio.opentelemetry.api.trace.Spanwas found at class-load time.
-
currentTraceId
Returns the trace id of the OTel span active on the current thread.- Returns:
- The 32-char hex trace id, or the empty string when OTel is absent or no valid span is active.
-
currentSpanId
Returns the span id of the OTel span active on the current thread.- Returns:
- The 16-char hex span id, or the empty string when OTel is absent or no valid span is active.
-