Search in sources :

Example 1 with Scope

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

the class ScopeManagerTraceContext method pop.

/**
 * Deactivates the current active span and returns it. If there is no active span returns null.
 */
@Override
public Span pop() {
    Scope scope = scopeManager.active();
    if (scope == null) {
        return null;
    }
    Span span = scope.span();
    scope.close();
    return span;
}
Also used : Scope(io.opentracing.Scope) Span(io.opentracing.Span)

Example 2 with Scope

use of io.opentracing.Scope in project brave by openzipkin.

the class BraveSpanBuilder method startActive.

@Override
public Scope startActive(boolean finishOnClose) {
    BraveSpan span = startManual();
    SpanInScope delegate = tracer.withSpanInScope(span.delegate);
    return new Scope() {

        @Override
        public void close() {
            if (finishOnClose)
                span.finish();
            delegate.close();
        }

        @Override
        public io.opentracing.Span span() {
            return span;
        }
    };
}
Also used : Scope(io.opentracing.Scope) SpanInScope(brave.Tracer.SpanInScope) SpanInScope(brave.Tracer.SpanInScope)

Example 3 with Scope

use of io.opentracing.Scope in project spring-cloud-sleuth by spring-cloud.

the class BraveTracerTest method subsequentChildrenNestProperly_OTStyle.

@Test
public void subsequentChildrenNestProperly_OTStyle() {
    // this test is semantically identical to subsequentChildrenNestProperly_BraveStyle, but uses
    // the OpenTracingAPI instead of the Brave API.
    Long idOfSpanA;
    Long shouldBeIdOfSpanA;
    Long idOfSpanB;
    Long shouldBeIdOfSpanB;
    Long parentIdOfSpanB;
    Long parentIdOfSpanC;
    try (Scope scopeA = opentracing.buildSpan("spanA").startActive(false)) {
        idOfSpanA = getTraceContext(scopeA).spanId();
        try (Scope scopeB = opentracing.buildSpan("spanB").startActive(false)) {
            idOfSpanB = getTraceContext(scopeB).spanId();
            parentIdOfSpanB = getTraceContext(scopeB).parentId();
            shouldBeIdOfSpanB = getTraceContext(opentracing.scopeManager().active()).spanId();
        }
        shouldBeIdOfSpanA = getTraceContext(opentracing.scopeManager().active()).spanId();
        try (Scope scopeC = opentracing.buildSpan("spanC").startActive(false)) {
            parentIdOfSpanC = getTraceContext(scopeC).parentId();
        }
    }
    assertEquals("SpanA should have been active again after closing B", idOfSpanA, shouldBeIdOfSpanA);
    assertEquals("SpanB should have been active prior to its closure", idOfSpanB, shouldBeIdOfSpanB);
    assertEquals("SpanB's parent should be SpanA", idOfSpanA, parentIdOfSpanB);
    assertEquals("SpanC's parent should be SpanA", idOfSpanA, parentIdOfSpanC);
}
Also used : SpanInScope(brave.Tracer.SpanInScope) Scope(io.opentracing.Scope) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Scope

use of io.opentracing.Scope in project spring-cloud-sleuth by spring-cloud.

the class BraveTracerTest method implicitParentFromSpanManager_start.

@Test
public void implicitParentFromSpanManager_start() {
    try (Scope scopeA = opentracing.buildSpan("spanA").startActive(true)) {
        BraveSpan span = opentracing.buildSpan("spanB").start();
        assertThat(span.unwrap().context().parentId()).isEqualTo(getTraceContext(scopeA).spanId());
    }
}
Also used : BraveSpan(brave.opentracing.BraveSpan) SpanInScope(brave.Tracer.SpanInScope) Scope(io.opentracing.Scope) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Scope

use of io.opentracing.Scope in project spring-cloud-sleuth by spring-cloud.

the class BraveTracerTest method implicitParentFromSpanManager_start_ignoreActiveSpan.

@Test
public void implicitParentFromSpanManager_start_ignoreActiveSpan() {
    try (Scope scopeA = opentracing.buildSpan("spanA").startActive(true)) {
        BraveSpan span = opentracing.buildSpan("spanB").ignoreActiveSpan().start();
        assertThat(span.unwrap().context().parentId()).isNull();
    }
}
Also used : BraveSpan(brave.opentracing.BraveSpan) SpanInScope(brave.Tracer.SpanInScope) Scope(io.opentracing.Scope) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Scope (io.opentracing.Scope)47 Test (org.junit.Test)32 Span (io.opentracing.Span)17 MockSpan (io.opentracing.mock.MockSpan)10 InMemoryReporter (com.uber.jaeger.reporters.InMemoryReporter)5 ConstSampler (com.uber.jaeger.samplers.ConstSampler)5 SpanInScope (brave.Tracer.SpanInScope)4 IOException (java.io.IOException)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 BraveSpan (brave.opentracing.BraveSpan)2 TextMapInjectAdapter (io.opentracing.propagation.TextMapInjectAdapter)2 HashMap (java.util.HashMap)2 ScopeManager (io.opentracing.ScopeManager)1 Tracer (io.opentracing.Tracer)1 MockTracer (io.opentracing.mock.MockTracer)1 AutoFinishScope (io.opentracing.util.AutoFinishScope)1 Continuation (io.opentracing.util.AutoFinishScope.Continuation)1 GlobalTracer (io.opentracing.util.GlobalTracer)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1