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;
}
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;
}
};
}
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);
}
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());
}
}
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();
}
}
Aggregations