Search in sources :

Example 6 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class ITHttpClient method supportsPortableCustomization.

@Test
public void supportsPortableCustomization() throws IOException {
    String uri = "/foo/bar?z=2&yAA=1";
    closeClient(client);
    httpTracing = httpTracing.toBuilder().clientRequestParser((request, context, span) -> {
        span.name(request.method().toLowerCase() + " " + request.path());
        // just the path is tagged by default
        HttpTags.URL.tag(request, span);
        span.tag("request_customizer.is_span", (span instanceof brave.Span) + "");
    }).clientResponseParser((response, context, span) -> {
        HttpResponseParser.DEFAULT.parse(response, context, span);
        span.tag("response_customizer.is_span", (span instanceof brave.Span) + "");
    }).build().clientOf("remote-service");
    client = newClient(server.getPort());
    server.enqueue(new MockResponse());
    get(client, uri);
    MutableSpan span = testSpanHandler.takeRemoteSpan(CLIENT);
    assertThat(span.name()).isEqualTo("get /foo/bar");
    assertThat(span.remoteServiceName()).isEqualTo("remote-service");
    assertThat(span.tags()).containsEntry("http.url", url(uri)).containsEntry("request_customizer.is_span", "false").containsEntry("response_customizer.is_span", "false");
}
Also used : Arrays(java.util.Arrays) SpanCustomizer(brave.SpanCustomizer) HttpRuleSampler(brave.http.HttpRuleSampler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Callable(java.util.concurrent.Callable) Extractor(brave.propagation.TraceContext.Extractor) Level(java.util.logging.Level) Sampler(brave.sampler.Sampler) ITRemote(brave.test.ITRemote) After(org.junit.After) MockWebServer(okhttp3.mockwebserver.MockWebServer) HttpResponseParser(brave.http.HttpResponseParser) SamplerFunction(brave.sampler.SamplerFunction) HttpRequest(brave.http.HttpRequest) Before(org.junit.Before) HttpAdapter(brave.http.HttpAdapter) HttpTracing(brave.http.HttpTracing) CLIENT(brave.Span.Kind.CLIENT) TraceContextOrSamplingFlags(brave.propagation.TraceContextOrSamplingFlags) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) IOException(java.io.IOException) Test(org.junit.Test) Logger(java.util.logging.Logger) TraceContext(brave.propagation.TraceContext) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) SocketPolicy(okhttp3.mockwebserver.SocketPolicy) Clock(brave.Clock) TimeUnit(java.util.concurrent.TimeUnit) HttpTags(brave.http.HttpTags) HttpRequestMatchers.pathStartsWith(brave.http.HttpRequestMatchers.pathStartsWith) Rule(org.junit.Rule) MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) SpanHandler(brave.handler.SpanHandler) SamplingFlags(brave.propagation.SamplingFlags) MockResponse(okhttp3.mockwebserver.MockResponse) HttpClientParser(brave.http.HttpClientParser) MockResponse(okhttp3.mockwebserver.MockResponse) MutableSpan(brave.handler.MutableSpan) MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 7 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class ITHttpClient method spanHandlerSeesError.

/**
 * This ensures custom span handlers can see the actual exception thrown, not just the "error"
 * tag value.
 */
void spanHandlerSeesError(Callable<Void> get) throws IOException {
    ConcurrentLinkedDeque<Throwable> caughtThrowables = new ConcurrentLinkedDeque<>();
    closeClient(client);
    httpTracing = HttpTracing.create(tracingBuilder(Sampler.ALWAYS_SAMPLE).clearSpanHandlers().addSpanHandler(new SpanHandler() {

        @Override
        public boolean end(TraceContext context, MutableSpan span, Cause cause) {
            Throwable error = span.error();
            if (error != null) {
                caughtThrowables.add(error);
            } else {
                caughtThrowables.add(new RuntimeException("Unexpected additional call to end"));
            }
            return true;
        }
    }).addSpanHandler(testSpanHandler).build());
    client = newClient(server.getPort());
    // If this passes, a span was reported with an error
    checkReportsSpanOnTransportException(get);
    assertThat(caughtThrowables).withFailMessage("Span finished with error, but caughtThrowables empty").isNotEmpty();
    if (caughtThrowables.size() > 1) {
        for (Throwable throwable : caughtThrowables) {
            Logger.getAnonymousLogger().log(Level.SEVERE, "multiple calls to finish", throwable);
        }
        assertThat(caughtThrowables).hasSize(1);
    }
}
Also used : MutableSpan(brave.handler.MutableSpan) TraceContext(brave.propagation.TraceContext) SpanHandler(brave.handler.SpanHandler) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque)

Example 8 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class ITHttpClient method clientTimestampAndDurationEnclosedByParent.

/**
 * This prevents confusion as a blocking client should end before, the start of the next span.
 */
@Test
public void clientTimestampAndDurationEnclosedByParent() throws IOException {
    server.enqueue(new MockResponse());
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    Clock clock = tracing.clock(parent);
    long start = clock.currentTimeMicroseconds();
    try (Scope scope = currentTraceContext.newScope(parent)) {
        get(client, "/foo");
    }
    long finish = clock.currentTimeMicroseconds();
    MutableSpan clientSpan = testSpanHandler.takeRemoteSpan(CLIENT);
    assertChildOf(clientSpan, parent);
    assertSpanInInterval(clientSpan, start, finish);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) TraceContext(brave.propagation.TraceContext) Clock(brave.Clock) Test(org.junit.Test)

Example 9 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class BaseITTracingClientInterceptor method clientTimestampAndDurationEnclosedByParent.

/**
 * This prevents confusion as a blocking client should end before, the start of the next span.
 */
@Test
public void clientTimestampAndDurationEnclosedByParent() {
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    Clock clock = tracing.clock(parent);
    long start = clock.currentTimeMicroseconds();
    try (Scope scope = currentTraceContext.newScope(parent)) {
        GreeterGrpc.newBlockingStub(client).sayHello(HELLO_REQUEST);
    }
    long finish = clock.currentTimeMicroseconds();
    MutableSpan clientSpan = testSpanHandler.takeRemoteSpan(CLIENT);
    assertChildOf(clientSpan, parent);
    assertSpanInInterval(clientSpan, start, finish);
}
Also used : MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) TraceContext(brave.propagation.TraceContext) Clock(brave.Clock) Test(org.junit.Test)

Example 10 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class BaseITTracingClientInterceptor method setsErrorTag_onUnimplemented.

@Test
public void setsErrorTag_onUnimplemented() {
    assertThatThrownBy(() -> GraterGrpc.newBlockingStub(client).seyHallo(HELLO_REQUEST)).isInstanceOf(StatusRuntimeException.class);
    MutableSpan span = testSpanHandler.takeRemoteSpanWithErrorTag(CLIENT, "UNIMPLEMENTED");
    assertThat(span.tags().get("grpc.status_code")).isEqualTo("UNIMPLEMENTED");
}
Also used : MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Aggregations

MutableSpan (brave.handler.MutableSpan)141 Test (org.junit.Test)107 TraceContext (brave.propagation.TraceContext)36 KafkaStreams (org.apache.kafka.streams.KafkaStreams)28 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)28 Topology (org.apache.kafka.streams.Topology)28 Scope (brave.propagation.CurrentTraceContext.Scope)14 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)12 KeyValue (org.apache.kafka.streams.KeyValue)9 ArrayList (java.util.ArrayList)8 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)8 MessagingTracing (brave.messaging.MessagingTracing)7 FileNotFoundException (java.io.FileNotFoundException)7 Arrays (java.util.Arrays)7 List (java.util.List)7 CONSUMER (brave.Span.Kind.CONSUMER)6 PRODUCER (brave.Span.Kind.PRODUCER)6 SpanHandler (brave.handler.SpanHandler)6 KafkaTracing (brave.kafka.clients.KafkaTracing)6 KAFKA_STREAMS_FILTERED_TAG (brave.kafka.streams.KafkaStreamsTags.KAFKA_STREAMS_FILTERED_TAG)6