Correlation ids for Dropwizard applications. They are useful to match requests between different components.
- Correlation ids are sent from one system to another using an http header in requests and responses. The default http header is
X-Correlation-Id
. - When the server processes a request, its correlation id (or a random UUID if not available) is put into slf4j mapped diagnostic context (MDC). The default MDC key is
correlationId
. - When using a Jersey or Apache http client to send requests to another system, the correlation id currently in the MDC (or a random UUID if not available) is put into the request http header.
This project is available in the Central Repository. To add it to your project simply add the following dependency to your POM:
<dependency>
<groupId>org.dhatim</groupId>
<artifactId>dropwizard-correlation-id</artifactId>
<version>4.0.0</version>
</dependency>
The default values are as follows:
correlationId:
headerName: X-Correlation-Id
mdcKey: correlationId
Without configuration:
public void initialize(Bootstrap<MyApplicationConfiguration> bootstrap) {
bootstrap.addBundle(CorrelationIdBundle.getDefault());
}
With configuration:
public void initialize(Bootstrap<MyApplicationConfiguration> bootstrap) {
bootstrap.addBundle(CorrelationIdBundle.withConfigurationSupplier(MyAppConfiguration::getCorrelationId));
}
Just register the provided filter into your Jersey client:
JerseyClientBuilder builder = new JerseyClientBuilder(...)...;
Client client = builder.build(...);
client.register(new CorrelationIdClientFilter(configuration));
If configuration
is omitted, default values apply.
Replace your HttpClientBuilder
by CorrelationIdHttpClientBuilder
this way:
HttpClientBuilder builder = new CorrelationIdHttpClientBuilder(..., configuration)...;
CloseableHttpClient cient = builder.build(...);
If configuration
is omitted, default values apply.
Please file bug reports and feature requests in GitHub issues.