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