Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

Dropwizard Correlation Id

Build Status Coverage Status Maven Central Javadocs

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.

Usage

Maven Artifacts

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>0.1.0</version>
</dependency>

Optional: edit your configuration YAML

The default values are as follows:

correlationId:
    headerName: X-Correlation-Id
    mdcKey: correlationId

Add the bundle to your Dropwizard application

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));
}

Usage with a Jersey client

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.

Usage with an Apache http client

Replace your HttpClientBuilder by CorrelationIdHttpClientBuilder this way:

HttpClientBuilder builder = new CorrelationIdHttpClientBuilder(..., configuration)...;
CloseableHttpClient cient = builder.build(...);

If configuration is omitted, default values apply.

Support

Please file bug reports and feature requests in GitHub issues.