use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class SpanBuilderTest method startScopedSpanRootWithOptions.
@Test
public void startScopedSpanRootWithOptions() {
StartSpanOptions startSpanOptions = new StartSpanOptions();
startSpanOptions.setSampler(Samplers.neverSample());
when(spanFactory.startSpan(isNull(Span.class), same(SPAN_NAME), eq(startSpanOptions))).thenReturn(span);
NonThrowingCloseable ss = spanBuilder.becomeRoot().setSampler(Samplers.neverSample()).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 ContextUtilsTest method testWithStatsContext.
@Test
public void testWithStatsContext() {
assertThat(ContextUtils.getCurrentStatsContext()).isNull();
NonThrowingCloseable scopedStatsCtx = ContextUtils.withStatsContext(statsContext);
try {
assertThat(ContextUtils.getCurrentStatsContext()).isSameAs(statsContext);
} finally {
scopedStatsCtx.close();
}
assertThat(ContextUtils.getCurrentStatsContext()).isNull();
}
Aggregations