Search in sources :

Example 36 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class TracingCallFactory method newCall.

@Override
public Call newCall(Request request) {
    TraceContext currentSpan = currentTraceContext.get();
    OkHttpClient.Builder b = ok.newBuilder();
    if (currentSpan != null)
        b.interceptors().add(0, new SetParentSpanInScope(currentSpan));
    // TODO: This can hide errors at the beginning of call.execute, such as invalid host!
    return b.build().newCall(request);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext)

Example 37 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class CurrentTraceContextTest method restoresSpanAfterRunnable.

@Test
public void restoresSpanAfterRunnable() throws Exception {
    TraceContext context0 = TraceContext.newBuilder().traceId(3L).spanId(3L).build();
    try (CurrentTraceContext.Scope scope0 = currentTraceContext.newScope(context0)) {
        attachesSpanInRunnable();
        assertThat(currentTraceContext.get()).isEqualTo(context0);
        verifyImplicitContext(context0);
    }
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) CurrentTraceContext(brave.propagation.CurrentTraceContext) Test(org.junit.Test)

Example 38 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class Tracer method toString.

@Override
public String toString() {
    TraceContext currentSpan = currentTraceContext.get();
    List<zipkin2.Span> inFlight = recorder.snapshot();
    return "Tracer{" + (currentSpan != null ? ("currentSpan=" + currentSpan + ", ") : "") + (inFlight.size() > 0 ? ("inFlight=" + inFlight + ", ") : "") + (noop.get() ? "noop=true, " : "") + "reporter=" + reporter + "}";
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext)

Example 39 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class MutableSpanMap method reportOrphanedSpans.

/**
 * Reports spans orphaned by garbage collection.
 */
void reportOrphanedSpans() {
    Reference<? extends TraceContext> reference;
    while ((reference = poll()) != null) {
        TraceContext context = reference.get();
        MutableSpan value = delegate.remove(reference);
        if (value == null || noop.get())
            continue;
        try {
            value.annotate(value.clock.currentTimeMicroseconds(), "brave.flush");
            reporter.report(value.toSpan());
        } catch (RuntimeException e) {
            // don't crash the caller if there was a problem reporting an unrelated span.
            if (context != null && logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "error flushing " + context, e);
            }
        }
    }
}
Also used : TraceContext(brave.propagation.TraceContext)

Example 40 with TraceContext

use of brave.propagation.TraceContext in project brave by openzipkin.

the class CurrentTraceContextExecutorTest method execute.

@Test
public void execute() throws Exception {
    final TraceContext[] threadValues = new TraceContext[2];
    CountDownLatch latch = new CountDownLatch(1);
    // execution time.
    try (CurrentTraceContext.Scope ws = currentTraceContext.newScope(context)) {
        executor.execute(() -> {
            threadValues[0] = currentTraceContext.get();
            try {
                latch.await();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                e.printStackTrace();
            }
        });
        // this won't run immediately because the other is blocked
        executor.execute(() -> threadValues[1] = currentTraceContext.get());
    }
    // invoked with
    try (CurrentTraceContext.Scope ws = currentTraceContext.newScope(context2)) {
        latch.countDown();
        shutdownExecutor();
        assertThat(threadValues).containsExactly(context, context);
    }
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) CountDownLatch(java.util.concurrent.CountDownLatch) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) CurrentTraceContext(brave.propagation.CurrentTraceContext) Test(org.junit.Test)

Aggregations

TraceContext (brave.propagation.TraceContext)54 Test (org.junit.Test)46 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)21 CurrentTraceContext (brave.propagation.CurrentTraceContext)10 TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Span (brave.Span)4 Tracer (brave.Tracer)4 Tracing (brave.Tracing)4 ThreadContextCurrentTraceContext (brave.context.log4j2.ThreadContextCurrentTraceContext)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 After (org.junit.After)4 Endpoint (zipkin2.Endpoint)4 Span (zipkin2.Span)4 Platform (brave.internal.Platform)3 Propagation (brave.propagation.Propagation)3 Reference (java.lang.ref.Reference)3