use of io.opentracing.Scope in project opentracing-java by opentracing.
the class MockTracerTest method testDefaultConstructor.
@Test
public void testDefaultConstructor() {
MockTracer mockTracer = new MockTracer();
Scope scope = mockTracer.buildSpan("foo").startActive(true);
assertEquals(scope, mockTracer.scopeManager().active());
Map<String, String> propag = new HashMap<>();
mockTracer.inject(scope.span().context(), Format.Builtin.TEXT_MAP, new TextMapInjectAdapter(propag));
assertFalse(propag.isEmpty());
}
use of io.opentracing.Scope in project opentracing-java by opentracing.
the class NoopScopeManagerTest method activeValueToleratesUseTest.
@Test
public void activeValueToleratesUseTest() {
try {
final Scope active = NoopScopeManager.INSTANCE.active();
assertNotNull(active);
active.close();
} catch (final NullPointerException e) {
fail("NoopScopeManagerImpl.active() should return a usable scope");
}
}
use of io.opentracing.Scope in project jaeger-client-java by jaegertracing.
the class ServerFilter method filter.
@Override
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) throws IOException {
try {
Scope scope = tracer.scopeManager().active();
if (scope == null) {
// hitting this case means previous filter was not called
return;
}
Tags.HTTP_STATUS.set(scope.span(), containerResponseContext.getStatus());
// We started the scope with finishOnClose=true, so we don't need to finish the span manually.
scope.close();
} catch (Exception e) {
log.error("Server Filter Response:", e);
}
}
use of io.opentracing.Scope in project jaeger-client-java by jaegertracing.
the class PropagationTest method testIgnoreActiveSpan.
@Test
public void testIgnoreActiveSpan() {
InMemoryReporter reporter = new InMemoryReporter();
Tracer tracer = new Tracer.Builder("test", reporter, new ConstSampler(true)).build();
try (Scope parent = tracer.buildSpan("parent").startActive(true)) {
tracer.buildSpan("child").ignoreActiveSpan().startActive(true).close();
}
assertEquals(2, reporter.getSpans().size());
Span childSpan = reporter.getSpans().get(0);
Span parentSpan = reporter.getSpans().get(1);
assertTrue(reporter.getSpans().get(0).getReferences().isEmpty());
assertTrue(reporter.getSpans().get(1).getReferences().isEmpty());
assertNotEquals(parentSpan.context().getTraceId(), childSpan.context().getTraceId());
assertEquals(0, childSpan.context().getParentId());
}
use of io.opentracing.Scope in project jaeger-client-java by jaegertracing.
the class PropagationTest method testNoAutoRefWithExistingRefs.
@Test
public void testNoAutoRefWithExistingRefs() {
InMemoryReporter reporter = new InMemoryReporter();
Tracer tracer = new Tracer.Builder("test", reporter, new ConstSampler(true)).build();
io.opentracing.Span initialSpan = tracer.buildSpan("initial").start();
try (Scope parent = tracer.buildSpan("parent").startActive(true)) {
tracer.buildSpan("child").asChildOf(initialSpan.context()).startActive(true).close();
}
initialSpan.finish();
assertEquals(3, reporter.getSpans().size());
Span childSpan = reporter.getSpans().get(0);
Span parentSpan = reporter.getSpans().get(1);
Span initSpan = reporter.getSpans().get(2);
assertTrue(initSpan.getReferences().isEmpty());
assertTrue(parentSpan.getReferences().isEmpty());
assertEquals(initSpan.context().getTraceId(), childSpan.context().getTraceId());
assertEquals(initSpan.context().getSpanId(), childSpan.context().getParentId());
assertEquals(0, initSpan.context().getParentId());
assertEquals(0, parentSpan.context().getParentId());
}
Aggregations