Search in sources :

Example 21 with TraceContextOrSamplingFlags

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

the class TracingRabbitListenerAdvice method invoke.

/**
 * MethodInterceptor for {@link SimpleMessageListenerContainer.ContainerDelegate#invokeListener(Channel, Message)}
 */
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
    Message message = (Message) methodInvocation.getArguments()[1];
    TraceContextOrSamplingFlags extracted = extractTraceContextAndRemoveHeaders(message);
    // named for BlockingQueueConsumer.nextMessage, which we can't currently see
    Span consumerSpan = tracer.nextSpan(extracted).kind(CONSUMER).name("next-message");
    Span listenerSpan = tracer.newChild(consumerSpan.context()).name("on-message");
    if (!consumerSpan.isNoop()) {
        consumerSpan.start();
        tagReceivedMessageProperties(consumerSpan, message.getMessageProperties());
        if (remoteServiceName != null) {
            consumerSpan.remoteEndpoint(Endpoint.newBuilder().serviceName(remoteServiceName).build());
        }
        consumerSpan.finish();
        listenerSpan.start();
    }
    try (SpanInScope ws = tracer.withSpanInScope(listenerSpan)) {
        return methodInvocation.proceed();
    } catch (Throwable t) {
        tagErrorSpan(listenerSpan, t);
        throw t;
    } finally {
        listenerSpan.finish();
    }
}
Also used : Message(org.springframework.amqp.core.Message) SpanInScope(brave.Tracer.SpanInScope) TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) Span(brave.Span)

Example 22 with TraceContextOrSamplingFlags

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

the class PropagationTest method verifyRoundTrip.

void verifyRoundTrip(TraceContextOrSamplingFlags expected) {
    TraceContextOrSamplingFlags extracted = propagation().extractor(mapEntry).extract(map);
    assertThat(extracted).isEqualTo(expected);
    Map<K, String> injected = new LinkedHashMap<>();
    if (expected.context() != null) {
        propagation().injector(mapEntry).inject(expected.context(), injected);
    } else {
        inject(injected, expected.samplingFlags());
    }
    assertThat(map).isEqualTo(injected);
}
Also used : TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with TraceContextOrSamplingFlags

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

the class TracerTest method nextSpan_extractedExtra_childOfCurrent.

@Test
public void nextSpan_extractedExtra_childOfCurrent() {
    Span parent = tracer.newTrace();
    TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.create(SamplingFlags.EMPTY).toBuilder().addExtra(1L).build();
    try (Tracer.SpanInScope ws = tracer.withSpanInScope(parent)) {
        assertThat(tracer.nextSpan(extracted).context().extra()).containsExactly(1L);
    }
}
Also used : TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) Test(org.junit.Test)

Example 24 with TraceContextOrSamplingFlags

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

the class TracerTest method nextSpan_extractedTraceId.

@Test
public void nextSpan_extractedTraceId() {
    TraceIdContext traceIdContext = TraceIdContext.newBuilder().traceId(1L).build();
    TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.create(traceIdContext);
    assertThat(tracer.nextSpan(extracted).context().traceId()).isEqualTo(1L);
}
Also used : TraceIdContext(brave.propagation.TraceIdContext) TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) Test(org.junit.Test)

Example 25 with TraceContextOrSamplingFlags

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

the class TracerTest method nextSpan_extractedTraceContext_extra.

@Test
public void nextSpan_extractedTraceContext_extra() {
    TraceContext traceContext = TraceContext.newBuilder().traceId(1L).spanId(2L).build();
    TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.create(traceContext).toBuilder().addExtra(1L).build();
    assertThat(tracer.nextSpan(extracted).context().extra()).containsExactly(1L);
}
Also used : StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) TraceContext(brave.propagation.TraceContext) TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) Test(org.junit.Test)

Aggregations

TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)27 Test (org.junit.Test)13 Span (brave.Span)10 ThreadLocalSpan (brave.propagation.ThreadLocalSpan)4 TraceContext (brave.propagation.TraceContext)4 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)4 StrictCurrentTraceContext (brave.propagation.StrictCurrentTraceContext)3 GenericMessage (org.springframework.messaging.support.GenericMessage)3 Tracer (brave.Tracer)2 TraceIdContext (brave.propagation.TraceIdContext)2 LinkedHashMap (java.util.LinkedHashMap)2 Endpoint (zipkin2.Endpoint)2 Kind (brave.Span.Kind)1 SpanInScope (brave.Tracer.SpanInScope)1 Result (com.alibaba.dubbo.rpc.Result)1 RpcContext (com.alibaba.dubbo.rpc.RpcContext)1 FutureAdapter (com.alibaba.dubbo.rpc.protocol.dubbo.FutureAdapter)1 SimpleForwardingServerCall (io.grpc.ForwardingServerCall.SimpleForwardingServerCall)1 ServerCall (io.grpc.ServerCall)1 TextMap (io.opentracing.propagation.TextMap)1