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