https://github.com/dhatim/dropwizard-correlation-id
https://github.com/dhatim/dropwizard-correlation-id
correlation dropwizard id java module request
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/dhatim/dropwizard-correlation-id
- Owner: dhatim
- License: mit
- Created: 2018-01-31T18:01:48.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2025-12-15T14:53:04.000Z (4 months ago)
- Last Synced: 2025-12-18T19:28:36.855Z (4 months ago)
- Topics: correlation, dropwizard, id, java, module, request
- Language: Java
- Size: 105 KB
- Stars: 6
- Watchers: 10
- Forks: 3
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dropwizard Correlation Id
[](https://github.com/dhatim/dropwizard-correlation-id/actions)
[](https://maven-badges.herokuapp.com/maven-central/org.dhatim/dropwizard-correlation-id)
[](https://www.javadoc.io/doc/org.dhatim/dropwizard-correlation-id)
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)](https://www.slf4j.org/manual.html#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](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.dhatim%22%20AND%20a%3A%22dropwizard-correlation-id%22). To add it to your project simply add the following dependency to your POM:
```xml
org.dhatim
dropwizard-correlation-id
4.0.0
```
### Optional: edit your configuration YAML
The default values are as follows:
```yaml
correlationId:
headerName: X-Correlation-Id
mdcKey: correlationId
```
### Add the bundle to your Dropwizard application
Without configuration:
```java
public void initialize(Bootstrap bootstrap) {
bootstrap.addBundle(CorrelationIdBundle.getDefault());
}
```
With configuration:
```java
public void initialize(Bootstrap bootstrap) {
bootstrap.addBundle(CorrelationIdBundle.withConfigurationSupplier(MyAppConfiguration::getCorrelationId));
}
```
### Usage with a Jersey client
Just register the provided filter into your Jersey client:
```java
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:
```java
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](https://github.com/dhatim/dropwizard-correlation-id/issues).