use of io.opencensus.common.Scope in project instrumentation-java by census-instrumentation.
the class ScopedTagMapTest method setCurrentTagsWithBuilder.
@Test
public void setCurrentTagsWithBuilder() {
assertThat(tagContextToList(tagger.getCurrentTagContext())).isEmpty();
Scope scope = tagger.emptyBuilder().put(KEY_1, VALUE_1).buildScoped();
try {
assertThat(tagContextToList(tagger.getCurrentTagContext())).containsExactly(Tag.create(KEY_1, VALUE_1));
} finally {
scope.close();
}
assertThat(tagContextToList(tagger.getCurrentTagContext())).isEmpty();
}
use of io.opencensus.common.Scope in project instrumentation-java by census-instrumentation.
the class CurrentTagMapUtilsTest method testWithTagMapUsingWrap.
@Test
public void testWithTagMapUsingWrap() {
Runnable runnable;
Scope scopedTags = CurrentTagMapUtils.withTagMap(tagContext);
try {
assertThat(CurrentTagMapUtils.getCurrentTagMap()).isSameInstanceAs(tagContext);
runnable = Context.current().wrap(new Runnable() {
@Override
public void run() {
assertThat(CurrentTagMapUtils.getCurrentTagMap()).isSameInstanceAs(tagContext);
}
});
} finally {
scopedTags.close();
}
assertThat(tagContextToList(CurrentTagMapUtils.getCurrentTagMap())).isEmpty();
// When we run the runnable we will have the TagContext in the current Context.
runnable.run();
}
use of io.opencensus.common.Scope in project beam by apache.
the class BeamFnMapTaskExecutor method execute.
@Override
public void execute() throws Exception {
Tracer tracer = Tracing.getTracer();
SpanBuilder builder = tracer.spanBuilder("MapTaskExecutor.Span").setRecordEvents(true);
// Start the progress tracker before execution (which blocks until execution is finished).
try (Scope unused = builder.startScopedSpan();
AutoCloseable unused2 = progressTrackerCloseable(progressTracker)) {
tracer.getCurrentSpan().addAnnotation("About to execute");
super.execute();
tracer.getCurrentSpan().addAnnotation("Done with execute");
}
}
Aggregations