No description or website provided.
Switch branches/tags
Nothing to show
Clone or download
ochedru Merge pull request #1 from ochedru/upgrade
Upgrade parent root-oss
Latest commit edaeb91 May 4, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis First commit Jan 31, 2018
src/main/java/org/dhatim/dropwizard/correlationid Default mdc key is correlationId with a lowercase C Feb 1, 2018
.gitignore First commit Jan 31, 2018
.travis.yml First commit Jan 31, 2018
LICENSE Create LICENSE Jan 31, 2018
README.md Upgrade parent root-oss May 4, 2018
pom.xml Upgrade parent root-oss May 4, 2018

README.md

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.