Class DmxTraced
Provides a chainable alternative to DmxTracing when the span name and
tracer are configured at different points:
DmxTraced.of("payment.charge")
.tracer(tracer)
.traceTry(() -> stripe.charge(amount));
The same signals are recorded as with DmxTracing.traceTry(String, CheckedSupplier): the span is
named, tagged with outcome, and on failure the exception tag is set
and the span is marked as error.
Use exceptionClassifier to control the exception tag value and
keep tag cardinality bounded in tracing backends. See
DmxTracing.of(Tracer, java.util.function.Function) for details.
This builder is mutable and not thread-safe; do not share one instance across concurrent per-call reconfigurations.
-
Method Summary
Modifier and TypeMethodDescriptionexceptionClassifier(Function<Throwable, String> classifier) Sets the function that maps each failure cause to itsexceptiontag value.static DmxTracedCreates a builder for the given span name.tracer(io.micrometer.tracing.Tracer tracer) Sets theTracerto open spans with.traceResult(CheckedSupplier<V> supplier) Executessupplierinside a new span.<V> Try<V> traceTry(CheckedSupplier<V> supplier) Executessupplierinside a new span.
-
Method Details
-
of
-
tracer
Sets theTracerto open spans with.- Parameters:
tracer- the tracer to use; must not benull- Returns:
- this builder
-
exceptionClassifier
Sets the function that maps each failure cause to itsexceptiontag value.The classifier should return a value from a small, bounded set to keep tag cardinality predictable in tracing backends. When not set, defaults to
getClass().getSimpleName()— an unsafe default in production.- Parameters:
classifier- maps a failure cause to itsexceptiontag value; must not be null, should return bounded values- Returns:
- this builder
-
traceTry
Executessupplierinside a new span.- Type Parameters:
V- the value type returned on success- Parameters:
supplier- the operation to execute; must not benull- Returns:
Success(value)on success,Failure(cause)on any exception- Throws:
IllegalStateException- iftracer(Tracer)was not set
-
traceResult
Executessupplierinside a new span.- Type Parameters:
V- the value type returned on success- Parameters:
supplier- the operation to execute; must not benull- Returns:
Ok(value)on success,Err(cause)on any exception- Throws:
IllegalStateException- iftracer(Tracer)was not set
-