Skip to content

Add counter name to exception message when negative value is detected #1090

Open
@AntuanRokanten

Description

@AntuanRokanten

Description:

I am using micrometer-registry-prometheus version 1.13.0 with Spring Boot 3.3.0, and sometimes I encounter the following exception when Prometheus scrapes metrics:

java.lang.IllegalArgumentException: -2.0: counters cannot have a negative value
at io.prometheus.metrics.model.snapshots.CounterSnapshot$CounterDataPointSnapshot.validate(CounterSnapshot.java:74)
at io.prometheus.metrics.model.snapshots.CounterSnapshot$CounterDataPointSnapshot.(CounterSnapshot.java:58)
at io.prometheus.metrics.model.snapshots.CounterSnapshot$CounterDataPointSnapshot.(CounterSnapshot.java:46)
at io.micrometer.prometheusmetrics.PrometheusMeterRegistry.lambda$newFunctionCounter$20(PrometheusMeterRegistry.java:372)
at io.micrometer.prometheusmetrics.MicrometerCollector.collect(MicrometerCollector.java:77)
at io.prometheus.metrics.model.registry.PrometheusRegistry.scrape(PrometheusRegistry.java:72)
at io.prometheus.metrics.model.registry.PrometheusRegistry.scrape(PrometheusRegistry.java:57)
at org.springframework.boot.actuate.metrics.export.prometheus.PrometheusScrapeEndpoint.scrape(PrometheusScrapeEndpoint.java:59)

The error message indicates that a counter has a negative value, but it does not specify which counter is causing the problem. This makes it difficult to identify the source of the issue in large applications with multiple counters.

Suggestion:

It would be helpful if the exception message included the name of the counter that is causing the problem. This additional information would significantly improve the ability to troubleshoot issues, especially in complex applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions