Search in sources :

Example 61 with Scope

use of io.opentracing.Scope in project jaeger-client-java by jaegertracing.

the class JaegerSubclassTest method testTracer.

@Test
public void testTracer() {
    final CustomConfiguration config = new CustomConfiguration("test-service");
    final CustomTracer.CustomBuilder builder = config.getTracerBuilder();
    final CustomTracer tracer = builder.build();
    final Span span = tracer.buildSpan("test-operation").start();
    try (Scope scope = tracer.activateSpan(span)) {
        Assert.assertNotNull(tracer.scopeManager().activeSpan());
        Assert.assertTrue(tracer.scopeManager().activeSpan() instanceof CustomSpan);
        Assert.assertTrue(tracer.scopeManager().activeSpan().context() instanceof CustomSpanContext);
    }
    config.closeTracer();
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span) Test(org.junit.Test)

Example 62 with Scope

use of io.opentracing.Scope in project jaeger-client-java by jaegertracing.

the class MDCScopeManagerTest method testCustomAndDefaultKeysCreation.

@Test
public void testCustomAndDefaultKeysCreation() {
    ScopeManager mdcScopeManager = new MDCScopeManager.Builder().withMDCSampledKey("customSampled").withMDCSpanIdKey("customSpanId").build();
    Tracer tracer = createTracer(mdcScopeManager);
    Span span = tracer.buildSpan("testCustomAndDefaultKeysCreation").start();
    Scope scope = tracer.activateSpan(span);
    assertSpanContextEqualsToMDC((JaegerSpanContext) span.context(), TRACE_ID, "customSpanId", "customSampled");
    scope.close();
    assertNullMDCKeys(TRACE_ID, "customSpanId", "customSampled");
}
Also used : ScopeManager(io.opentracing.ScopeManager) Scope(io.opentracing.Scope) Tracer(io.opentracing.Tracer) Span(io.opentracing.Span) Test(org.junit.Test)

Example 63 with Scope

use of io.opentracing.Scope in project jaeger-client-java by jaegertracing.

the class MDCScopeManagerTest method testCustomKeysCreation.

@Test
public void testCustomKeysCreation() {
    ScopeManager mdcScopeManager = new MDCScopeManager.Builder().withMDCTraceIdKey("CustomTraceId").withMDCSampledKey("customSampled").withMDCSpanIdKey("customSpanId").build();
    Tracer tracer = createTracer(mdcScopeManager);
    Span span = tracer.buildSpan("testCustomKeysCreation").start();
    Scope scope = tracer.activateSpan(span);
    assertSpanContextEqualsToMDC((JaegerSpanContext) span.context(), "CustomTraceId", "customSpanId", "customSampled");
    scope.close();
    assertNullMDCKeys("CustomTraceId", "customSampled", "customSpanId");
}
Also used : ScopeManager(io.opentracing.ScopeManager) Scope(io.opentracing.Scope) Tracer(io.opentracing.Tracer) Span(io.opentracing.Span) Test(org.junit.Test)

Example 64 with Scope

use of io.opentracing.Scope in project jaeger-client-java by jaegertracing.

the class MDCScopeManagerTest method testNestedSpans.

@Test
public void testNestedSpans() {
    Span parentSpan = defaultTracer.buildSpan("parent").start();
    try (Scope scope = defaultTracer.activateSpan(parentSpan)) {
        assertSpanContextEqualsToMDC((JaegerSpanContext) parentSpan.context(), TRACE_ID, SPAN_ID, SAMPLED);
        Span childSpan = defaultTracer.buildSpan("child").start();
        try (Scope childScope = defaultTracer.activateSpan(childSpan)) {
            assertSpanContextEqualsToMDC((JaegerSpanContext) childSpan.context(), TRACE_ID, SPAN_ID, SAMPLED);
        }
        assertSpanContextEqualsToMDC((JaegerSpanContext) parentSpan.context(), TRACE_ID, SPAN_ID, SAMPLED);
    }
    assertNullMDCKeys(TRACE_ID, SPAN_ID, SAMPLED);
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span) Test(org.junit.Test)

Example 65 with Scope

use of io.opentracing.Scope in project jaeger-client-java by jaegertracing.

the class MDCScopeManagerTest method testDefaultCreation.

@Test
public void testDefaultCreation() {
    Span span = defaultTracer.buildSpan("test Default").start();
    Scope scope = defaultTracer.activateSpan(span);
    assertSpanContextEqualsToMDC((JaegerSpanContext) span.context(), TRACE_ID, SPAN_ID, SAMPLED);
    scope.close();
    assertNullMDCKeys(TRACE_ID, SPAN_ID, SAMPLED);
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span) 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