use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class StatsContextFactoryTest method testWithStatsContext.
@Test
public void testWithStatsContext() {
assertThat(factory.getCurrentStatsContext()).isEqualTo(defaultCtx);
NonThrowingCloseable scopedStatsCtx = factory.withStatsContext(statsContext);
try {
assertThat(factory.getCurrentStatsContext()).isEqualTo(statsContext);
} finally {
scopedStatsCtx.close();
}
assertThat(factory.getCurrentStatsContext()).isEqualTo(defaultCtx);
}
use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class BasicContextTracing method main.
/** Main method. */
public static void main(String[] args) {
Span span = tracer.spanBuilder("MyRootSpan").becomeRoot().startSpan();
try (NonThrowingCloseable ws = tracer.withSpan(span)) {
doWork();
}
span.end();
}
use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class MultiSpansContextTracing method main.
/** Main method. */
public static void main(String[] args) {
TraceExporter.LoggingServiceHandler.registerService(Tracing.getTraceExporter());
Span span = tracer.spanBuilder("MyRootSpan").becomeRoot().startSpan();
try (NonThrowingCloseable ws = tracer.withSpan(span)) {
doWork();
}
span.end();
}
use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class TracerTest method startScopedSpanRoot.
@Test
public void startScopedSpanRoot() {
Tracer mockTracer = new MockTracer(spanFactory);
when(spanFactory.startSpan(isNull(Span.class), same(SPAN_NAME), eq(new StartSpanOptions()))).thenReturn(span);
NonThrowingCloseable ss = mockTracer.spanBuilder(SPAN_NAME).becomeRoot().startScopedSpan();
try {
assertThat(tracer.getCurrentSpan()).isSameAs(span);
} finally {
ss.close();
}
verify(span).end(same(EndSpanOptions.DEFAULT));
}
use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class TracerTest method propagationViaRunnable.
@Test
public void propagationViaRunnable() {
Runnable runnable = null;
NonThrowingCloseable ws = tracer.withSpan(span);
try {
assertThat(tracer.getCurrentSpan()).isSameAs(span);
runnable = Context.current().wrap(new Runnable() {
@Override
public void run() {
assertThat(tracer.getCurrentSpan()).isSameAs(span);
}
});
} finally {
ws.close();
}
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
// When we run the runnable we will have the span in the current Context.
runnable.run();
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
}
Aggregations