# Add Prometheus Metrics to a Quarkus App

Yes. An agent adds Micrometer's Prometheus registry to your Quarkus app with HTTP, datasource and Hibernate metrics, a counter and a test, and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/add-prometheus-metrics/quarkus/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the module before adding an extension. In a Quarkus app like the `hibernate-orm-panache-quickstart` module of quarkusio/quarkus-quickstarts, `pom.xml` imports the `quarkus-bom` at platform version 3.40.1.1, targets Java 17 and depends on `quarkus-hibernate-orm-panache`, `quarkus-rest-jackson` and `quarkus-jdbc-postgresql`, with `quarkus-junit` and `rest-assured` for tests. Two resources expose the same CRUD API two ways: `FruitEntityResource` at `entity/fruits` on a `PanacheEntity`, and `FruitRepositoryResource` at `repository/fruits` through a `PanacheRepository`, each with `GET`, `POST`, `PUT` and `DELETE` and an `ErrorMapper` that turns exceptions into JSON. `application.properties` turns on SQL logging, loads `import.sql` with three fruits, and sets the production datasource; in dev and test, Dev Services start PostgreSQL, as the README says. `FruitsEndpointTest` is a `@QuarkusTest` that lists, deletes `/1` and lists again with REST Assured, and `FruitsEndpointIT` reruns it as an integration test against the packaged app. The same repository's `micrometer-quickstart` already shows the house style: `quarkus-micrometer-registry-prometheus` in the POM and an injected `MeterRegistry` for counters, timers and a gauge.

The change starts with one dependency, `quarkus-micrometer-registry-prometheus`, managed by the BOM so it needs no version. That alone makes Quarkus serve `/q/metrics` in Prometheus text format with JVM, system and HTTP server metrics, where every request is timed under `http_server_requests_seconds` with a `uri` tag of the matched template, `/entity/fruits/{id}` rather than one series per id, and a `status` tag. Two properties in `application.properties` widen that: `quarkus.datasource.metrics.enabled=true` publishes the Agroal connection pool's meters, and `quarkus.hibernate-orm.metrics.enabled=true` exports Hibernate's statistics, queries executed and entities loaded. Nothing in the resources has to change for any of that.

One business metric is added where it means something. Both `create` methods, in `FruitEntityResource` and `FruitRepositoryResource`, get an injected `MeterRegistry` in the way `ExampleResource` in the micrometer quickstart does, and increment a `fruits.created` counter tagged with `api` as `entity` or `repository`, so the two implementations can be compared on one chart. The `ErrorMapper` classes increment `fruits.errors` tagged with the status code, which gives a count of 404s and 422s that the HTTP server metric already splits by status but not by cause. The agent follows the repository's import rule, no star imports, which `.github/workflows/build-pr-development.yml` checks with `git grep` before building.

Tests follow `FruitsEndpointTest`. A new `MetricsEndpointTest` under the same package is a `@QuarkusTest` that reads `/q/metrics`, asserts a 200 with `http_server_requests_seconds` present, posts a fruit to `entity/fruits` and asserts `fruits_created_total` with the `api="entity"` tag appears, and requests a missing id to see the error counter move. The agent runs `./mvnw -pl hibernate-orm-panache-quickstart test` from the repository root using the wrapper, with Dev Services providing PostgreSQL where the sandbox has a container runtime, and otherwise points `%test.quarkus.datasource` at a PostgreSQL it starts itself and says so in the pull request. It adds a `Metrics` section to the module's `README.md` with the endpoint and the new meter names, and opens the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add Prometheus metrics to the hibernate-orm-panache-quickstart module and open a pull request. Read the root pom.xml, hibernate-orm-panache-quickstart/pom.xml, its README.md, src/main/resources/application.properties, src/main/resources/import.sql, FruitEntityResource.java, FruitRepositoryResource.java, FruitEntity.java, FruitRepository.java, FruitsEndpointTest.java and FruitsEndpointIT.java, and for the house style micrometer-quickstart/pom.xml and its ExampleResource.java, plus .github/workflows/build-pr-development.yml. Add the quarkus-micrometer-registry-prometheus dependency to the module's pom.xml with no version, managed by the BOM. Set quarkus.datasource.metrics.enabled=true and quarkus.hibernate-orm.metrics.enabled=true in application.properties. Inject a MeterRegistry into FruitEntityResource and FruitRepositoryResource the way ExampleResource does, increment a fruits.created counter tagged api=entity or api=repository in each create method, and increment a fruits.errors counter tagged with the status code in each ErrorMapper. Use no star imports. Add MetricsEndpointTest as a @QuarkusTest beside FruitsEndpointTest that reads /q/metrics, asserts http_server_requests_seconds is present, posts a fruit and asserts fruits_created_total with the entity tag, and requests a missing id to see the error counter. Run ./mvnw -pl hibernate-orm-panache-quickstart test from the repository root, using Dev Services for PostgreSQL if a container runtime is available and otherwise a PostgreSQL you start and configure under the test profile, and say which in the pull request. Add a Metrics section to the module README naming the endpoint and the new meters, and open the pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The result is a pull request on its own branch with one new dependency in the module's `pom.xml`, two properties in `application.properties`, small changes to the two resource classes, a new test class and a README section. The description quotes the first lines of `/q/metrics` from the running test application, lists the meters that appear with no Java change (HTTP server, JVM, Agroal, Hibernate) and the two the code adds, and names the Prometheus scrape path for the operator.

The transcript keeps the Maven run with the existing `FruitsEndpointTest` and the new `MetricsEndpointTest` passing together, and the Dev Services or self-started PostgreSQL log that fed them. `GET /o/{org}/p/{project}/sessions/{id}/changes` returns the diff per file.

A reviewer checks that the counter tags are low-cardinality, `api` with two values and `status` with a handful, never an id, that the `uri` tag on the HTTP metric shows templates rather than concrete paths, and that the native profile still builds if the team ships native images, since the Prometheus registry is supported there. A follow-up on the same session can add a `Timer` around the Panache queries or a Grafana dashboard JSON for the new series.

## Run it on every service with no /q/metrics

Metrics are a hand-off job: well specified, mostly reading, and worth doing on every service. From Claude Code or Codex with Rush connected as an MCP server at `https://api.phoenix.so/mcp`, ask for a `create_session` with this prompt and your repository, keep working, and read the pull request later with `get_session`; `wait_for_sessions` waits up to 50 seconds per call when you would rather block. The sandbox parks at the end of the turn with its Maven repository warm, so a `send_session_message` asking for a timer on the delete path reuses it.

From a script, send one `POST /o/{org}/sessions` per Quarkus service with the repository in `resources`. A `webhook_url` on the key receives `run.completed` with `data.session_url` for each run the key started, so a handler can gather the pull request links for the platform team.

## Why run it on Rush?

The dependency is one line and the value is in what gets verified: that `/q/metrics` actually serves under the test profile, that the HTTP metric tags are templates and not ids, that the pool and Hibernate statistics switch on, and that the business counter moves when a fruit is created. The agent runs the Quarkus test suite in its own sandbox, with PostgreSQL started for it, and reads the real scrape output before the pull request exists, which is more than a dependency bump reviewed in a diff viewer ever shows.

The evidence stays with the result: the Maven run, the first lines of the scrape and the diff are in the transcript, and the pull request links to it. A platform team that wants the same meters on every Quarkus service runs the same request against each module, one sandbox and one pull request each, with the resource classes read from each repository rather than assumed.

## Frequently asked questions

### Why Micrometer and not SmallRye Metrics?

Micrometer is the metrics library the Quarkus guides and this repository's own `micrometer-quickstart` use, and the Prometheus registry extension exports its meters in the format Prometheus scrapes without an adapter. SmallRye Metrics is the older MicroProfile API, and the quickstarts no longer centre on it.

### What do I get without changing any Java code?

The `quarkus-micrometer-registry-prometheus` dependency alone serves `/q/metrics` with HTTP server request timings tagged by URI template, method, status and outcome, and JVM memory, GC and thread meters. The two properties the agent adds publish the Agroal datasource pool meters and Hibernate ORM statistics as well. The Java changes are only for the two business counters.

### Will the metric tags explode with one series per fruit id?

No. The HTTP server binder uses the matched route template, so requests to `entity/fruits/1` and `entity/fruits/2` share one `uri="/entity/fruits/{id}"` series, and the new counters are tagged only with `api` and the status code. The prompt forbids ids in tags and the reviewer's checklist repeats it.

### Does the test need a database?

Yes, like the existing `FruitsEndpointTest`: the module's tests run against PostgreSQL that Quarkus Dev Services starts in a container during the test phase. Where the sandbox has no container runtime, the agent starts a PostgreSQL itself and points the test profile at it, and the pull request says which path was taken.

### Is the metrics endpoint exposed to the internet?

It is served by the application on the same port under `/q/metrics`, as every Quarkus non-application endpoint is. Whether a scraper or the public can reach it is a matter of the deployment's network rules, and the README section the agent adds says so.

## More Quarkus jobs

- [Add Rate Limiting to a Quarkus REST API](https://getrush.ai/run/add-rate-limiting/quarkus/)
- [Add Request ID Logging to a Quarkus API](https://getrush.ai/run/add-request-id-logging/quarkus/)
- [Add Security Headers to a Quarkus REST API](https://getrush.ai/run/add-security-headers/quarkus/)

## The same job on other stacks

- [Add Prometheus Metrics to a Rocket App](https://getrush.ai/run/add-prometheus-metrics/rocket/)
- [Add Prometheus Metrics to an Express and Sequelize API](https://getrush.ai/run/add-prometheus-metrics/sequelize/)
- [Add Prometheus Metrics to a Slim 4 App](https://getrush.ai/run/add-prometheus-metrics/slim/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
