
entry-point.async-event-handler.metrics.metrics-reporter.mustache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scaffold-clean-architecture Show documentation
Show all versions of scaffold-clean-architecture Show documentation
Gradle plugin to create a clean application in Java that already works, It follows our best practices!
package {{package}}.events.metrics;
import io.micrometer.core.instrument.MeterRegistry;
{{#lombok}}
import lombok.AllArgsConstructor;
{{/lombok}}
import org.reactivecommons.api.domain.Command;
import org.reactivecommons.api.domain.DomainEvent;
import org.reactivecommons.async.api.AsyncQuery;
import org.reactivecommons.async.commons.communications.Message;
import org.reactivecommons.async.commons.ext.CustomReporter;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import java.time.Duration;
@Service
{{#lombok}}
@AllArgsConstructor
{{/lombok}}
public class MetricsReporter implements CustomReporter {
private final MeterRegistry registry;
{{^lombok}}
public MetricsReporter(MeterRegistry registry) {
this.registry = registry;
}
{{/lombok}}
@Override
public void reportMetric(String type, String handlerPath, Long duration, boolean success) {
String status = success ? "success" : "error";
registry.timer("async_operation_flow_duration",
"exception", "", "type",
type, "operation", handlerPath,
"status", status)
.record(Duration.ofMillis(duration));
}
@Override
public Mono reportError(Throwable ex, Message rawMessage, Command> message, boolean redelivered) {
return Mono.empty();
}
@Override
public Mono reportError(Throwable ex, Message rawMessage, DomainEvent> message, boolean redelivered) {
return Mono.empty();
}
@Override
public Mono reportError(Throwable ex, Message rawMessage, AsyncQuery> message, boolean redelivered) {
return Mono.empty();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy