Search in sources :

Example 81 with MutableSpan

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

the class BaseITTracingClientInterceptor method setsErrorTag_onCanceledFuture.

@Test
public void setsErrorTag_onCanceledFuture() {
    server.enqueueDelay(TimeUnit.SECONDS.toMillis(1));
    ListenableFuture<HelloReply> resp = GreeterGrpc.newFutureStub(client).sayHello(HELLO_REQUEST);
    assumeTrue("lost race on cancel", resp.cancel(true));
    MutableSpan span = testSpanHandler.takeRemoteSpanWithErrorTag(CLIENT, "CANCELLED");
    assertThat(span.tags().get("grpc.status_code")).isEqualTo("CANCELLED");
}
Also used : MutableSpan(brave.handler.MutableSpan) HelloReply(io.grpc.examples.helloworld.HelloReply) Test(org.junit.Test)

Example 82 with MutableSpan

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

the class ITHttpServer method notFound.

/**
 * If http route is supported, then the span name should include it
 */
@Test
public void notFound() throws IOException {
    // we can't use get("/foo/bark") because get(path) throws assumption fail on 404
    assertThat(call("GET", "/foo/bark").code()).isEqualTo(404);
    MutableSpan span = testSpanHandler.takeRemoteSpanWithErrorTag(SERVER, "404");
    // verify normal tags
    assertThat(span.tags()).hasSize(4).containsEntry("http.method", "GET").containsEntry("http.path", "/foo/bark").containsEntry("http.status_code", "404");
    // Either the span name is the method, or it is a route expression
    String name = span.name();
    if (name != null && !"GET".equals(name)) {
        assertThat(name).isEqualTo("GET not_found");
    }
}
Also used : MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 83 with MutableSpan

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

the class ITHttpServer method createsChildSpan.

/**
 * This ensures thread-state is propagated from trace interceptors to user code. The endpoint
 * "/child" is expected to create an in-process span. When this works, it should be a child of the
 * "current span", in this case the span representing an incoming server request. When thread
 * state isn't managed properly, the child span will appear as a new trace.
 */
@Test
public void createsChildSpan() throws IOException {
    get("/child");
    MutableSpan child = testSpanHandler.takeLocalSpan();
    MutableSpan server = testSpanHandler.takeRemoteSpan(SERVER);
    assertChildOf(child, server);
    // sanity check
    assertThat(child.name()).isEqualTo("child");
}
Also used : MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 84 with MutableSpan

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

the class ITHttpServer method createsChildWhenJoinDisabled.

@Test
public void createsChildWhenJoinDisabled() throws IOException {
    tracing = tracingBuilder(NEVER_SAMPLE).supportsJoin(false).build();
    httpTracing = HttpTracing.create(tracing);
    init();
    String path = "/foo";
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    get(new Request.Builder().url(url(path)).header("b3", B3SingleFormat.writeB3SingleFormat(parent)).build());
    MutableSpan span = testSpanHandler.takeRemoteSpan(SERVER);
    assertChildOf(span, parent);
    assertThat(span.id()).isNotEqualTo(parent.spanIdString());
}
Also used : MutableSpan(brave.handler.MutableSpan) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 85 with MutableSpan

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

the class ITHttpServer method spanHandlerSeesError.

void spanHandlerSeesError(String path) throws IOException {
    ConcurrentLinkedDeque<Throwable> caughtThrowables = new ConcurrentLinkedDeque<>();
    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());
    init();
    // If this passes, a span was reported with an error
    httpStatusCodeTagMatchesResponse_onUncaughtException(path, ".*not ready");
    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)

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