Search in sources :

Example 26 with TraceContext

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

the class MutableSpanMapTest method getOrCreate_reusesClockFromParent.

/**
 * Ensure we use the same clock for traces that started in-process
 */
@Test
public void getOrCreate_reusesClockFromParent() {
    TraceContext trace = TraceContext.newBuilder().traceId(1L).spanId(2L).build();
    TraceContext trace2 = TraceContext.newBuilder().traceId(2L).spanId(2L).build();
    TraceContext traceChild = TraceContext.newBuilder().traceId(1L).parentId(2L).spanId(3L).build();
    MutableSpan traceSpan = map.getOrCreate(trace);
    MutableSpan trace2Span = map.getOrCreate(trace2);
    MutableSpan traceChildSpan = map.getOrCreate(traceChild);
    assertThat(traceSpan.clock).isSameAs(traceChildSpan.clock);
    assertThat(traceSpan.clock).isNotSameAs(trace2Span.clock);
}
Also used : TraceContext(brave.propagation.TraceContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with TraceContext

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

the class ITTracingFilter_Consumer method makesChildOfCurrentSpan.

@Test
public void makesChildOfCurrentSpan() throws Exception {
    brave.Span parent = tracing.tracer().newTrace().name("test").start();
    try (Tracer.SpanInScope ws = tracing.tracer().withSpanInScope(parent)) {
        client.get().sayHello("jorge");
    } finally {
        parent.finish();
    }
    TraceContext context = server.takeRequest().context();
    assertThat(context.traceId()).isEqualTo(parent.context().traceId());
    assertThat(context.parentId()).isEqualTo(parent.context().spanId());
    // we report one local and one client span
    assertThat(Arrays.asList(spans.take(), spans.take())).extracting(Span::kind).containsOnly(null, Span.Kind.CLIENT);
}
Also used : Tracer(brave.Tracer) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 28 with TraceContext

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

the class ITTracingFilter_Consumer method propagatesSpan.

@Test
public void propagatesSpan() throws Exception {
    client.get().sayHello("jorge");
    TraceContext context = server.takeRequest().context();
    assertThat(context.parentId()).isNull();
    assertThat(context.sampled()).isTrue();
    spans.take();
}
Also used : TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 29 with TraceContext

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

the class ITTracingClientInterceptor method makesChildOfCurrentSpan.

@Test
public void makesChildOfCurrentSpan() throws Exception {
    brave.Span parent = tracer.newTrace().name("test").start();
    try (Tracer.SpanInScope ws = tracer.withSpanInScope(parent)) {
        GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
    } finally {
        parent.finish();
    }
    TraceContext context = server.takeRequest().context();
    assertThat(context.traceId()).isEqualTo(parent.context().traceId());
    assertThat(context.parentId()).isEqualTo(parent.context().spanId());
    // we report one local and one client span
    assertThat(Arrays.asList(spans.take(), spans.take())).extracting(Span::kind).containsOnly(null, Span.Kind.CLIENT);
}
Also used : Tracer(brave.Tracer) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) ThreadContextCurrentTraceContext(brave.context.log4j2.ThreadContextCurrentTraceContext) Test(org.junit.Test)

Example 30 with TraceContext

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

the class ITTracingServerInterceptor method currentSpanVisibleToUserInterceptors.

/**
 * NOTE: for this to work, the tracing interceptor must be last (so that it executes first)
 *
 * <p>Also notice that we are only making the current context available in the request side.
 */
@Test
public void currentSpanVisibleToUserInterceptors() throws Exception {
    AtomicReference<TraceContext> fromUserInterceptor = new AtomicReference<>();
    init(new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
            testLogger.info("in span!");
            fromUserInterceptor.set(grpcTracing.tracing().currentTraceContext().get());
            return next.startCall(call, headers);
        }
    });
    GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
    assertThat(fromUserInterceptor.get()).isNotNull();
    spans.take();
}
Also used : ServerInterceptor(io.grpc.ServerInterceptor) Metadata(io.grpc.Metadata) TraceContext(brave.propagation.TraceContext) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) ThreadContextCurrentTraceContext(brave.context.log4j2.ThreadContextCurrentTraceContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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