Java Code Examples for io.opentracing.ScopeManager#activate()

The following examples show how to use io.opentracing.ScopeManager#activate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitMqTracingUtils.java    From java-spring-rabbitmq with Apache License 2.0 6 votes vote down vote up
static Scope buildSendSpan(Tracer tracer, MessageProperties messageProperties) {
  Tracer.SpanBuilder spanBuilder =
      tracer
          .buildSpan(RabbitMqTracingTags.SPAN_KIND_PRODUCER)
          .ignoreActiveSpan()
          .withTag(Tags.SPAN_KIND.getKey(), RabbitMqTracingTags.SPAN_KIND_PRODUCER);

  ScopeManager scopeManager = tracer.scopeManager();
  Optional<SpanContext> existingSpanContext = Optional.ofNullable(scopeManager)
      .map(ScopeManager::activeSpan)
      .map(Span::context);

  existingSpanContext.ifPresent(spanBuilder::asChildOf);

  if (messageProperties.getHeaders() != null) {
    Optional<SpanContext> messageParentContext = findParent(messageProperties, tracer);
    messageParentContext.ifPresent(spanBuilder::asChildOf);
  }
  Span span = spanBuilder.start();
  return scopeManager.activate(span);
}
 
Example 2
Source File: TracingContextProvider.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public MiniConProp.ContextSnapshot capture() {
    Tracer tracer = GlobalTracer.get();
    ScopeManager scopeManager = tracer.scopeManager();
    Scope activeScope = scopeManager.active();

    if (activeScope != null) {
        Span span = activeScope.span();
        return () -> {
            Scope propagated = scopeManager.activate(span, false);
            return propagated::close;
        };
    }

    return MiniConProp.ContextSnapshot.NOOP;
}
 
Example 3
Source File: TracingFilter.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private void finishAndCloseActiveSpan() {
  ScopeManager scopeManager = GlobalTracer.get().scopeManager();
  if (scopeManager != null && scopeManager.activeSpan() != null) {
    scopeManager.activeSpan().finish();
    scopeManager.activate(null);
  }
}
 
Example 4
Source File: TracingContextProvider.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Override
public ThreadContextSnapshot currentContext(Map<String, String> props) {
    Tracer tracer = GlobalTracer.get();
    ScopeManager scopeManager = tracer.scopeManager();
    Scope activeScope = scopeManager.active();

    if (activeScope != null) {
        Span span = activeScope.span();
        return () -> {
            Scope propagated = scopeManager.activate(span, false);
            return propagated::close;
        };
    }
    return () -> DO_NOTHING;
}
 
Example 5
Source File: ProxyScopeManagerTest.java    From opentracing-toolbox with MIT License 5 votes vote down vote up
@Test
void shouldProxyScopeManager() {
    final ScopeManager manager = unit.scopeManager();

    final Span test = unit.buildSpan("test").start();
    try (final Scope ignored = manager.activate(test)) {
        manager.activeSpan().setOperationName("GET");
    } finally {
        test.finish();
    }

    final MockSpan span = getOnlyElement(tracer.finishedSpans());
    assertEquals("get", span.operationName());
}