use of brave.propagation.TraceContext in project brave by openzipkin.
the class TracingTest method alwaysReportSpans_reportsEvenWhenUnsampled.
@Test
public void alwaysReportSpans_reportsEvenWhenUnsampled() {
TraceContext sampledLocal = TraceContext.newBuilder().traceId(1).spanId(1).sampledLocal(true).build();
try (Tracing tracing = Tracing.newBuilder().addSpanHandler(spans).sampler(Sampler.NEVER_SAMPLE).alwaysReportSpans().build()) {
tracing.tracer().toSpan(sampledLocal).start().finish();
}
assertThat(spans).isNotEmpty();
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class OpenTracingAdapterTest method injectTraceContext.
@Test
public void injectTraceContext() {
TraceContext context = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build();
Map<String, String> map = new LinkedHashMap<>();
TextMapAdapter request = new TextMapAdapter(map);
opentracing.inject(new BraveSpanContext(context), Format.Builtin.HTTP_HEADERS, request);
assertThat(map).containsExactly(entry("X-B3-TraceId", "0000000000000001"), entry("X-B3-SpanId", "0000000000000002"), entry("X-B3-Sampled", "1"));
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class InternalPropagationTest method shallowCopy.
@Test
public void shallowCopy() {
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(2).debug(true).extra(Collections.singletonList(1L)).build();
assertThat(InternalPropagation.instance.shallowCopy(context)).isNotSameAs(context).usingRecursiveComparison().isEqualTo(context);
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class TracingInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
RequestWrapper request = new RequestWrapper(chain.request());
Span span;
TraceContext parent = chain.request().tag(TraceContext.class);
if (parent != null) {
// TracingCallFactory setup this request
span = handler.handleSendWithParent(request, parent != NULL_SENTINEL ? parent : null);
} else {
// This is using interceptors only
span = handler.handleSend(request);
}
parseRouteAddress(chain, span);
Response response = null;
Throwable error = null;
try (Scope ws = currentTraceContext.newScope(span.context())) {
return response = chain.proceed(request.build());
} catch (Throwable t) {
error = t;
throw t;
} finally {
// Intentionally not the same instance as chain.proceed, as properties may have changed
if (response != null)
request = new RequestWrapper(response.request());
handler.handleReceive(new ResponseWrapper(request, response, error), span);
}
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class ITKafkaTracing method continues_a_trace_when_only_trace_id_propagated.
@Test
public void continues_a_trace_when_only_trace_id_propagated() {
consumerTracing = KafkaTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).clearSpanHandlers().addSpanHandler(consumerSpanHandler).propagationFactory(new TraceIdOnlyPropagation()).build());
producerTracing = KafkaTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).clearSpanHandlers().addSpanHandler(producerSpanHandler).propagationFactory(new TraceIdOnlyPropagation()).build());
producer = createTracingProducer();
consumer = createTracingConsumer();
send(new ProducerRecord<>(testName.getMethodName(), TEST_KEY, TEST_VALUE));
// intentionally using deprecated method as we are checking the same class in an invoker test
// under src/it. If we want to explicitly tests the Duration arg, we will have to subclass.
ConsumerRecords<String, String> records = consumer.poll(10_000L);
assertThat(records).hasSize(1);
MutableSpan producerSpan = takeProducerSpan();
MutableSpan consumerSpan = takeConsumerSpan();
assertThat(producerSpan.traceId()).isEqualTo(consumerSpan.traceId());
for (ConsumerRecord<String, String> record : records) {
TraceContext forProcessor = consumerTracing.nextSpan(record).context();
assertThat(forProcessor.traceIdString()).isEqualTo(consumerSpan.traceId());
}
}
Aggregations