use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class TracerTest method getCurrentSpan_WithSpan.
@Test
public void getCurrentSpan_WithSpan() {
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
NonThrowingCloseable ws = tracer.withSpan(span);
try {
assertThat(tracer.getCurrentSpan()).isSameAs(span);
} finally {
ws.close();
}
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
}
use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class ContextUtilsTest method testWithStatsContextUsingWrap.
@Test
public void testWithStatsContextUsingWrap() {
Runnable runnable;
NonThrowingCloseable scopedStatsCtx = ContextUtils.withStatsContext(statsContext);
try {
assertThat(ContextUtils.getCurrentStatsContext()).isSameAs(statsContext);
runnable = Context.current().wrap(new Runnable() {
@Override
public void run() {
assertThat(ContextUtils.getCurrentStatsContext()).isSameAs(statsContext);
}
});
} finally {
scopedStatsCtx.close();
}
assertThat(ContextUtils.getCurrentStatsContext()).isNull();
// When we run the runnable we will have the statsContext in the current Context.
runnable.run();
}
use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class ContextUtilsTest method propagationViaRunnable.
@Test
public void propagationViaRunnable() {
Runnable runnable = null;
NonThrowingCloseable ws = ContextUtils.withSpan(span);
try {
assertThat(ContextUtils.getCurrentSpan()).isSameAs(span);
runnable = Context.current().wrap(new Runnable() {
@Override
public void run() {
assertThat(ContextUtils.getCurrentSpan()).isSameAs(span);
}
});
} finally {
ws.close();
}
assertThat(ContextUtils.getCurrentSpan()).isNotSameAs(span);
// When we run the runnable we will have the span in the current Context.
runnable.run();
}
use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class ContextUtilsTest method withSpan.
@Test
public void withSpan() {
assertThat(ContextUtils.getCurrentSpan()).isNull();
NonThrowingCloseable ws = ContextUtils.withSpan(span);
try {
assertThat(ContextUtils.getCurrentSpan()).isSameAs(span);
} finally {
ws.close();
}
assertThat(ContextUtils.getCurrentSpan()).isNull();
;
}
use of com.google.instrumentation.common.NonThrowingCloseable in project instrumentation-java by census-instrumentation.
the class ScopedSpanHandleTest method initAttachesSpan_CloseDetachesAndEndsSpan.
@Test
public void initAttachesSpan_CloseDetachesAndEndsSpan() {
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
NonThrowingCloseable ss = new ScopedSpanHandle(span);
try {
assertThat(tracer.getCurrentSpan()).isSameAs(span);
} finally {
ss.close();
}
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
verify(span).end(same(EndSpanOptions.DEFAULT));
}
Aggregations