Search in sources :

Example 1 with TraceContext

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

the class AWSPropagationTest method injectExtraStuff.

@Test
public void injectExtraStuff() {
    AWSPropagation.Extra extra = new AWSPropagation.Extra();
    extra.fields = ";Robot=Hello;TotalTimeSoFar=112ms;CalledFrom=Foo";
    TraceContext extraContext = sampledContext.toBuilder().extra(Arrays.asList(extra)).build();
    injector.inject(extraContext, carrier);
    assertThat(carrier).containsEntry("x-amzn-trace-id", "Root=1-67891233-abcdef012345678912345678;Parent=463ac35c9f6413ad;Sampled=1;Robot=Hello;TotalTimeSoFar=112ms;CalledFrom=Foo");
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 2 with TraceContext

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

the class AWSPropagationTest method traceIdWhenPassThrough_nullOnTruncated.

@Test
public void traceIdWhenPassThrough_nullOnTruncated() {
    carrier.put("x-amzn-trace-id", "Root=1-58211399-36d228ad5d99923122bbe3");
    TraceContext context = contextWithPassThrough();
    assertThat(AWSPropagation.traceId(context)).isNull();
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 3 with TraceContext

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

the class ITTracingClientInterceptor method usesParentFromInvocationTime.

/**
 * This tests that the parent is determined at the time the request was made, not when the request
 * was executed.
 */
@Test
public void usesParentFromInvocationTime() throws Exception {
    server.enqueueDelay(TimeUnit.SECONDS.toMillis(1));
    GreeterGrpc.GreeterFutureStub futureStub = GreeterGrpc.newFutureStub(client);
    brave.Span parent = tracer.newTrace().name("test").start();
    try (Tracer.SpanInScope ws = tracer.withSpanInScope(parent)) {
        futureStub.sayHello(HELLO_REQUEST);
        futureStub.sayHello(HELLO_REQUEST);
    } finally {
        parent.finish();
    }
    brave.Span otherSpan = tracer.newTrace().name("test2").start();
    try (Tracer.SpanInScope ws = tracer.withSpanInScope(otherSpan)) {
        for (int i = 0; i < 2; i++) {
            TraceContext context = server.takeRequest().context();
            assertThat(context.traceId()).isEqualTo(parent.context().traceId());
            assertThat(context.parentId()).isEqualTo(parent.context().spanId());
        }
    } finally {
        otherSpan.finish();
    }
    // Check we reported 2 local spans and 2 client spans
    assertThat(Arrays.asList(spans.take(), spans.take(), spans.take(), spans.take())).extracting(Span::kind).containsOnly(null, Span.Kind.CLIENT);
}
Also used : Tracer(brave.Tracer) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) ThreadContextCurrentTraceContext(brave.context.log4j2.ThreadContextCurrentTraceContext) Test(org.junit.Test)

Example 4 with TraceContext

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

the class ITTracingClientInterceptor method propagatesSpan.

@Test
public void propagatesSpan() throws Exception {
    GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
    TraceContext context = server.takeRequest().context();
    assertThat(context.parentId()).isNull();
    assertThat(context.sampled()).isTrue();
    spans.take();
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) ThreadContextCurrentTraceContext(brave.context.log4j2.ThreadContextCurrentTraceContext) Test(org.junit.Test)

Example 5 with TraceContext

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

the class HttpClientHandlerTest method handleSend_injectsTheTraceContext_onTheCarrier.

@Test
public void handleSend_injectsTheTraceContext_onTheCarrier() {
    Object customCarrier = new Object();
    TraceContext context = handler.handleSend(injector, customCarrier, request).context();
    verify(injector).inject(context, customCarrier);
}
Also used : TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Aggregations

TraceContext (brave.propagation.TraceContext)194 Test (org.junit.Test)161 CurrentTraceContext (brave.propagation.CurrentTraceContext)73 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)52 Scope (brave.propagation.CurrentTraceContext.Scope)46 MutableSpan (brave.handler.MutableSpan)38 Span (brave.Span)14 MockResponse (okhttp3.mockwebserver.MockResponse)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 SpanHandler (brave.handler.SpanHandler)9 Clock (brave.Clock)7 TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 TestSpanHandler (brave.test.TestSpanHandler)6 AssertableCallback (brave.test.util.AssertableCallback)6 Message (javax.jms.Message)6 After (org.junit.After)6 Tracing (brave.Tracing)5 SamplingFlags (brave.propagation.SamplingFlags)5