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);
}
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()));
}
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();
}
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);
}
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);
}
Aggregations