forked from opentracing/opentracing-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to follow suit with core changes
- Loading branch information
Showing
6 changed files
with
105 additions
and
84 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
opentracing-mdc-demo/src/main/java/io/opentracing/mdcdemo/MDCActiveSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package io.opentracing.mdcdemo; | ||
|
||
import io.opentracing.ActiveSpanSource; | ||
import io.opentracing.Span; | ||
import io.opentracing.impl.AbstractActiveSpan; | ||
import org.slf4j.MDC; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* MDCActiveSpan illustrates the core ActiveSpan concepts and capabilities to a first approximation. Not | ||
* production-quality code. | ||
*/ | ||
class MDCActiveSpan extends AbstractActiveSpan { | ||
private MDCActiveSpanSource mdcActiveSpanSource; | ||
private MDCActiveSpan toRestore = null; | ||
|
||
MDCActiveSpan(MDCActiveSpanSource mdcActiveSpanSource, Span span, Map<String, String> mdcContext, AtomicInteger refCount) { | ||
super(span, refCount); | ||
this.mdcActiveSpanSource = mdcActiveSpanSource; | ||
this.toRestore = mdcActiveSpanSource.tlsSnapshot.get(); | ||
mdcActiveSpanSource.tlsSnapshot.set(this); | ||
MDC.setContextMap(mdcContext); | ||
} | ||
|
||
@Override | ||
protected void doDeactivate() { | ||
if (mdcActiveSpanSource.tlsSnapshot.get() != this) { | ||
// This shouldn't happen if users call methods in the expected order. Bail out. | ||
return; | ||
} | ||
mdcActiveSpanSource.tlsSnapshot.set(toRestore); | ||
} | ||
|
||
@Override | ||
protected ActiveSpanSource spanSource() { | ||
return mdcActiveSpanSource; | ||
} | ||
|
||
static class MDCContinuation extends AbstractActiveSpan.AbstractContinuation { | ||
private MDCActiveSpanSource mdcActiveSpanSource; | ||
private final Map<String, String> mdcContext; | ||
private final Span span; | ||
|
||
MDCContinuation(MDCActiveSpanSource source, Span span, AtomicInteger refCount) { | ||
super(refCount); | ||
this.mdcActiveSpanSource = source; | ||
this.mdcContext = MDC.getCopyOfContextMap(); | ||
this.span = span; | ||
} | ||
|
||
@Override | ||
public MDCActiveSpan activate() { | ||
return new MDCActiveSpan(mdcActiveSpanSource, span, mdcContext, refCount); | ||
} | ||
} | ||
|
||
} |
63 changes: 9 additions & 54 deletions
63
opentracing-mdc-demo/src/main/java/io/opentracing/mdcdemo/MDCActiveSpanSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
opentracing-mdc-demo/src/main/java/io/opentracing/mdcdemo/TracedCallable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters