use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method withSpanInScope.
@Test
public void withSpanInScope() {
Span current = tracer.newTrace();
try (SpanInScope ws = tracer.withSpanInScope(current)) {
assertThat(tracer.currentSpan()).isEqualTo(current);
assertThat(tracer.currentSpanCustomizer()).isNotEqualTo(current).isNotEqualTo(NoopSpanCustomizer.INSTANCE);
}
// context was cleared
assertThat(tracer.currentSpan()).isNull();
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method simulateInProcessPropagation.
/**
* Must be a separate method from the test method to allow for local variables to be garbage
* collected
*/
private static void simulateInProcessPropagation(Tracer tracer1, Tracer tracer2) {
Span span1 = tracer1.newTrace();
span1.start();
// Pretend we're on child thread
Tracer.SpanInScope spanInScope = tracer2.withSpanInScope(span1);
// Back on original thread
span1.finish();
// Pretend we're on child thread
Span span2 = tracer2.currentSpan();
spanInScope.close();
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class NoopSpanTest method equals_lazySpan_notSameContext.
@Test
public void equals_lazySpan_notSameContext() {
Span current;
try (SpanInScope ws = tracer.withSpanInScope(tracer.newTrace())) {
current = tracer.currentSpan();
}
assertThat(span).isNotEqualTo(current);
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class NoopSpanTest method equals_lazySpan_sameContext.
@Test
public void equals_lazySpan_sameContext() {
Span current;
try (SpanInScope ws = tracer.withSpanInScope(span)) {
current = tracer.currentSpan();
}
assertThat(span).isEqualTo(current);
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracingInterceptor method intercept.
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
RequestWrapper request = new RequestWrapper(chain.request());
Span span = handler.handleSend(request);
Response response = null;
Throwable error = null;
try (SpanInScope ws = tracer.withSpanInScope(span)) {
return response = chain.proceed(request.build());
} catch (Throwable e) {
error = e;
throw e;
} finally {
handler.handleReceive(new ResponseWrapper(response, error), span);
}
}
Aggregations