Search in sources :

Example 1 with Nullable

use of brave.internal.Nullable in project brave by openzipkin.

the class ThreadLocalSpan method remove.

/**
 * 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;
    SpanAndScope scope = currentSpanInScope.get().pollFirst();
    if (scope == null)
        return currentSpan;
    scope.scope().close();
    assert scope.span().equals(currentSpan) : "Misalignment: scoped span " + scope.span() + " !=  current span " + currentSpan;
    return currentSpan;
}
Also used : Tracer(brave.Tracer) Span(brave.Span) Nullable(brave.internal.Nullable)

Example 2 with Nullable

use of brave.internal.Nullable in project brave by openzipkin.

the class ThreadLocalSpan method 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);
    SpanAndScope spanAndScope = SpanAndScope.create(next, tracer.withSpanInScope(next));
    currentSpanInScope.get().addFirst(spanAndScope);
    return next;
}
Also used : Tracer(brave.Tracer) Span(brave.Span) Nullable(brave.internal.Nullable)

Example 3 with Nullable

use of brave.internal.Nullable in project brave by openzipkin.

the class ThreadLocalSpan method next.

/**
 * 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();
    SpanAndScope spanAndScope = SpanAndScope.create(next, tracer.withSpanInScope(next));
    currentSpanInScope.get().addFirst(spanAndScope);
    return next;
}
Also used : Tracer(brave.Tracer) Span(brave.Span) Nullable(brave.internal.Nullable)

Example 4 with Nullable

use of brave.internal.Nullable in project brave by openzipkin.

the class AWSPropagation method currentTraceId.

/**
 * Returns the current {@link #traceId(TraceContext)} or null if not available
 */
@Nullable
public static String currentTraceId() {
    Tracing tracing = Tracing.current();
    if (tracing == null)
        return null;
    TraceContext context = tracing.currentTraceContext().get();
    if (context == null)
        return null;
    return traceId(context);
}
Also used : TraceContext(brave.propagation.TraceContext) Tracing(brave.Tracing) Nullable(brave.internal.Nullable)

Aggregations

Nullable (brave.internal.Nullable)4 Span (brave.Span)3 Tracer (brave.Tracer)3 Tracing (brave.Tracing)1 TraceContext (brave.propagation.TraceContext)1