use of brave.Tracer.SpanInScope in project java-chassis by ServiceComb.
the class ZipkinTracingFilter method onFilter.
@SuppressWarnings({ "try", "unused" })
@Override
public CompletableFuture<Response> onFilter(Invocation invocation, FilterNode nextNode) {
ZipkinTracingDelegate tracing = collectTracing(invocation);
Span span = tracing.createSpan(invocation);
try (SpanInScope scope = tracing.tracer().tracer().withSpanInScope(span)) {
return nextNode.onFilter(invocation).whenComplete((response, exception) -> tracing.onResponse(span, response, Exceptions.unwrap(exception)));
}
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracingClientFilter method filter.
@Override
public void filter(ClientRequestContext request, ClientResponseContext response) {
Span span = tracer.currentSpan();
if (span == null)
return;
((SpanInScope) request.getProperty(SpanInScope.class.getName())).close();
handler.handleReceive(new ClientResponseContextWrapper(request, response), span);
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method nextSpan_getsExtraFromPropagationFactory.
@Test
public void nextSpan_getsExtraFromPropagationFactory() {
propagationFactory = baggageFactory;
Span parent = tracer.nextSpan();
BAGGAGE_FIELD.updateValue(parent.context(), "napkin");
TraceContext nextSpan;
try (SpanInScope scope = tracer.withSpanInScope(parent)) {
nextSpan = tracer.nextSpan().context();
}
assertThat(BAGGAGE_FIELD.getValue(nextSpan)).isEqualTo("napkin");
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method nextSpan_extractedExtra_appendsToChildOfCurrent.
@Test
public void nextSpan_extractedExtra_appendsToChildOfCurrent() {
// current parent already has extra stuff
Span parent = tracer.nextSpan(TraceContextOrSamplingFlags.newBuilder(EMPTY).addExtra(1L).build());
TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.newBuilder(EMPTY).addExtra(1F).build();
try (SpanInScope ws = tracer.withSpanInScope(parent)) {
assertThat(tracer.nextSpan(extracted).context().extra()).containsExactlyInAnyOrder(1L, 1F);
}
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class TracerTest method nextSpan_extractedNothing_makesChildOfCurrent.
@Test
public void nextSpan_extractedNothing_makesChildOfCurrent() {
Span parent = tracer.newTrace();
try (SpanInScope ws = tracer.withSpanInScope(parent)) {
Span nextSpan = tracer.nextSpan(TraceContextOrSamplingFlags.create(EMPTY));
assertThat(nextSpan.context().parentId()).isEqualTo(parent.context().spanId());
}
}
Aggregations