RunnableWithTracing implements Runnable { @Override @SuppressWarnings("deprecation") public void run() { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origRunnable.run(); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } RunnableWithTracing(Runnable origRunnable);  RunnableWithTracing(Runnable origRunnable,
                               Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  RunnableWithTracing(Runnable origRunnable,
                               Deque<Span> spanStackForExecution,
                               Map<String, String> mdcContextMapForExecution); static RunnableWithTracing withTracing(Runnable origRunnable); static RunnableWithTracing withTracing(Runnable origRunnable,
                                                   Pair<Deque<Span>, Map<String, String>> originalThreadInfo); static RunnableWithTracing withTracing(Runnable origRunnable,
                                                   Deque<Span> spanStackForExecution,
                                                   Map<String, String> mdcContextMapForExecution); @Override @SuppressWarnings("deprecation") void run();  }
@DataProvider(value = { "true", "false" }) @Test public void run_handles_tracing_and_mdc_info_as_expected(boolean throwException) { throwExceptionDuringCall = throwException; Tracer.getInstance().startRequestWithRootSpan("foo"); Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy(); Map<String, String> mdcInfo = MDC.getCopyOfContextMap(); final RunnableWithTracing instance = new RunnableWithTracing( runnableMock, spanStack, mdcInfo ); resetTracing(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); Throwable ex = catchThrowable(new ThrowingCallable() { @Override public void call() throws Throwable { instance.run(); } }); verify(runnableMock).run(); if (throwException) assertThat(ex).isNotNull(); else assertThat(ex).isNull(); assertThat(currentSpanStackWhenRunnableWasCalled.get(0)).isEqualTo(spanStack); assertThat(currentMdcInfoWhenRunnableWasCalled.get(0)).isEqualTo(mdcInfo); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); }