Class DmxObserved
Provides a chainable alternative to DmxObservation when the observation
name and registry are configured at different points:
DmxObserved.of("payment.charge")
.registry(observationRegistry)
.observeTry(() -> stripe.charge(amount));
The same signals are recorded as with DmxObservation.observeTry(String, CheckedSupplier): the
observation is named and tagged with outcome, and on failure the
exception key is set and the observation is marked as error.
Use exceptionClassifier to control the exception key value and
satisfy Micrometer's low-cardinality contract in production. See
DmxObservation.of(ObservationRegistry, 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 itsexceptionkey value.observeResult(CheckedSupplier<V> supplier) Executessupplierinside a new observation.<V> Try<V> observeTry(CheckedSupplier<V> supplier) Executessupplierinside a new observation.static DmxObservedCreates a builder for the given observation name.registry(io.micrometer.observation.ObservationRegistry registry) Sets theObservationRegistryto create observations with.
-
Method Details
-
of
Creates a builder for the given observation name.- Parameters:
name- the observation name; must not benull- Returns:
- a new
DmxObservedbuilder
-
registry
Sets theObservationRegistryto create observations with.- Parameters:
registry- the registry to use; must not benull- Returns:
- this builder
-
exceptionClassifier
Sets the function that maps each failure cause to itsexceptionkey value.The classifier must return a value from a small, bounded set (≤ 100 distinct values) to satisfy Micrometer's low-cardinality contract. When not set, defaults to
getClass().getSimpleName()— an unsafe default in production.- Parameters:
classifier- maps a failure cause to itsexceptionkey value; must not be null, must return bounded values- Returns:
- this builder
-
observeTry
Executessupplierinside a new observation.- 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- ifregistry(ObservationRegistry)was not set
-
observeResult
Executessupplierinside a new observation.- 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- ifregistry(ObservationRegistry)was not set
-