# Add Request ID Logging to a Quarkus API

Yes. An agent gives every request in a Quarkus REST app an id from X-Request-ID or a new UUID, puts it in the log format and the response, tests it and opens a PR.

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

## What the agent does

The agent reads how requests are logged today before adding anything. In a service shaped like the `rest-json-quickstart` in quarkusio/quarkus-quickstarts, `pom.xml` imports the Quarkus platform at `3.40.1.1`, depends on `quarkus-rest-jackson`, and tests with `quarkus-junit` and `rest-assured` under `maven-surefire-plugin` 3.5.4 through the repository's `mvnw`. `FruitResource.java` serves `GET`, `POST` and `DELETE` on `/fruits` from an in-memory `Set<Fruit>`, `LegumeResource.java` does the same for legumes, and `src/main/resources` holds only `META-INF/resources/fruits.html` and `legumes.html`: there is no `application.properties`. `LoggingFilter.java` is a JAX-RS `@Provider` implementing `ContainerRequestFilter` that injects `UriInfo` and the Vert.x `HttpServerRequest` and logs `Request GET /fruits from IP …` with a JBoss `Logger`. Nothing ties that line to the lines a resource logs afterwards, and nothing in the response lets a client quote the request back to you.

The agent extends `LoggingFilter` rather than adding a second request filter. It reads `X-Request-ID` from the incoming headers, generates a `UUID` when the header is absent or longer than a sane maximum, stores the value as a request property on the `ContainerRequestContext`, and puts it in the logging MDC under `requestId` with `org.jboss.logging.MDC`. Quarkus keeps MDC values on the request's Vert.x context, so a resource method that runs on a worker thread still logs the same id. A new `RequestIdResponseFilter` implementing `ContainerResponseFilter` copies the property to an `X-Request-ID` response header and removes the MDC entry when the response leaves.

Then it creates `src/main/resources/application.properties` with one setting, `quarkus.log.console.format`, equal to the default console format with `requestId=%X{requestId}` inserted after the level, so every line a request produces carries the id and lines from startup show it empty. The existing `LOG.infof` call in the filter keeps its text, and the agent does not add an access log, since `quarkus.http.access-log` would duplicate what the filter already writes.

Tests follow `FruitResourceTest.java`: a `@QuarkusTest` class using RestAssured's `given().when().get("/fruits")`. The new `RequestIdTest` sends a request with `X-Request-ID: abc-123` and asserts the same value comes back in the response header, sends one without the header and asserts the response header matches a UUID pattern, and sends a `POST /fruits` to check the header is set on a `200` with a JSON body. Before pushing it runs `./mvnw -B test` inside `rest-json-quickstart`, then `./mvnw quarkus:dev` and a `curl -i` against `/fruits` to paste the header and the matching log line into the pull request.

## Start it with one API call

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

```json
{
  "agent": "codex",
  "input": "Add request id logging to the Quarkus REST service in rest-json-quickstart and open a pull request. Read pom.xml, src/main/java/org/acme/rest/json/LoggingFilter.java, FruitResource.java, LegumeResource.java, src/test/java/org/acme/rest/json/FruitResourceTest.java and the contents of src/main/resources first. In LoggingFilter read X-Request-ID, generate a UUID when it is missing or unreasonably long, store it as a request property and put it in the MDC under requestId with org.jboss.logging.MDC; keep the existing log line. Add a ContainerResponseFilter that writes the id to an X-Request-ID response header and clears the MDC entry. Create src/main/resources/application.properties with quarkus.log.console.format equal to the default format plus requestId=%X{requestId} after the level. Add RequestIdTest as a @QuarkusTest with RestAssured covering a supplied id echoed back, a generated id matching a UUID pattern, and the header on a POST /fruits response. Run ./mvnw -B test in rest-json-quickstart, then start quarkus:dev and include a curl -i response and the matching log line in the pull request. Do not change the resources or the HTML files.",
  "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

What comes back is a pull request that changes `LoggingFilter.java`, adds `RequestIdResponseFilter.java`, `RequestIdTest.java` and a one-line `application.properties`. The description shows the `mvnw test` summary with the three new tests, a `curl -i http://localhost:8080/fruits` response with its `X-Request-ID` header, and the console line from the same request with `requestId=` set to the same value.

On a repository with the quickstarts' `build-pr-development.yml` workflow, the pull request builds the changed quickstart with the development platform version. The change adds no dependency, so the native profile in `Dockerfile.native` is unaffected.

A reviewer checks that a client-supplied id is bounded and never echoed into a log line unescaped, that the MDC entry is cleared so an id cannot leak into the next request on a reused thread, and that the format change keeps the fields their log pipeline parses. Then they decide whether to add the same filter to the other quickstarts in the repository, which the pull request does not touch.

## Run it on every new Quarkus service

Send one `POST /o/{org}/sessions` per Quarkus repository with this prompt and that repository in `resources`. Each run reads its own `pom.xml` and `application.properties`, so a service that already uses `quarkus-opentelemetry` gets its trace id put in the log format instead of a second id, and a service with an existing `application.properties` has its format line edited rather than replaced.

Give the API key a `webhook_url` and Rush POSTs `run.completed` when each turn finishes, with the `session_url` to read the pull request link from, so a handler on your server can post it where that service's owners review.

## Why run it on Rush?

The point of a request id is that the header and the log line agree, and the only way to know is to run the service and read both. In a Rush sandbox the agent starts `quarkus:dev`, sends a request with `curl -i`, and keeps the response and the console output in the run's record, so the pull request shows the two values side by side rather than asserting they match.

A Quarkus test suite boots the application for every `@QuarkusTest` class, which is slow enough that people skip it locally. The agent runs the full `./mvnw test` in its own sandbox before pushing, and the same request body works for every Quarkus service a team owns, each run with its own build.

## Frequently asked questions

### Why not use quarkus-opentelemetry for this?

If the service already exports traces, the trace id is the right correlation key and the agent puts `%X{traceId}` in the format instead. This quickstart has no tracing dependency, and a single filter adds an id without pulling in an exporter.

### Does the MDC survive the switch to a worker thread?

Yes. Quarkus stores MDC values on the request's Vert.x context rather than on the thread, so a blocking resource method running on a worker thread logs the id the filter set on the event loop. The test asserts the header; the pasted console line shows the log side.

### Will the new log format break my log parser?

The pull request inserts one `requestId=` field into the default format and changes nothing else. If your pipeline expects JSON, say so in `input` and the agent adds `quarkus-logging-json` instead, where the MDC field appears as a key.

### Can a client set any value as the id?

The filter accepts the header but caps its length and falls back to a UUID when it is over the cap, so a malicious header cannot flood the log. The id is logged through the formatter's `%X`, not concatenated into the message.

## More Quarkus jobs

- [Add Security Headers to a Quarkus REST API](https://getrush.ai/run/add-security-headers/quarkus/)
- [Add Soft Delete to a Quarkus Panache Entity](https://getrush.ai/run/add-soft-delete/quarkus/)
- [Add Structured Logging to a Quarkus App](https://getrush.ai/run/add-structured-logging/quarkus/)

## The same job on other stacks

- [Add Request ID Logging to a React Router App](https://getrush.ai/run/add-request-id-logging/react-router/)
- [Add Request ID Logging to a Rocket App](https://getrush.ai/run/add-request-id-logging/rocket/)
- [Add Request ID Logging to a Serverless Express API](https://getrush.ai/run/add-request-id-logging/serverless/)

## 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/)
