Java Code Examples for io.opentracing.Tracer#scopeManager()

The following examples show how to use io.opentracing.Tracer#scopeManager() . 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: 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 4
Source File: TracingContextProvider.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Override
public ThreadContextSnapshot clearedContext(Map<String, String> props) {
    return () -> {
        Tracer tracer = GlobalTracer.get();
        ScopeManager scopeManager = tracer.scopeManager();
        Scope activeScope = scopeManager.active();
        if (activeScope != null) {
            activeScope.close();
        }
        return () -> {
            // TODO: we should bring back the span here
        };
    };
}
 
Example 5
Source File: TracerWrapper.java    From java-jfr-tracer with Apache License 2.0 4 votes vote down vote up
public TracerWrapper(Tracer delegate) {
	this.delegate = requireNonNull(delegate);
	this.scopeManager = new ScopeManagerWrapper(delegate.scopeManager());
}
 
Example 6
Source File: LoggerTracerModule.java    From java-span-reporter with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
protected ScopeManager scopeManager(@Named("backend") Tracer tracer) {
    return (tracer.scopeManager() == null) ? tracer.scopeManager() : new ThreadLocalScopeManager();
}
 
Example 7
Source File: AsyncOpenTracingContextTest.java    From tchannel-java with MIT License 4 votes vote down vote up
@Override
protected @NotNull TracingContext tracingContext(@NotNull Tracer tracer) {
    return new OpenTracingContext(tracer.scopeManager());
}
 
Example 8
Source File: OpenTracingContextTest.java    From tchannel-java with MIT License 4 votes vote down vote up
@Override
protected @NotNull TracingContext tracingContext(@NotNull Tracer tracer) {
    return new OpenTracingContext(tracer.scopeManager());
}