Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds MDCCurrentTraceContext for log correlation #389

Merged
merged 1 commit into from
May 3, 2017

Conversation

codefromthecrypt
Copy link
Member

This adds trace and span IDs to the SLF4J Mapped Diagnostic Context (MDC)
so that you can search or aggregate logs accordingly.

To enable this, configure brave.Tracing with MDCCurrentTraceContext
like so:

tracing = Tracing.newBuilder()
    .currentTraceContext(MDCCurrentTraceContext.create())
    ...
    .build();

Then, in your log configuration, you can use traceId and or spanId.

Here's an example logback configuration:

<pattern>%d [%X{traceId}/%X{spanId}] [%thread] %-5level %logger{36} - %msg%n</pattern>

When a trace is in progress, it would log statements like this:

2017-05-02 23:36:04,789 [fcd015bf6f8b05ba/fcd015bf6f8b05ba] [main] INFO  c.a.FooController - I got here!

Users could then copy/paste the trace ID into the zipkin UI, or use log
correlation to further debug a problem.

Fixes #150
See #369

@codefromthecrypt
Copy link
Member Author

cc @llinder @devinsba

@codefromthecrypt
Copy link
Member Author

@ryangardner I know you asked for this a year ago, but everything's coming together now

@codefromthecrypt
Copy link
Member Author

@jplock @hyleung @takezoe fyi on this, too.. Not sure if SLF4J is a constant for y'all or not

This adds trace and span IDs to the SLF4J Mapped Diagnostic Context (MDC)
so that you can search or aggregate logs accordingly.

To enable this, configure `brave.Tracing` with `MDCCurrentTraceContext`
like so:

```java
tracing = Tracing.newBuilder()
    .currentTraceContext(MDCCurrentTraceContext.create())
    ...
    .build();
```

Then, in your log configuration, you can use `traceId` and or `spanId`.
@llinder
Copy link
Member

llinder commented May 2, 2017

nice!

@devinsba
Copy link
Member

devinsba commented May 2, 2017

Looks good to me. Whats up with the circle-ci failure?

@codefromthecrypt
Copy link
Member Author

codefromthecrypt commented May 3, 2017 via email

@codefromthecrypt codefromthecrypt merged commit 5a93fc0 into master May 3, 2017
@codefromthecrypt codefromthecrypt deleted the context-slf4j branch May 3, 2017 01:08
@codefromthecrypt
Copy link
Member Author

next release won't be until this weekend, so feel free to provide feedback after the fact. merged so people can play with snapshots

@codefromthecrypt
Copy link
Member Author

bumped version to 4.3.0-SNAPSHOT

@kuroneko25
Copy link

Can this be extended to Log4j2 thread context?

@codefromthecrypt
Copy link
Member Author

codefromthecrypt commented May 4, 2017 via email

@kuroneko25
Copy link

Awesome!

codefromthecrypt pushed a commit that referenced this pull request May 6, 2017
This adds trace and span IDs to the Log4J 2 Thread Context so that you
can search or aggregate logs accordingly.

To enable this, configure `brave.Tracing` with `ThreadContextCurrentTraceContext`
like so:

```java
tracing = Tracing.newBuilder()
    .currentTraceContext(ThreadContextCurrentTraceContext.create())
    ...
    .build();
```

See #389
@codefromthecrypt
Copy link
Member Author

codefromthecrypt commented May 6, 2017 via email

codefromthecrypt pushed a commit that referenced this pull request May 7, 2017
This adds trace and span IDs to the Log4J 2 Thread Context so that you
can search or aggregate logs accordingly.

To enable this, configure `brave.Tracing` with `ThreadContextCurrentTraceContext`
like so:

```java
tracing = Tracing.newBuilder()
    .currentTraceContext(ThreadContextCurrentTraceContext.create())
    ...
    .build();
```

See #389
@ndecapite
Copy link

Currently trying to add the traceID into my logging for any HTTP request..

What is this logback configuration that is referenced(the only xml files I have are my pom.xml)? Also, because the decorator's create() methods are all deprecrated, should I be using the get() method instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: a way to get traceId into an SLF4j MDC
5 participants