use of brave.handler.SpanHandler in project brave by openzipkin.
the class TracingTest method basicUsage.
@Test
public void basicUsage() {
try (Tracing tracing = Tracing.newBuilder().addSpanHandler(new SpanHandler() {
}).build()) {
ScopedSpan parent = tracing.tracer().startScopedSpan("parent");
tracing.tracer().newChild(parent.context()).finish();
parent.finish();
}
}
use of brave.handler.SpanHandler 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.SpanHandler in project brave by openzipkin.
the class TracerTest method tracerThatPartitionsNamesOnlocalRootId.
Map<Long, List<String>> tracerThatPartitionsNamesOnlocalRootId() {
Map<Long, List<String>> reportedNames = new LinkedHashMap<>();
tracer = Tracing.newBuilder().addSpanHandler(new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
assertThat(context.localRootId()).isNotZero();
reportedNames.computeIfAbsent(context.localRootId(), k -> new ArrayList<>()).add(span.name());
// retain
return true;
}
}).alwaysSampleLocal().build().tracer();
return reportedNames;
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class TracingTest method spanHandler_dataChangesVisibleToZipkin.
@Test
public void spanHandler_dataChangesVisibleToZipkin() {
String serviceNameOverride = "favistar";
SpanHandler spanHandler = new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
span.localServiceName(serviceNameOverride);
return true;
}
};
List<zipkin2.Span> zipkinSpans = new ArrayList<>();
try (Tracing tracing = Tracing.newBuilder().spanReporter(zipkinSpans::add).addSpanHandler(spanHandler).build()) {
tracing.tracer().newTrace().start().finish();
}
assertThat(zipkinSpans.get(0).localServiceName()).isEqualTo(serviceNameOverride);
}
use of brave.handler.SpanHandler in project brave by openzipkin.
the class TracingTest method spanHandler_multiple.
@Test
public void spanHandler_multiple() {
SpanHandler one = new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
return true;
}
};
SpanHandler two = new SpanHandler() {
@Override
public boolean end(TraceContext context, MutableSpan span, Cause cause) {
return true;
}
};
try (Tracing tracing = Tracing.newBuilder().addSpanHandler(one).addSpanHandler(two).build()) {
assertThat((Object) tracing.tracer().pendingSpans).extracting("spanHandler.delegate.handlers").asInstanceOf(InstanceOfAssertFactories.array(SpanHandler[].class)).containsExactly(one, two);
}
}
Aggregations