use of brave.Span in project brave by openzipkin.
the class TracingContainerFilter method filter.
@Override
public void filter(ContainerRequestContext request) {
if (resourceInfo != null)
request.setProperty(ResourceInfo.class.getName(), resourceInfo);
Span span = handler.handleReceive(extractor, request);
if (resourceInfo != null)
parser.resourceInfo(resourceInfo, span);
request.removeProperty(ResourceInfo.class.getName());
if (shouldPutSpanInScope(resourceInfo)) {
request.setProperty(SpanInScope.class.getName(), tracer.withSpanInScope(span));
} else {
request.setProperty(Span.class.getName(), span);
}
}
use of brave.Span in project brave by openzipkin.
the class KafkaTracingTest method nextSpan_should_use_span_from_headers_as_parent.
@Test
public void nextSpan_should_use_span_from_headers_as_parent() {
addB3Headers(fakeRecord);
Span span = kafkaTracing.nextSpan(fakeRecord);
TraceContext context = span.context();
assertThat(HexCodec.toLowerHex(context.traceId())).isEqualTo(TRACE_ID);
assertThat(HexCodec.toLowerHex(context.parentId())).isEqualTo(SPAN_ID);
assertThat(context.sampled()).isEqualTo(true);
}
use of brave.Span in project brave by openzipkin.
the class KafkaTracingTest method joinSpan_should_retrieve_span_from_headers.
@Test
public void joinSpan_should_retrieve_span_from_headers() {
addB3Headers(fakeRecord);
Span span = kafkaTracing.joinSpan(fakeRecord);
TraceContext context = span.context();
assertThat(HexCodec.toLowerHex(context.traceId())).isEqualTo(TRACE_ID);
assertThat(HexCodec.toLowerHex(context.spanId())).isEqualTo(SPAN_ID);
assertThat(context.sampled()).isEqualTo(true);
}
use of brave.Span in project brave by openzipkin.
the class TracingJdbcEventListenerTest method nullSqlWontNPE.
@Test
public void nullSqlWontNPE() throws SQLException {
ArrayList<zipkin2.Span> spans = new ArrayList<>();
try (Tracing tracing = tracingBuilder(Sampler.ALWAYS_SAMPLE, spans).build()) {
when(statementInformation.getSql()).thenReturn(null);
when(statementInformation.getConnectionInformation()).thenReturn(ci);
when(ci.getConnection()).thenReturn(connection);
when(connection.getMetaData()).thenReturn(metaData);
when(metaData.getURL()).thenReturn(url);
TracingJdbcEventListener listener = new TracingJdbcEventListener("", false);
listener.onBeforeAnyExecute(statementInformation);
listener.onAfterAnyExecute(statementInformation, 1, null);
assertThat(spans).isEmpty();
}
}
use of brave.Span in project brave by openzipkin.
the class OneWaySpanTest method startWithOneTracerAndStopWithAnother.
@Test
public void startWithOneTracerAndStopWithAnother() throws Exception {
// start a new span representing a request
Span span = clientTracing.tracer().newTrace();
// inject the trace context into the request
Request.Builder request = new Request.Builder().url(server.url("/"));
clientTracing.propagation().injector(Request.Builder::addHeader).inject(span.context(), request);
// fire off the request asynchronously, totally dropping any response
new OkHttpClient().newCall(request.build()).enqueue(mock(Callback.class));
// start the client side and flush instead of processing a response
span.kind(Span.Kind.CLIENT).start().flush();
// block on the server handling the request, so we can run assertions
flushedIncomingRequest.await();
// // zipkin doesn't backfill timestamp and duration when storing raw spans
List<zipkin2.Span> spans = storage.spanStore().getTrace(span.context().traceIdString()).execute();
// check that the client send arrived first
zipkin2.Span clientSpan = spans.get(0);
assertThat(clientSpan.name()).isNull();
assertThat(clientSpan.localServiceName()).isEqualTo("client");
assertThat(clientSpan.kind()).isEqualTo(zipkin2.Span.Kind.CLIENT);
// check that the server receive arrived last
zipkin2.Span serverSpan = spans.get(1);
assertThat(serverSpan.name()).isEqualTo("get");
assertThat(serverSpan.localServiceName()).isEqualTo("server");
assertThat(serverSpan.kind()).isEqualTo(zipkin2.Span.Kind.SERVER);
// check that the server span is shared
assertThat(serverSpan.shared()).isTrue();
// check that no spans reported duration
assertThat(clientSpan.duration()).isNull();
assertThat(serverSpan.duration()).isNull();
}
Aggregations