dhatim / dropwizard-correlation-id

MIT License
6 stars 3 forks source link
correlation dropwizard id java module request

Dropwizard Correlation Id

Build Status Maven Central Javadocs

Correlation ids for Dropwizard applications. They are useful to match requests between different components.

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>4.0.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.