@Benchmark public void newScope_log4j2() { try (CurrentTraceContext.Scope ws = log4j2.newScope(contextWithParent)) { } }
@Benchmark public void newScope_redundant_default() { try (CurrentTraceContext.Scope ws = base.newScope(context)) { } }
@Benchmark public void newScope_clear_default() { try (CurrentTraceContext.Scope ws = base.newScope(null)) { } }
@Test public void maybeScope_doesntDuplicateContext() { try (Scope scope = currentTraceContext.newScope(context)) { try (Scope scope2 = currentTraceContext.maybeScope(context)) { assertThat(scope2).isEqualTo(Scope.NOOP); } } }
@Override public Scope newScope(@Nullable TraceContext currentSpan) { Scope scope = delegate.newScope(currentSpan); return decorateScope(currentSpan, scope); } }
@Override public Scope newScope(@Nullable TraceContext currentSpan) { Scope scope = delegate.newScope(currentSpan); return decorateScope(currentSpan, scope); } }
@Override public CurrentTraceContext.Scope newScope(@Nullable TraceContext currentSpan) { CurrentTraceContext.Scope scope = delegate.newScope(currentSpan); return decorateScope(currentSpan, scope); } }
@Test public void newScope_canClearScope() { canClearScope(() -> currentTraceContext.newScope(null)); }
@Test public void restoresSpanAfterCallable() throws Exception { try (Scope scope0 = currentTraceContext.newScope(context)) { attachesSpanInCallable(); assertThat(currentTraceContext.get()) .isEqualTo(context); verifyImplicitContext(context); } }
@Test public void attachesSpanInCallable_canClear() throws Exception { Callable<?> callable = currentTraceContext.wrap(() -> { assertThat(currentTraceContext.get()).isNull(); verifyImplicitContext(null); return true; }); // Set another span between the time the task was made and executed. try (Scope scope2 = currentTraceContext.newScope(context2)) { callable.call(); // runs assertion verifyImplicitContext(context2); } }
@Benchmark public void tracedClient_get_resumeTrace() throws Exception { try (Scope scope = Tracing.current().currentTraceContext().newScope(context)) { get(tracedClient); } } }
@Override public void accept(CurrentTraceContext current) { try (Scope ws = current.newScope(TraceContext.newBuilder().traceId(1L).spanId(2L).build())) { } } }
@Override public void accept(CurrentTraceContext current) { current.newScope(TraceContext.newBuilder().traceId(1L).spanId(2L).build()); } }
@Override public void process(HttpRequest request, HttpContext context) { HttpHost host = HttpClientContext.adapt(context).getTargetHost(); TraceContext parent = (TraceContext) context.getAttribute(TraceContext.class.getName()); Span span; try (Scope scope = currentTraceContext.maybeScope(parent)) { span = handler.nextSpan(request); } HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request, host); parseTargetAddress(requestWrapper, span); handler.handleSend(injector, request, requestWrapper, span); context.setAttribute(Span.class.getName(), span); context.setAttribute(Scope.class.getName(), currentTraceContext.newScope(span.context())); } }
@Test public void restoresSpanAfterRunnable() throws Exception { TraceContext context0 = TraceContext.newBuilder().traceId(3L).spanId(3L).build(); try (Scope scope0 = currentTraceContext.newScope(context0)) { attachesSpanInRunnable(); assertThat(currentTraceContext.get()) .isEqualTo(context0); verifyImplicitContext(context0); } }
@Test public void copy() { try (SafeCloseable requestContextScope = mockRequestContext.push()) { try (Scope traceContextScope = currentTraceContext.newScope(traceContext)) { RequestContextCurrentTraceContext.copy(mockRequestContext, mockRequestContext2); assertThat(attrs1.attrs().next().get()) .isEqualTo(traceContext) .isEqualTo(attrs2.attrs().next().get()); } } }
@Test public void newScope_canClearScope() { try (SafeCloseable requestContextScope = mockRequestContext.push()) { try (Scope traceContextScope = currentTraceContext.newScope(traceContext)) { try (Scope traceContextScope2 = currentTraceContext.newScope(null)) { assertThat(currentTraceContext.get()).isNull(); } assertThat(currentTraceContext.get()).isEqualTo(traceContext); } } }
@Test public void newScope_appliesWhenCurrentRequestContext() { try (SafeCloseable requestContextScope = mockRequestContext.push()) { try (Scope traceContextScope = currentTraceContext.newScope(traceContext)) { assertThat(traceContextScope).hasToString("InitialRequestScope"); assertThat(currentTraceContext.get()).isEqualTo(traceContext); } } }
@Test public void newScope_doesNothingWhenNoCurrentRequestContext() { try (Scope traceContextScope = currentTraceContext.newScope(traceContext)) { assertThat(traceContextScope).hasToString("IncompleteConfigurationScope"); assertThat(currentTraceContext.get()).isNull(); } }
@Test public void newScope_respondsToPing() { final PingPongExtra extra = new PingPongExtra(); final TraceContext extraContext = TraceContext.newBuilder().traceId(1).spanId(1) .extra(Collections.singletonList(extra)).build(); try (Scope traceContextScope = currentTraceContext.newScope(extraContext)) { assertThat(traceContextScope).hasToString("NoopScope"); assertThat(extra.isPong()).isTrue(); } }