Search in sources :

Example 41 with SpanInScope

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

the class CurrentSpanCustomizerTest method tag.

@Test
public void tag() {
    span.start();
    try (SpanInScope ws = tracing.tracer().withSpanInScope(span)) {
        spanCustomizer.tag("foo", "bar");
    }
    span.flush();
    assertThat(spans).flatExtracting(s -> s.tags().entrySet()).containsExactly(entry("foo", "bar"));
}
Also used : TestSpanHandler(brave.test.TestSpanHandler) MutableSpan(brave.handler.MutableSpan) Map(java.util.Map) After(org.junit.After) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Assertions.entry(org.assertj.core.api.Assertions.entry) SpanInScope(brave.Tracer.SpanInScope) SpanInScope(brave.Tracer.SpanInScope) Test(org.junit.Test)

Example 42 with SpanInScope

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

the class CurrentSpanCustomizerTest method name.

@Test
public void name() {
    span.start();
    try (SpanInScope ws = tracing.tracer().withSpanInScope(span)) {
        spanCustomizer.name("newname");
    }
    span.flush();
    assertThat(spans).extracting(MutableSpan::name).containsExactly("newname");
}
Also used : SpanInScope(brave.Tracer.SpanInScope) Test(org.junit.Test)

Example 43 with SpanInScope

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

the class CurrentSpanCustomizerTest method annotate.

@Test
public void annotate() {
    span.start();
    try (SpanInScope ws = tracing.tracer().withSpanInScope(span)) {
        spanCustomizer.annotate("foo");
    }
    span.flush();
    assertThat(spans.get(0).annotations()).extracting(Map.Entry::getValue).containsExactly("foo");
}
Also used : SpanInScope(brave.Tracer.SpanInScope) Map(java.util.Map) Test(org.junit.Test)

Example 44 with SpanInScope

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

the class TracingProtocolExec method execute.

@Override
public CloseableHttpResponse execute(HttpRoute route, org.apache.http.client.methods.HttpRequestWrapper req, HttpClientContext context, HttpExecutionAware execAware) throws IOException, HttpException {
    HttpRequestWrapper request = new HttpRequestWrapper(req, context.getTargetHost());
    Span span = tracer.nextSpan(httpSampler, request);
    context.setAttribute(Span.class.getName(), span);
    CloseableHttpResponse response = null;
    Throwable error = null;
    try (SpanInScope ws = tracer.withSpanInScope(span)) {
        return response = protocolExec.execute(route, req, context, execAware);
    } catch (Throwable e) {
        error = e;
        throw e;
    } finally {
        handler.handleReceive(new HttpResponseWrapper(response, context, error), span);
    }
}
Also used : SpanInScope(brave.Tracer.SpanInScope) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Span(brave.Span)

Example 45 with SpanInScope

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

the class TracingDispatcher method dispatch.

@Override
public MockResponse dispatch(RecordedRequest req) throws InterruptedException {
    RecordedRequestWrapper request = new RecordedRequestWrapper(req);
    Span span = handler.handleReceive(request);
    MockResponse response = null;
    Throwable error = null;
    try (SpanInScope ws = tracer.withSpanInScope(span)) {
        return response = delegate.dispatch(req);
    } catch (Throwable e) {
        error = e;
        throw e;
    } finally {
        handler.handleSend(new MockResponseWrapper(request, response, error), span);
    }
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) SpanInScope(brave.Tracer.SpanInScope) Span(brave.Span)

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