Skip to content

Commit

Permalink
thread-context 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldraper committed Mar 8, 2017
1 parent 6216fe9 commit aef99b8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 54 deletions.
2 changes: 1 addition & 1 deletion thread-context/build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
libraryDependencies ++= Seq(
"com.lucidchart" % "thread-context" % "0.5",
"com.lucidchart" % "thread-context" % "0.7",
"io.opentracing" % "opentracing-api" % "0.20.7",
"io.opentracing" % "opentracing-noop" % "0.20.7"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.opentracing.threadcontext;

import com.github.threadcontext.Context;
import com.github.threadcontext.MutableContextSupplier;
import com.github.threadcontext.ThreadLocalContextSupplier;
import com.github.threadcontext.control.TryFinallyContext;
import io.opentracing.NoopSpan;
import io.opentracing.Span;

public class ContextSpan {

public static final ContextSpan DEFAULT = new ContextSpan(Context.DEFAULT);

private final ThreadLocal<Span> span;

public ContextSpan(MutableContextSupplier contextSupplier) {
span = new ThreadLocal<Span>() {
protected Span initialValue() {
return NoopSpan.INSTANCE;
}
};
contextSupplier.suppliers.add(new ThreadLocalContextSupplier<>(span));
}

public Span get() {
return span.get();
}

public Context set(Span span) {
return new TryFinallyContext(() -> {
Span oldValue = this.span.get();
this.span.set(span);
return () -> this.span.set(oldValue);
});
}

}

This file was deleted.

0 comments on commit aef99b8

Please sign in to comment.