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