@Override
    public void filter(final ContainerRequestContext request,
            final ContainerResponseContext response) throws IOException {

        String id = Optional.ofNullable(request.getHeaderString(REQUEST_ID))
            .filter(header -> !header.isEmpty())
            .orElseGet(() -> generateRandomUuid().toString());

        logger.trace("method={} path={} request_id={} status={} length={}",
                request.getMethod(), request.getUriInfo().getPath(), id,
                response.getStatus(), response.getLength());
        response.getHeaders().putSingle(REQUEST_ID, id);
    }
@Test
    void addsRandomRequestIdHeader() throws Exception {

        requestIdFilter.filter(request, response);

        String requestId = (String) headers.getFirst("X-Request-Id");
        assertThat(requestId).isNotNull();
        assertThat(UUID.fromString(requestId)).isNotNull();
        verify(logger).trace("method={} path={} request_id={} status={} length={}",
            "GET", "/some/path", requestId, 200, 2048);
    }