Skip to content

Commit

Permalink
More withSpan methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldraper committed Mar 6, 2017
1 parent 4e625de commit 6216fe9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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.4",
"com.lucidchart" % "thread-context" % "0.5",
"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
Expand Up @@ -5,6 +5,7 @@
import com.github.threadcontext.ThreadLocalSaver;
import io.opentracing.NoopSpan;
import io.opentracing.Span;
import java.util.concurrent.Callable;
import java.util.function.Supplier;

public final class ThreadContextSpan {
Expand Down Expand Up @@ -35,4 +36,18 @@ public static void withSpan(Span span, Runnable runnable) {
});
}

public static <T> T withSpan(Span span, Callable<T> callable) throws Exception {
return saver.runAndRestore(() -> {
ThreadContextSpan.span.set(span);
return callable.call();
});
}

public static <T> T withSpan(Span span, Supplier<T> supplier) throws Exception {
return saver.runAndRestore(() -> {
ThreadContextSpan.span.set(span);
return supplier.get();
});
}

}

0 comments on commit 6216fe9

Please sign in to comment.