Search in sources :

Example 31 with Scope

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

the class ActiveSpanTest method testNoAutoRefWithExistingRefs.

@Test
public void testNoAutoRefWithExistingRefs() {
    JaegerSpan initialSpan = tracer.buildSpan("initial").start();
    JaegerSpan parent = tracer.buildSpan("parent").start();
    try (Scope ignored = tracer.activateSpan(parent)) {
        tracer.buildSpan("child").asChildOf(initialSpan.context()).start().finish();
    } finally {
        parent.finish();
        initialSpan.finish();
    }
    initialSpan.finish();
    assertEquals(3, reporter.getSpans().size());
    JaegerSpan parentSpan = reporter.getSpans().get(1);
    assertTrue(parentSpan.getReferences().isEmpty());
    JaegerSpan initSpan = reporter.getSpans().get(2);
    assertTrue(initSpan.getReferences().isEmpty());
    JaegerSpanContext initialSpanContext = initSpan.context();
    assertEquals(0, initialSpanContext.getParentId());
    JaegerSpan childSpan = reporter.getSpans().get(0);
    JaegerSpanContext childSpanContext = childSpan.context();
    assertEquals(initialSpanContext.getTraceId(), childSpanContext.getTraceId());
    assertEquals(initialSpanContext.getSpanId(), childSpanContext.getParentId());
    JaegerSpanContext parentSpanContext = parentSpan.context();
    assertEquals(0, parentSpanContext.getParentId());
}
Also used : Scope(io.opentracing.Scope) Test(org.junit.Test)

Example 32 with Scope

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

the class ActiveSpanTest method testIgnoreActiveSpan.

@Test
public void testIgnoreActiveSpan() {
    Span span = tracer.buildSpan("parent").start();
    try (Scope ignored = tracer.activateSpan(span)) {
        tracer.buildSpan("child").ignoreActiveSpan().start().finish();
    } finally {
        span.finish();
    }
    assertEquals(2, reporter.getSpans().size());
    JaegerSpan childSpan = reporter.getSpans().get(0);
    JaegerSpan parentSpan = reporter.getSpans().get(1);
    JaegerSpanContext parentSpanContext = parentSpan.context();
    JaegerSpanContext childSpanContext = childSpan.context();
    assertTrue((reporter.getSpans().get(0)).getReferences().isEmpty());
    assertTrue((reporter.getSpans().get(1)).getReferences().isEmpty());
    assertNotEquals(parentSpanContext.getTraceId(), childSpanContext.getTraceId());
    assertEquals(0, childSpanContext.getParentId());
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span) Test(org.junit.Test)

Example 33 with Scope

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

the class ActiveSpanTest method testActiveSpanNotAutoFinishOnClose.

@Test
public void testActiveSpanNotAutoFinishOnClose() {
    Span span = tracer.buildSpan("parent").start();
    try (Scope ignored = tracer.activateSpan(span)) {
    // noop
    }
    assertTrue(reporter.getSpans().isEmpty());
    span.finish();
    assertEquals(1, reporter.getSpans().size());
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span) Test(org.junit.Test)

Example 34 with Scope

use of io.opentracing.Scope in project cxf by apache.

the class AbstractOpenTracingClientProvider method stopTraceSpan.

protected void stopTraceSpan(final TraceScopeHolder<TraceScope> holder, final Throwable ex) {
    if (holder == null) {
        return;
    }
    final TraceScope traceScope = holder.getScope();
    if (traceScope != null) {
        Span span = traceScope.getSpan();
        Scope scope = traceScope.getScope();
        // in another thread and should be re-attached to the current one.
        if (holder.isDetached()) {
            scope = tracer.scopeManager().activate(span);
        }
        span.setTag(Tags.ERROR.getKey(), Boolean.TRUE);
        if (ex != null) {
            final Map<String, Object> logEvent = new HashMap<>(2);
            logEvent.put("event", Tags.ERROR.getKey());
            logEvent.put("message", ex.getMessage());
            span.log(logEvent);
        }
        span.finish();
        scope.close();
    }
}
Also used : Scope(io.opentracing.Scope) HashMap(java.util.HashMap) Span(io.opentracing.Span)

Example 35 with Scope

use of io.opentracing.Scope in project cxf by apache.

the class AbstractOpenTracingClientProvider method startTraceSpan.

protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, URI uri, String method) {
    final Span parent = tracer.activeSpan();
    final Span activeSpan;
    final Scope scope;
    if (parent == null) {
        activeSpan = tracer.buildSpan(buildSpanDescription(uri.toString(), method)).start();
        scope = tracer.scopeManager().activate(activeSpan);
    } else {
        activeSpan = tracer.buildSpan(buildSpanDescription(uri.toString(), method)).asChildOf(parent).start();
        scope = tracer.scopeManager().activate(activeSpan);
    }
    // Set additional tags
    activeSpan.setTag(Tags.HTTP_METHOD.getKey(), method);
    activeSpan.setTag(Tags.HTTP_URL.getKey(), uri.toString());
    tracer.inject(activeSpan.context(), Builtin.HTTP_HEADERS, new TextMapInjectAdapter(requestHeaders));
    // In case of asynchronous client invocation, the span should be detached as JAX-RS
    // client request / response filters are going to be executed in different threads.
    Span span = null;
    if (isAsyncInvocation()) {
        span = activeSpan;
        scope.close();
    }
    return new TraceScopeHolder<TraceScope>(new TraceScope(activeSpan, scope), span != null);
}
Also used : Scope(io.opentracing.Scope) TextMapInjectAdapter(org.apache.cxf.tracing.opentracing.internal.TextMapInjectAdapter) Span(io.opentracing.Span)

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