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