Search in sources :

Example 6 with SpanInScope

use of brave.Tracer.SpanInScope in project java-chassis by ServiceComb.

the class ZipkinTracingFilter method onFilter.

@SuppressWarnings({ "try", "unused" })
@Override
public CompletableFuture<Response> onFilter(Invocation invocation, FilterNode nextNode) {
    ZipkinTracingDelegate tracing = collectTracing(invocation);
    Span span = tracing.createSpan(invocation);
    try (SpanInScope scope = tracing.tracer().tracer().withSpanInScope(span)) {
        return nextNode.onFilter(invocation).whenComplete((response, exception) -> tracing.onResponse(span, response, Exceptions.unwrap(exception)));
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span)

Example 7 with SpanInScope

use of brave.Tracer.SpanInScope in project brave by openzipkin.

the class TracingClientFilter method filter.

@Override
public void filter(ClientRequestContext request, ClientResponseContext response) {
    Span span = tracer.currentSpan();
    if (span == null)
        return;
    ((SpanInScope) request.getProperty(SpanInScope.class.getName())).close();
    handler.handleReceive(new ClientResponseContextWrapper(request, response), span);
}
Also used : SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span)

Example 8 with SpanInScope

use of brave.Tracer.SpanInScope in project brave by openzipkin.

the class TracerTest method nextSpan_getsExtraFromPropagationFactory.

@Test
public void nextSpan_getsExtraFromPropagationFactory() {
    propagationFactory = baggageFactory;
    Span parent = tracer.nextSpan();
    BAGGAGE_FIELD.updateValue(parent.context(), "napkin");
    TraceContext nextSpan;
    try (SpanInScope scope = tracer.withSpanInScope(parent)) {
        nextSpan = tracer.nextSpan().context();
    }
    assertThat(BAGGAGE_FIELD.getValue(nextSpan)).isEqualTo("napkin");
}
Also used : SpanInScope(brave.Tracer.SpanInScope) StrictCurrentTraceContext(brave.propagation.StrictCurrentTraceContext) CurrentTraceContext(brave.propagation.CurrentTraceContext) TraceContext(brave.propagation.TraceContext) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 9 with SpanInScope

use of brave.Tracer.SpanInScope in project brave by openzipkin.

the class TracerTest method nextSpan_extractedExtra_appendsToChildOfCurrent.

@Test
public void nextSpan_extractedExtra_appendsToChildOfCurrent() {
    // current parent already has extra stuff
    Span parent = tracer.nextSpan(TraceContextOrSamplingFlags.newBuilder(EMPTY).addExtra(1L).build());
    TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.newBuilder(EMPTY).addExtra(1F).build();
    try (SpanInScope ws = tracer.withSpanInScope(parent)) {
        assertThat(tracer.nextSpan(extracted).context().extra()).containsExactlyInAnyOrder(1L, 1F);
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) Test(org.junit.Test)

Example 10 with SpanInScope

use of brave.Tracer.SpanInScope in project brave by openzipkin.

the class TracerTest method nextSpan_extractedNothing_makesChildOfCurrent.

@Test
public void nextSpan_extractedNothing_makesChildOfCurrent() {
    Span parent = tracer.newTrace();
    try (SpanInScope ws = tracer.withSpanInScope(parent)) {
        Span nextSpan = tracer.nextSpan(TraceContextOrSamplingFlags.create(EMPTY));
        assertThat(nextSpan.context().parentId()).isEqualTo(parent.context().spanId());
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Aggregations

SpanInScope (brave.Tracer.SpanInScope)55 Span (brave.Span)34 Test (org.junit.Test)23 MutableSpan (brave.handler.MutableSpan)13 MockResponse (okhttp3.mockwebserver.MockResponse)4 Tracer (brave.Tracer)3 TopicPublisher (javax.jms.TopicPublisher)3 TraceContextOrSamplingFlags (brave.propagation.TraceContextOrSamplingFlags)2 RequestContext (com.netflix.zuul.context.RequestContext)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 Destination (javax.jms.Destination)2 Response (javax.ws.rs.core.Response)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 HasSpan.hasSpan (org.apache.cxf.systest.jaxrs.tracing.brave.HasSpan.hasSpan)2 Request (org.apache.cxf.tracing.brave.internal.HttpAdapterFactory.Request)2 BraveClientProvider (org.apache.cxf.tracing.brave.jaxrs.BraveClientProvider)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 Tracing (brave.Tracing)1