Class DmxMetered
Provides a chainable alternative to DmxMicrometer when the metric name,
tags, and registry are configured at different points:
DmxMetered.of("payment.charge")
.tags(Tags.of("provider", "stripe"))
.registry(registry)
.recordTry(() -> stripe.charge(amount));
The same metrics are recorded as with DmxMicrometer.recordTry(String, Tags, CheckedSupplier):
{name}.count, {name}.duration, and {name}.failure.
This builder is mutable and not thread-safe; avoid sharing one instance for concurrent per-call reconfiguration.
Use exceptionClassifier to control the exception tag value and
satisfy Micrometer's low-cardinality contract in production. See
DmxMicrometer.of(MeterRegistry, java.util.function.Function) for details.
-
Method Summary
Modifier and TypeMethodDescriptionexceptionClassifier(Function<Throwable, String> classifier) Sets the function that maps each failure cause to itsexceptiontag value.static DmxMeteredCreates a builder for the given metric name.recordResult(CheckedSupplier<V> supplier) Executes the supplier and records metrics.<V> Try<V> recordTry(CheckedSupplier<V> supplier) Executes the supplier and records metrics.registry(io.micrometer.core.instrument.MeterRegistry registry) Sets theMeterRegistryto register metrics with.tags(io.micrometer.core.instrument.Tags tags) Sets the tags to attach to all metrics for this operation.
-
Method Details
-
of
Creates a builder for the given metric name.- Parameters:
name- the base metric name; must not be null- Returns:
- a new
DmxMeteredbuilder
-
tags
Sets the tags to attach to all metrics for this operation.- Parameters:
tags- the tags to apply; must not be null- Returns:
- this builder
-
registry
Sets theMeterRegistryto register metrics with.- Parameters:
registry- the registry to use; must not be null- Returns:
- this builder
-
exceptionClassifier
Sets the function that maps each failure cause to itsexceptiontag value.The classifier must return a value from a small, bounded set to satisfy Micrometer's low-cardinality requirement. 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, must return bounded values- Returns:
- this builder
-
recordTry
Executes the supplier and records metrics.- 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- ifregistry(MeterRegistry)was not set
-
recordResult
Executes the supplier and records metrics.- 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- ifregistry(MeterRegistry)was not set
-