SuccessCallbackWithTracing implements SuccessCallback<T> { @Override @SuppressWarnings("deprecation") public void onSuccess(T result) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origSuccessCallback.onSuccess(result); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } SuccessCallbackWithTracing(SuccessCallback<T> origSuccessCallback);  SuccessCallbackWithTracing(SuccessCallback<T> origSuccessCallback,
                                      Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  SuccessCallbackWithTracing(SuccessCallback<T> origSuccessCallback,
                                      Deque<Span> spanStackForExecution,
                                      Map<String, String> mdcContextMapForExecution); static SuccessCallbackWithTracing<T> withTracing(SuccessCallback<T> origSuccessCallback); static SuccessCallbackWithTracing<T> withTracing(SuccessCallback<T> origSuccessCallback,
                                                         Pair<Deque<Span>, Map<String, String>> originalThreadInfo); static SuccessCallbackWithTracing<T> withTracing(SuccessCallback<T> origSuccessCallback,
                                                         Deque<Span> spanStackForExecution,
                                                         Map<String, String> mdcContextMapForExecution); @Override @SuppressWarnings("deprecation") void onSuccess(T result);  }
@DataProvider(value = { "true", "false" }) @Test public void onSuccess_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(); SuccessCallbackWithTracing instance = new SuccessCallbackWithTracing( successCallbackMock, spanStack, mdcInfo ); resetTracing(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); Throwable ex = catchThrowable(() -> instance.onSuccess(inObj)); verify(successCallbackMock).onSuccess(inObj); if (throwException) { assertThat(ex).isNotNull(); } else { assertThat(ex).isNull(); } assertThat(currentSpanStackWhenSuccessCallbackWasCalled.get(0)).isEqualTo(spanStack); assertThat(currentMdcInfoWhenSuccessCallbackWasCalled.get(0)).isEqualTo(mdcInfo); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); }