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");
}
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();
}
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);
}
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
"//");
}
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 /");
}
}
Aggregations