Search in sources :

Example 11 with MutableSpan

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

the class BaseITTracingServerInterceptor method setsErrorOnException.

/**
 * {@link GreeterImpl} is trained to throw an {@link IllegalArgumentException} on error
 */
@Test
public void setsErrorOnException() {
    assertThatThrownBy(() -> GreeterGrpc.newBlockingStub(client).sayHello(HelloRequest.newBuilder().setName("bad").build()));
    MutableSpan span = testSpanHandler.takeRemoteSpanWithErrorMessage(Span.Kind.SERVER, "bad");
    assertThat(span.tags()).containsEntry("grpc.status_code", "UNKNOWN");
}
Also used : MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 12 with MutableSpan

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

the class BaseITTracingServerInterceptor method setsErrorOnRuntimeException.

@Test
public void setsErrorOnRuntimeException() {
    assertThatThrownBy(() -> GreeterGrpc.newBlockingStub(client).sayHello(HelloRequest.newBuilder().setName("testerror").build())).isInstanceOf(StatusRuntimeException.class);
    MutableSpan span = testSpanHandler.takeRemoteSpanWithErrorMessage(Span.Kind.SERVER, "testerror");
    assertThat(span.tags().get("grpc.status_code")).isNull();
}
Also used : MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test)

Example 13 with MutableSpan

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

the class ITHttpServer method readsBaggage_existingTrace.

@Test
public void readsBaggage_existingTrace() throws IOException {
    String traceId = "463ac35c9f6413ad";
    readsBaggage(new Request.Builder().header("X-B3-TraceId", traceId).header("X-B3-SpanId", traceId));
    MutableSpan span = testSpanHandler.takeRemoteSpan(SERVER);
    assertThat(span.traceId()).isEqualTo(traceId);
    assertThat(span.id()).isEqualTo(traceId);
}
Also used : MutableSpan(brave.handler.MutableSpan) HttpRequest(brave.http.HttpRequest) Request(okhttp3.Request) Test(org.junit.Test)

Example 14 with MutableSpan

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

the class ITHttpServer method routeBasedRequestNameIncludesPathPrefix.

private void routeBasedRequestNameIncludesPathPrefix(String prefix) throws IOException {
    Response request1 = get(prefix + "/1?foo");
    Response request2 = get(prefix + "/2?bar");
    // get() doesn't check the response, check to make sure the server didn't 500
    assertThat(request1.isSuccessful()).isTrue();
    assertThat(request2.isSuccessful()).isTrue();
    // Reading the route parameter from the response ensures the test endpoint is correct
    assertThat(request1.body().string()).isEqualTo("1");
    assertThat(request2.body().string()).isEqualTo("2");
    MutableSpan span1 = testSpanHandler.takeRemoteSpan(SERVER);
    MutableSpan span2 = testSpanHandler.takeRemoteSpan(SERVER);
    // verify that the path and url reflect the initial request (not a route expression)
    assertThat(span1.tags()).containsEntry("http.method", "GET").containsEntry("http.path", prefix + "/1").containsEntry("http.url", url(prefix + "/1?foo"));
    assertThat(span2.tags()).containsEntry("http.method", "GET").containsEntry("http.path", prefix + "/2").containsEntry("http.url", url(prefix + "/2?bar"));
    // We don't know the exact format of the http route as it is framework specific
    // However, we know that it should match both requests and include the common part of the path
    Set<String> routeBasedNames = new LinkedHashSet<>(Arrays.asList(span1.name(), span2.name()));
    assertThat(routeBasedNames).hasSize(1);
    assertThat(routeBasedNames.iterator().next()).startsWith("GET " + prefix).doesNotEndWith(// no trailing slashes
    "/").doesNotContain(// no duplicate slashes
    "//");
}
Also used : Response(okhttp3.Response) LinkedHashSet(java.util.LinkedHashSet) MutableSpan(brave.handler.MutableSpan)

Example 15 with MutableSpan

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

the class ITHttpServer method options.

/**
 * This tests both that a root path ends up as "/" (slash) not "" (empty), as well that less
 * typical OPTIONS methods can be traced.
 */
@Test
public void options() throws IOException {
    assertThat(call("OPTIONS", "/").isSuccessful()).isTrue();
    MutableSpan span = testSpanHandler.takeRemoteSpan(SERVER);
    // verify normal tags
    assertThat(span.tags()).containsEntry("http.method", "OPTIONS").containsEntry("http.path", "/");
    // Either the span name is the method, or it is a route expression
    String name = span.name();
    if (name != null && !"OPTIONS".equals(name)) {
        assertThat(name).isEqualTo("OPTIONS /");
    }
}
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