Class DmxTraced

java.lang.Object
dmx.fun.tracing.DmxTraced

@NullMarked public final class DmxTraced extends Object
Fluent builder for traced dmx-fun operations.

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 Details

    • of

      public static DmxTraced of(String name)
      Creates a builder for the given span name.
      Parameters:
      name - the span name; must not be null
      Returns:
      a new DmxTraced builder
    • tracer

      public DmxTraced tracer(io.micrometer.tracing.Tracer tracer)
      Sets the Tracer to open spans with.
      Parameters:
      tracer - the tracer to use; must not be null
      Returns:
      this builder
    • exceptionClassifier

      public DmxTraced exceptionClassifier(Function<Throwable, String> classifier)
      Sets the function that maps each failure cause to its exception tag 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 its exception tag value; must not be null, should return bounded values
      Returns:
      this builder
    • traceTry

      public <V> Try<V> traceTry(CheckedSupplier<V> supplier)
      Executes supplier inside a new span.
      Type Parameters:
      V - the value type returned on success
      Parameters:
      supplier - the operation to execute; must not be null
      Returns:
      Success(value) on success, Failure(cause) on any exception
      Throws:
      IllegalStateException - if tracer(Tracer) was not set
    • traceResult

      public <V> Result<V, Throwable> traceResult(CheckedSupplier<V> supplier)
      Executes supplier inside a new span.
      Type Parameters:
      V - the value type returned on success
      Parameters:
      supplier - the operation to execute; must not be null
      Returns:
      Ok(value) on success, Err(cause) on any exception
      Throws:
      IllegalStateException - if tracer(Tracer) was not set