|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: 'Quarkus Micrometer using Prometheus client v1' |
| 4 | +date: 2025-06-12 |
| 5 | +tags: micrometer prometheus |
| 6 | +synopsis: Micrometer has moved to use the Prometheus client v1. This post explains the migration paths and required changes for applications. |
| 7 | +author: brunobat |
| 8 | +--- |
| 9 | + |
| 10 | +== Quarkus Micrometer using Prometheus client v1 |
| 11 | + |
| 12 | +Micrometer has moved to using the Prometheus Client v1.x. |
| 13 | + |
| 14 | +This change has happened on Micrometer v1.13 but since then, in quarkus we have been using the legacy `io.prometheus:simpleclient` |
| 15 | +to not interfere with the release of the previous LTS and to provide a clear migration path to all Quarkus applications. |
| 16 | + |
| 17 | +The time to upgrade comes with the upcoming Quarkus 3.25.0, and you might not need to take action, but if your application is affected there will be two choices: |
| 18 | + |
| 19 | +1. Upgrade Quarkus, deal with the breaking changes and use the new client version. This is the recommended path. |
| 20 | +2. Continue using the legacy and deprecated Prometheus client v0.x by using a newly created extension on Quarkiverse. |
| 21 | + |
| 22 | +=== Upgrade Quarkus and use Prometheus Client v1.x |
| 23 | + |
| 24 | +The `quarkus-micrometer-registry-prometheus` extension is now using the Prometheus Client v1.x including breaking changes expressed in detail on the https://github.com/micrometer-metrics/micrometer/wiki/1.13-Migration-Guide[Micrometer 1.13 Migration Guide], featuring package, API and semantic convention changes. |
| 25 | + |
| 26 | +These are the main points to consider in the new Quarkus 3.25.0: |
| 27 | + |
| 28 | +* Counters now use Longs instead of Doubles. |
| 29 | +** Before: `"registry=\"prometheus\",status=\"200\",uri=\"/example/prime/{number}\"} 2.0` |
| 30 | +** Now: `"registry=\"prometheus\",status=\"200\",uri=\"/example/prime/{number}\"} 2` |
| 31 | +* `io.micrometer.prometheusmetrics.PrometheusMeterRegistry` must be used instead of the old `io.micrometer.prometheus.PrometheusMeterRegistry`. |
| 32 | +* `io.prometheus.metrics.tracer.common.SpanContext` must be used instead of the old `io.prometheus.client.exemplars.ExemplarSampler` |
| 33 | +* The new Prometheus client uses some reserved words that must not be used to name metrics, therefore some metrics were renamed. Some examples of reserved words and renamed metrics: |
| 34 | +** `info`. Before: `jvm_info_total`. Now: `jvm_total` |
| 35 | +** `duration`. Before: `http_server_requests_duration_seconds`. Now: `http_server_requests_seconds` |
| 36 | +* Some metrics would display Tags ending in a comma (`,`). This tailing comma has now been removed. Example: `"hibernate_flushes_total{entityManagerFactory=\"<default>\",env=\"test\",env2=\"test\",registry=\"prometheus\",} 1.0"` |
| 37 | +* It is no longer possible to create a metric generating Service Level Objectives and Percentiles at the same time. |
| 38 | + |
| 39 | +Other changes: |
| 40 | + |
| 41 | +* Metrics must be registered always with the same tags. Micrometer will now send a warning if we register the same metric more than once with different Tag names. |
| 42 | + |
| 43 | +Quarkus automatic instrumentation is now producing metrics according to these changes. If your application generates their custom metrics, please update metrics creation, tests and dashboard queries according to the above guidelines. |
| 44 | + |
| 45 | +=== Continue using the legacy and deprecated Prometheus client v0.x |
| 46 | + |
| 47 | +This is a short term solution because the old v0.x client is deprecated and will be removed at some point. |
| 48 | + |
| 49 | +In this case, the core extension must be *removed*: |
| 50 | + |
| 51 | +```xml |
| 52 | +<dependency> |
| 53 | + <groupId>io.quarkus</groupId> |
| 54 | + <artifactId>quarkus-micrometer-registry-prometheu</artifactId> |
| 55 | +</dependency> |
| 56 | +``` |
| 57 | + |
| 58 | +And the legacy Quarkiverse extension must be *added*: |
| 59 | + |
| 60 | +```xml |
| 61 | +<dependency> |
| 62 | + <groupId>${project.groupId}</groupId> |
| 63 | + <artifactId>quarkus-micrometer-registry-prometheus-simpleclient</artifactId> |
| 64 | +</dependency> |
| 65 | +``` |
| 66 | + |
| 67 | +from this repository: https://github.com/quarkiverse/quarkus-micrometer-registry/tree/main/micrometer-registry-prometheus-simpleclient[micrometer-registry-prometheus-simpleclient] after version 3.4.0. |
| 68 | + |
| 69 | +=== Conclusion |
| 70 | + |
| 71 | +The Micrometer extension is the recommended way to generate metrics in Quarkus and this a rare moment were breaking changes were introduced. Now is the moment to evaluate if you application requires Micrometer related changes, in face of Quarkus 3.25.0. |
| 72 | + |
| 73 | +For more details on Observability in Quarkus please visit https://quarkus.io/guides/observability[this guide]. |
0 commit comments