Package com.babelqueue.otel
Class Tracing
java.lang.Object
com.babelqueue.otel.Tracing
Optional OpenTelemetry tracing for a babelqueue producer or consumer (ADR-0025) — the Java
mirror of the Go
babelqueue-go/otel, Python babelqueue.otel and Node
@babelqueue/core/otel helpers.
Produce/consume spans are correlated across every hop and SDK through the envelope's
trace_id — a UUID, which maps 1:1 to a 32-hex OpenTelemetry trace id (traceIdOf(java.lang.String)
/ uuidOf(java.lang.String)). A non-UUID trace_id is hashed deterministically (SHA-256).
- Consumer:
wrapHandler(io.opentelemetry.api.trace.Tracer, com.babelqueue.idempotency.Handler)emits aCONSUMERspanprocess <urn>in thetrace_id-derived trace, recording the handler's error/status. It reuses the sharedHandler, so it composes withIdempotent.wrap/SchemaValidation.wrap. - Producer:
publish(io.opentelemetry.api.trace.Tracer, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>, com.babelqueue.otel.Sender)emits aPRODUCERspanpublish <urn>that carries the active trace's id into the message'strace_id, then writes it via aSender.
Every hop that shares a trace_id shares one OTel trace. Exact cross-hop span
parent-child linkage (W3C traceparent as a transport header) is a documented follow-up.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringPublishes(urn, data)to the"default"queue under aPRODUCERspan.static Stringpublish(io.opentelemetry.api.trace.Tracer tracer, String urn, Map<String, Object> data, String queue, Sender send) Emits aPRODUCERspanpublish <urn>, carrying the active trace's id into the built envelope'strace_idso the downstream consumer recovers the same trace, then writes the envelope viasend.static StringMaps an envelopetrace_idto a deterministic 32-hex OTel trace id: a UUID maps to its hex bytes; any other string is hashed (SHA-256, first 16 bytes).static StringFormats a 32-hex OTel trace id as a canonical UUID string — the form a producer stamps into the message'strace_idso a consumer can recover the same trace id viatraceIdOf(java.lang.String).static HandlerwrapHandler(io.opentelemetry.api.trace.Tracer tracer, Handler handler) Wraps a consume handler to emit aCONSUMERspan per message, in the OTel trace derived from the envelope'strace_id, recording the handler's error/status.
-
Method Details
-
traceIdOf
Maps an envelopetrace_idto a deterministic 32-hex OTel trace id: a UUID maps to its hex bytes; any other string is hashed (SHA-256, first 16 bytes). Never the all-zero (invalid) trace id. The inverse ofuuidOf(java.lang.String)for the UUID case.- Parameters:
traceId- the envelopetrace_id- Returns:
- a valid 32-hex OTel trace id
-
uuidOf
Formats a 32-hex OTel trace id as a canonical UUID string — the form a producer stamps into the message'strace_idso a consumer can recover the same trace id viatraceIdOf(java.lang.String).- Parameters:
traceIdHex- a 32-hex OTel trace id- Returns:
- the canonical UUID string
-
wrapHandler
Wraps a consume handler to emit aCONSUMERspan per message, in the OTel trace derived from the envelope'strace_id, recording the handler's error/status. The handler receives the fullEnvelopeas before.- Parameters:
tracer- the OTel tracerhandler- the handler to instrument- Returns:
- the wrapped handler
-
publish
public static String publish(io.opentelemetry.api.trace.Tracer tracer, String urn, Map<String, Object> data, Sender send) throws ExceptionPublishes(urn, data)to the"default"queue under aPRODUCERspan. Seepublish(Tracer, String, Map, String, Sender).- Parameters:
tracer- the OTel tracerurn- the message URNdata- the message datasend- the transport write- Returns:
- the published message id (
meta.id) - Throws:
Exception- ifsendfails (recorded on the span and re-thrown)
-
publish
public static String publish(io.opentelemetry.api.trace.Tracer tracer, String urn, Map<String, Object> data, String queue, Sender send) throws ExceptionEmits aPRODUCERspanpublish <urn>, carrying the active trace's id into the built envelope'strace_idso the downstream consumer recovers the same trace, then writes the envelope viasend.- Parameters:
tracer- the OTel tracerurn- the message URNdata- the message dataqueue- the destination queuesend- the transport write- Returns:
- the published message id (
meta.id) - Throws:
Exception- ifsendfails (recorded on the span and re-thrown)
-