use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class ITHttpClient method propagatesExtra_unsampledTrace.
@Test
public void propagatesExtra_unsampledTrace() throws Exception {
Tracer tracer = httpTracing.tracing().tracer();
server.enqueue(new MockResponse());
brave.Span parent = tracer.newTrace(SamplingFlags.NOT_SAMPLED).name("test").start();
try (SpanInScope ws = tracer.withSpanInScope(parent)) {
ExtraFieldPropagation.set(parent.context(), EXTRA_KEY, "joey");
get(client, "/foo");
} finally {
parent.finish();
}
assertThat(server.takeRequest().getHeader(EXTRA_KEY)).isEqualTo("joey");
}
use of brave.Tracer.SpanInScope in project brave by openzipkin.
the class BraveSpanBuilder method startActive.
@Override
public Scope startActive(boolean finishOnClose) {
BraveSpan span = startManual();
SpanInScope delegate = tracer.withSpanInScope(span.delegate);
return new Scope() {
@Override
public void close() {
if (finishOnClose)
span.finish();
delegate.close();
}
@Override
public io.opentracing.Span span() {
return span;
}
};
}
use of brave.Tracer.SpanInScope in project incubator-servicecomb-java-chassis by apache.
the class ZipkinTracingHandler method handle.
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
Span span = tracingDelegate.createSpan(invocation);
try (SpanInScope scope = tracer.tracer().withSpanInScope(span)) {
LOGGER.debug("{}: Generated tracing span for {}", tracingDelegate.name(), invocation.getOperationName());
invocation.next(onResponse(invocation, asyncResp, span));
} catch (Exception e) {
LOGGER.debug("{}: Failed invocation on {}", tracingDelegate.name(), invocation.getOperationName(), e);
tracingDelegate.onResponse(span, null, e);
throw e;
}
}
use of brave.Tracer.SpanInScope in project spring-cloud-sleuth by spring-cloud.
the class TraceRunnable method run.
@Override
public void run() {
Throwable error = null;
try (SpanInScope ws = this.tracer.withSpanInScope(this.span.start())) {
this.delegate.run();
} catch (RuntimeException | Error e) {
error = e;
throw e;
} finally {
this.errorParser.parseErrorTags(this.span.customizer(), error);
this.span.finish();
}
}
use of brave.Tracer.SpanInScope in project tutorials by eugenp.
the class SleuthService method doSomeWorkNewSpan.
public void doSomeWorkNewSpan() throws InterruptedException {
logger.info("I'm in the original span");
Span newSpan = tracer.newTrace().name("newSpan").start();
try (SpanInScope ws = tracer.withSpanInScope(newSpan.start())) {
Thread.sleep(1000L);
logger.info("I'm in the new span doing some cool work that needs its own span");
} finally {
newSpan.finish();
}
logger.info("I'm in the original span");
}
Aggregations