Search in sources :

Example 31 with TraceContext

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

the class HttpClientHandler method nextSpan.

/**
 * Creates a potentially noop span representing this request. This is used when you need to
 * provision a span in a different scope than where the request is executed.
 *
 * @since 4.4
 */
public Span nextSpan(Req request) {
    TraceContext parent = currentTraceContext.get();
    // inherit the sampling decision
    if (parent != null)
        return tracer.newChild(parent);
    // If there was no parent, we are making a new trace. Try to sample the request.
    Boolean sampled = sampler.trySample(adapter, request);
    // defer sampling decision to trace ID
    if (sampled == null)
        return tracer.newTrace();
    return tracer.newTrace(sampled ? SamplingFlags.SAMPLED : SamplingFlags.NOT_SAMPLED);
}
Also used : CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext)

Example 32 with TraceContext

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

the class HttpServerHandlerTest method handleReceive_reusesSpanIds.

@Test
public void handleReceive_reusesSpanIds() {
    TraceContext incomingContext = tracer.nextSpan().context();
    when(extractor.extract(request)).thenReturn(TraceContextOrSamplingFlags.create(incomingContext));
    handler.handleReceive(extractor, request).finish();
    assertThat(spans.get(0).shared()).isTrue();
    assertThat(spans.get(0).traceId()).isEqualTo(incomingContext.traceIdString());
    assertThat(spans.get(0).id()).isEqualTo(HexCodec.toLowerHex(incomingContext.spanId()));
}
Also used : TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 33 with TraceContext

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

the class HttpServerHandlerTest method handleReceive_makesRequestBasedSamplingDecision_context.

@Test
public void handleReceive_makesRequestBasedSamplingDecision_context() {
    TraceContext incomingContext = tracer.nextSpan().context().toBuilder().sampled(null).build();
    when(extractor.extract(request)).thenReturn(TraceContextOrSamplingFlags.create(incomingContext));
    // request sampler says false eventhough trace ID sampler would have said true
    when(sampler.trySample(adapter, request)).thenReturn(false);
    assertThat(handler.handleReceive(extractor, request).isNoop()).isTrue();
}
Also used : TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 34 with TraceContext

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

the class KafkaTracingTest method joinSpan_should_create_span_if_no_headers.

@Test
public void joinSpan_should_create_span_if_no_headers() {
    Span span = kafkaTracing.joinSpan(fakeRecord);
    TraceContext context = span.context();
    assertThat(HexCodec.toLowerHex(context.traceId())).isNotEmpty().isNotEqualTo(TRACE_ID);
    assertThat(HexCodec.toLowerHex(context.spanId())).isNotEmpty().isNotEqualTo(SPAN_ID);
}
Also used : TraceContext(brave.propagation.TraceContext) Span(brave.Span) Test(org.junit.Test)

Example 35 with TraceContext

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

the class KafkaTracingTest method nextSpan_should_create_span_if_no_headers.

@Test
public void nextSpan_should_create_span_if_no_headers() {
    Span span = kafkaTracing.nextSpan(fakeRecord);
    TraceContext context = span.context();
    assertThat(HexCodec.toLowerHex(context.traceId())).isNotEmpty().isNotEqualTo(TRACE_ID);
    assertThat(HexCodec.toLowerHex(context.spanId())).isNotEmpty().isNotEqualTo(SPAN_ID);
}
Also used : TraceContext(brave.propagation.TraceContext) Span(brave.Span) 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