0

I have an issue where I can not log any request/response on q/health/ready or q/health/live endpoints. I implemented already LoggingFilter to intercept all the request and responses, but doesn't work for MicroProfile health endpoints.

@Provider
public class LoggingFilter implements ContainerResponseFilter, ContainerRequestFilter, WriterInterceptor {
... implementation of other methods...
    @Override
    public void aroundWriteTo(WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException {
        writerInterceptorContext.proceed();
        String endpoint = (String) writerInterceptorContext.getProperty(LoggingFilter.ENDPOINT);

        if (null != writerInterceptorContext.getEntity()) {
            String responseBody = writerInterceptorContext.getEntity().toString();
            LOG.info("response", Map.of(
                    "headers", writerInterceptorContext.getHeaders(),
                    "body", responseBody,
                    "endpoint", endpoint,
                    "requestId", writerInterceptorContext.getProperty(REQUEST_ID)));
        } else {
            LOG.info("response", Map.of(
                    "headers", writerInterceptorContext.getHeaders(),
                    "endpoint", endpoint,
                    "requestId", writerInterceptorContext.getProperty(REQUEST_ID)));
        }
    }

1 Answers1

3

Quarkus exposes health endpoints as Vert.x routes - https://github.com/quarkusio/quarkus/blob/main/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java#L198. This is why JAX-RS filters/interceptors won't work for your use case.

However, I believe that what you're trying to do should be achievable with an access log - https://quarkus.io/guides/http-reference#configuring-http-access-logs. Please let me know if you'll be able to do it. If not, we can add optional handler registrations to the health routes.

xstefank
  • 434
  • 1
  • 3
  • 8
  • This is perfect for logging! Thanks. Do you have any advice how we can track all of the requests on /live and /ready endpoints with customer request header identifiers, which will be chained (e.g. RequestId=service1.service2.serviceX). Is this possible? , because we want to get the liveness requests chain in our logs for all services. Do you have any recommendations to achieve that with the framework or custom implementation on our end? @xstefank – GrofMonteCristo Oct 24 '22 at 07:25
  • This should be represented as normal request header so either `quarkus.http.access-log.pattern=%h %l %u %t "%r" %s %b "%{ALL_REQUEST_HEADERS}"` to log all headers or `quarkus.http.access-log.pattern=%h %l %u %t "%r" %s %b "%{i,RequestId}"` to just log the RequetId header. – xstefank Oct 26 '22 at 07:07