Search in sources :

Example 51 with Scope

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());
}
Also used : Scope(io.opentracing.Scope) HashMap(java.util.HashMap) TextMapInjectAdapter(io.opentracing.propagation.TextMapInjectAdapter) Test(org.junit.Test)

Example 52 with Scope

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");
    }
}
Also used : Scope(io.opentracing.Scope) Test(org.junit.Test)

Example 53 with 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);
    }
}
Also used : Scope(io.opentracing.Scope) IOException(java.io.IOException)

Example 54 with Scope

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());
}
Also used : InMemoryReporter(com.uber.jaeger.reporters.InMemoryReporter) Scope(io.opentracing.Scope) ConstSampler(com.uber.jaeger.samplers.ConstSampler) Test(org.junit.Test)

Example 55 with Scope

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());
}
Also used : InMemoryReporter(com.uber.jaeger.reporters.InMemoryReporter) Scope(io.opentracing.Scope) ConstSampler(com.uber.jaeger.samplers.ConstSampler) Test(org.junit.Test)

Aggregations

Scope (io.opentracing.Scope)80 Test (org.junit.Test)52 Span (io.opentracing.Span)46 MockSpan (io.opentracing.mock.MockSpan)10 Tracer (io.opentracing.Tracer)7 Response (javax.ws.rs.core.Response)6 InMemoryReporter (com.uber.jaeger.reporters.InMemoryReporter)5 ConstSampler (com.uber.jaeger.samplers.ConstSampler)5 ScopeManager (io.opentracing.ScopeManager)5 SpanInScope (brave.Tracer.SpanInScope)4 SpanContext (io.opentracing.SpanContext)4 HashMap (java.util.HashMap)4 SpanBuilder (io.opentracing.Tracer.SpanBuilder)3 IOException (java.io.IOException)3 Traced (org.eclipse.microprofile.opentracing.Traced)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 BraveSpan (brave.opentracing.BraveSpan)2 RequestTraceSpan (fish.payara.notification.requesttracing.RequestTraceSpan)2 RequestTracingService (fish.payara.nucleus.requesttracing.RequestTracingService)2 Downstream (io.jaegertracing.crossdock.api.Downstream)2