TracingState extends Pair<Deque<Span>, Map<String, String>> { public static TracingState getCurrentThreadTracingState() { return Tracer.getInstance().getCurrentTracingStateCopy(); } TracingState(Deque<Span> spanStack, Map<String, String> mdcInfo); static TracingState getCurrentThreadTracingState(); @Override Deque<Span> getLeft(); @Override Map<String, String> getRight(); @Override Map<String, String> setValue(Map<String, String> value); @Nullable Span getActiveSpan(); final Deque<Span> spanStack; final Map<String, String> mdcInfo; }
@Test public void getCurrentThreadTracingState_works_as_expected() { Tracer tracer = Tracer.getInstance(); tracer.startRequestWithRootSpan("request-" + UUID.randomUUID().toString()); Deque<Span> currentSpanStack = tracer.getCurrentSpanStackCopy(); Map<String, String> currentMdcInfo = MDC.getCopyOfContextMap(); assertThat(currentSpanStack.size()).isGreaterThanOrEqualTo(1); assertThat(currentMdcInfo).isNotEmpty(); TracingState currentTracingState = TracingState.getCurrentThreadTracingState(); assertThat(currentTracingState.spanStack).isEqualTo(currentSpanStack); assertThat(currentTracingState.mdcInfo).isEqualTo(currentMdcInfo); }