Search in sources :

Example 1 with Span

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);
    }
}
Also used : ResourceInfo(javax.ws.rs.container.ResourceInfo) SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span)

Example 2 with 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);
}
Also used : TraceContext(brave.propagation.TraceContext) Span(brave.Span) Test(org.junit.Test)

Example 3 with Span

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);
}
Also used : TraceContext(brave.propagation.TraceContext) Span(brave.Span) Test(org.junit.Test)

Example 4 with Span

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();
    }
}
Also used : ArrayList(java.util.ArrayList) Tracing(brave.Tracing) Span(brave.Span) Test(org.junit.Test)

Example 5 with Span

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();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Callback(okhttp3.Callback) Request(okhttp3.Request) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Span(brave.Span) Test(org.junit.Test)

Aggregations

Span (brave.Span)279 Test (org.junit.Test)156 Tracer (brave.Tracer)100 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)45 SpanInScope (brave.Tracer.SpanInScope)38 Tracing (brave.Tracing)19 ThreadLocalSpan (brave.propagation.ThreadLocalSpan)19 TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)19 TraceContext (brave.propagation.TraceContext)17 Scope (brave.propagation.CurrentTraceContext.Scope)16 Bean (org.springframework.context.annotation.Bean)13 Configuration (org.springframework.context.annotation.Configuration)13 Log (org.apache.commons.logging.Log)12 LogFactory (org.apache.commons.logging.LogFactory)12 Sampler (brave.sampler.Sampler)11 BDDAssertions.then (org.assertj.core.api.BDDAssertions.then)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 CurrentTraceContext (brave.propagation.CurrentTraceContext)10 RunWith (org.junit.runner.RunWith)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9