/** * Returns the span set in scope via {@link #next()} or null if there was none. * * <p>When assertions are on, this will throw an assertion error if the span returned was not the * one currently in context. This could happen if someone called {@link * Tracer#withSpanInScope(Span)} or {@link CurrentTraceContext#newScope(TraceContext)} outside a * try/finally block. */ @Nullable public Span remove() { Tracer tracer = tracer(); Span currentSpan = tracer != null ? tracer.currentSpan() : null; Object[] spanAndScope = getCurrentSpanInScopeStack().pollFirst(); if (spanAndScope == null) return currentSpan; Span span = (Span) spanAndScope[0]; ((SpanInScope) spanAndScope[1]).close(); assert span.equals(currentSpan) : "Misalignment: scoped span " + span + " != current span " + currentSpan; return currentSpan; }
/** * Returns the {@link Tracer#nextSpan()} or null if {@link #CURRENT_TRACER} and tracing isn't * available. */ @Nullable public Span next() { Tracer tracer = tracer(); if (tracer == null) return null; Span next = tracer.nextSpan(); Object[] spanAndScope = {next, tracer.withSpanInScope(next)}; getCurrentSpanInScopeStack().addFirst(spanAndScope); return next; }
/** * Returns the {@link Tracer#nextSpan(TraceContextOrSamplingFlags)} or null if {@link * #CURRENT_TRACER} and tracing isn't available. */ @Nullable public Span next(TraceContextOrSamplingFlags extracted) { Tracer tracer = tracer(); if (tracer == null) return null; Span next = tracer.nextSpan(extracted); Object[] spanAndScope = {next, tracer.withSpanInScope(next)}; getCurrentSpanInScopeStack().addFirst(spanAndScope); return next; }
/** * Returns the span set in scope via {@link #next()} or null if there was none. * * <p>When assertions are on, this will throw an assertion error if the span returned was not the * one currently in context. This could happen if someone called {@link * Tracer#withSpanInScope(Span)} or {@link CurrentTraceContext#newScope(TraceContext)} outside a * try/finally block. */ @Nullable public Span remove() { Tracer tracer = tracer(); Span currentSpan = tracer != null ? tracer.currentSpan() : null; Object[] spanAndScope = getCurrentSpanInScopeStack().pollFirst(); if (spanAndScope == null) return currentSpan; Span span = (Span) spanAndScope[0]; ((SpanInScope) spanAndScope[1]).close(); assert span.equals(currentSpan) : "Misalignment: scoped span " + span + " != current span " + currentSpan; return currentSpan; }
/** * Returns the {@link Tracer#nextSpan()} or null if {@link #CURRENT_TRACER} and tracing isn't * available. */ @Nullable public Span next() { Tracer tracer = tracer(); if (tracer == null) return null; Span next = tracer.nextSpan(); Object[] spanAndScope = {next, tracer.withSpanInScope(next)}; getCurrentSpanInScopeStack().addFirst(spanAndScope); return next; }
/** * Returns the {@link Tracer#nextSpan(TraceContextOrSamplingFlags)} or null if {@link * #CURRENT_TRACER} and tracing isn't available. */ @Nullable public Span next(TraceContextOrSamplingFlags extracted) { Tracer tracer = tracer(); if (tracer == null) return null; Span next = tracer.nextSpan(extracted); Object[] spanAndScope = {next, tracer.withSpanInScope(next)}; getCurrentSpanInScopeStack().addFirst(spanAndScope); return next; }