All jobs

Add Structured Logging to a Quarkus App

Yes. An agent adds quarkus-logging-json, puts a request id in the MDC from a filter, keeps console logs readable in dev, tests it with RestAssured, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the build and the existing logging before it changes a format. In a service shaped like the rest-json-quickstart of quarkusio/quarkus-quickstarts, pom.xml imports the io.quarkus.platform:quarkus-bom 3.40.1.1, depends on quarkus-rest-jackson with quarkus-junit and rest-assured for tests, targets Java 17, and configures Surefire to use org.jboss.logmanager.LogManager. There is no application.properties, so every logging setting is at its default. FruitResource.java serves GET, POST and DELETE /fruits over an in-memory set, and LoggingFilter.java is already a ContainerRequestFilter that logs Request %s %s from IP %s with the JBoss Logger for every call, which is the hook the agent builds on.

It adds the quarkus-logging-json extension to pom.xml, unversioned under the BOM, and a src/main/resources/application.properties that turns JSON on for the prod profile with %prod.quarkus.log.console.json=true and leaves it off for dev and test, so ./mvnw quarkus:dev still prints readable lines. It sets quarkus.log.console.json.additional-field.service.value to the artifact id and quarkus.log.console.json.exception-output-type=formatted so stack traces come through as one field. LoggingFilter.java becomes the place a request id is minted: it reads an X-Request-Id header or generates a UUID, puts it in the MDC under requestId along with method and path, and a matching ContainerResponseFilter echoes the id on the response and clears the MDC so the values do not leak into the next request on the same worker thread.

Tests follow FruitResourceTest.java: @QuarkusTest with RestAssured's given().when().get("/fruits"). The new LoggingFilterTest.java sends a request with an X-Request-Id header and asserts the same value comes back on the response, sends one without and asserts a UUID-shaped id is present, and a test profile that sets quarkus.log.console.json=true captures stdout to assert one line parses as JSON with requestId, method and path fields. FruitResourceIT.java extends the existing test for the native profile, so the agent adds the same IT subclass for the new test.

Before pushing, the agent runs ./mvnw -B clean verify with the repository's Maven wrapper on JDK 21, the version the Pull Request Build workflow uses, and also starts the packaged jar with -Dquarkus.profile=prod to paste two real JSON log lines, one for a GET /fruits and one for the POST, in the pull request. The workflow's star-import check is honoured by writing explicit imports.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "codex",
  "input": "Add structured logging to this Quarkus service and open a pull request. Read pom.xml, src/main/java/org/acme/rest/json/LoggingFilter.java, src/main/java/org/acme/rest/json/FruitResource.java, src/test/java/org/acme/rest/json/FruitResourceTest.java, src/test/java/org/acme/rest/json/FruitResourceIT.java and src/main/docker/Dockerfile.jvm first. Add the quarkus-logging-json extension unversioned under the BOM. Add src/main/resources/application.properties enabling JSON console output for the prod profile only, with a service additional field set to the artifact id and formatted exception output. Change LoggingFilter to read or generate an X-Request-Id, put requestId, method and path in the MDC, and add a response filter that echoes the id and clears the MDC. Add LoggingFilterTest with RestAssured: a sent X-Request-Id is echoed, a missing one yields a UUID, and under a test profile with JSON on, one captured log line parses as JSON with requestId, method and path. Add the matching IT subclass. Use explicit imports, no star imports. Run ./mvnw -B clean verify, start the packaged jar with the prod profile, and paste two JSON log lines and the build output in the pull request. Do not change FruitResource, LegumeResource or the Dockerfiles.",
  "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 with one new dependency in pom.xml, a new application.properties, the reworked LoggingFilter.java plus a response filter, LoggingFilterTest.java and LoggingFilterIT.java. The description shows two JSON log lines from the packaged jar, each with timestamp, level, message, requestId, method, path and service, and the Surefire summary from ./mvnw clean verify.

On a repository with a Maven workflow, the pull request runs ./mvnw clean install on JDK 21 and the star-import check, so a wildcard import or a failing filter test shows there. The existing FruitResourceTest and LegumeResourceTest run unchanged, since dev and test profiles keep the plain format.

A reviewer checks that JSON is on only for prod, that the MDC is cleared in the response filter, that a caller-supplied X-Request-Id is echoed rather than replaced, and that the exception output type produces one field their log pipeline can index. Then they map requestId to a field in their log search.

Run it on every service onboarded to the log pipeline

A platform team moving services onto a JSON log pipeline sends one POST /o/{org}/sessions per repository with this prompt and that repository in resources. Each run reads its own pom.xml and filters, so a service that already has a request filter gets the MDC lines added to it rather than a second filter, and each run opens its own pull request.

Give the API key a webhook_url and Rush POSTs run.completed when each turn ends, with the session_url to read the pull request and the sample log lines from.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Switching a service to JSON logs is a configuration change with two traps: turning it on in dev, where nobody can read it, and leaving the MDC dirty so a request id from one call shows up on the next. In a Rush sandbox the agent runs the packaged jar under the prod profile, captures real log lines, writes the test that parses one, and keeps every mvnw command and its output in the run's record, so the pull request shows the format the pipeline will receive.

The quickstart's own tests pass before and after because the test profile keeps the plain format, and the agent proves that by running clean verify rather than asserting it. The same request works unchanged on every Quarkus service a team owns.

Frequently asked questions

Will dev mode logs become JSON?

No. The property is %prod.quarkus.log.console.json=true, so ./mvnw quarkus:dev and the test profile keep the default readable format. Setting quarkus.log.console.json=true without the profile prefix would change all three, which the pull request avoids.

Does it add a dependency?

One: io.quarkus:quarkus-logging-json, a first-party extension pinned by the quarkus-bom already imported in pom.xml, so no version string is added.

What if the caller sends its own request id?

The filter reads X-Request-Id first and only generates a UUID when the header is absent, so an id from a gateway or a calling service is kept and echoed on the response. The test covers both cases.

Why clear the MDC in a response filter?

Quarkus serves requests on a pool of worker threads, and the MDC is thread-local, so a value left behind after one response would appear on the next request that thread handles. The response filter removes requestId, method and path after echoing the id.

More Quarkus jobs

The same job on other stacks

Keep reading