client_java icon indicating copy to clipboard operation
client_java copied to clipboard

Issue when using @Timed annotation with prometheus-metrics-instrumentation-dropwizard

Open kpur-sbab opened this issue 8 months ago • 2 comments

@Timed annotation, which can be annotated on the methods generates dropwizard metrics with .total as a suffix.

This is not compatible with prometheus-metrics-instrumentation-dropwizard to export dropwizard metrics.

Since the io.prometheus.metrics.instrumentation.dropwizard.DropwizardExports class has a method fromSnapshotAndCount which sanitizes the metric name withPrometheusNaming.sanitizeMetricName(dropwizardName).

As a result it causes duplicate metric name exception when prometheus endpoint is invoked.

Original reference here: https://github.com/dropwizard/dropwizard/issues/10030 #

kpur-sbab avatar Apr 08 '25 08:04 kpur-sbab

This will be fixed in https://github.com/prometheus/OpenMetrics/issues/286 - which basically says that metric names are not changed or checked in client sdks

zeitlinger avatar Apr 08 '25 10:04 zeitlinger

Great thanks. We are doing this as a temporary fix for DW 4.x

prometheusRegistry.register(new DropwizardExports(environment.metrics(),
                (name, metric) -> !(metric instanceof Timer) || !name.matches(".*[._]total.*")));
        environment.admin()
                .addServlet("prometheusMetrics", new PrometheusMetricsServlet(prometheusRegistry))
                .addMapping("/prometheusMetrics");

kpur-sbab avatar Apr 10 '25 12:04 kpur-sbab