io.opentracing.ScopeManager Java Examples

The following examples show how to use io.opentracing.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: SpanBuilderRTest.java    From java-span-reporter with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    this.reporterMock = mock(Reporter.class);
    this.spanBuilderMock = mock(Tracer.SpanBuilder.class);
    this.scopeManagerMock = mock(ScopeManager.class);
    this.newSpanMock = mock(Span.class);
    this.parentSpanMock = mock(Span.class);
    this.parentSpanContextMock = mock(SpanContext.class);

    // default mock behaviors
    when(spanBuilderMock.start()).thenReturn(newSpanMock);
    when(parentSpanMock.context()).thenReturn(parentSpanContextMock);
}
 
Example #4
Source File: OpenTracingVersion.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
static v0_32 buildIfSupported() {
  // Find OpenTracing 0.32 deprecated method
  try {
    if (ScopeManager.class.getMethod("activate", Span.class, boolean.class)
        .getAnnotation(Deprecated.class) != null) {
      return new v0_32();
    }
  } catch (NoSuchMethodException e) {
    // EmptyCatch: ignored
  }
  return null;
}
 
Example #5
Source File: OpenTracingVersion.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
static boolean isV0_31() {
  // Find OpenTracing 0.31 method
  try {
    if (ScopeManager.class.getMethod("activate", Span.class, boolean.class)
        .getAnnotation(Deprecated.class) == null) {
      return true;
    }
  } catch (NoSuchMethodException e) {
    // EmptyCatch: ignored
  }
  return false;
}
 
Example #6
Source File: QuarkusJaegerTracer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private ScopeManager getScopeManager() {
    ScopeManager scopeManager = new ThreadLocalScopeManager();
    if (logTraceContext) {
        scopeManager = new MDCScopeManager(scopeManager);
    }
    return scopeManager;
}
 
Example #7
Source File: TracingConcurrencyStrategy.java    From feign-opentracing with Apache License 2.0 5 votes vote down vote up
public OpenTracingHystrixCallable(Callable<S> delegate, ScopeManager scopeManager, Span span) {
    if (span == null || delegate == null || scopeManager == null) {
        throw new NullPointerException();
    }
    this.delegateCallable = delegate;
    this.scopeManager = scopeManager;
    this.span = span;
}
 
Example #8
Source File: ProxyMockTracer.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Override
public ProxyMockScopeManager scopeManager() {
  final ScopeManager mockScopeManager = super.scopeManager();
  final ScopeManager realScopeManager = realTracer.scopeManager();
  if (scopeManager == null || scopeManager.mockScopeManager != mockScopeManager || scopeManager.realScopeManager != realScopeManager)
    scopeManager = new ProxyMockScopeManager(this, mockScopeManager, realScopeManager);

  return scopeManager;
}
 
Example #9
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());
}
 
Example #10
Source File: Sample01.java    From java-span-reporter with Apache License 2.0 5 votes vote down vote up
private static Tracer provideTracerByConstructor() throws Exception {
    Tracer backend = new MockTracer();
    Reporter reporter = new Slf4jReporter(LoggerFactory.getLogger("tracer"), true);
    //ScopeManager scopeManager = new ThreadLocalScopeManager();
    ScopeManager scopeManager = new ThreadLocalScopeManager();
    return new TracerR(backend, reporter, scopeManager);
}
 
Example #11
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 #12
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 #13
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 #14
Source File: GrpcTracerFacade.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
  return getTracer().scopeManager();
}
 
Example #15
Source File: OpenCensusTracerAdapter.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
  throw new UnsupportedOperationException("Adapter does not support scopeManager");
}
 
Example #16
Source File: TracerFacade.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
  return tracer.scopeManager();
}
 
Example #17
Source File: BraveTracer.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public ScopeManager scopeManager() {
  return null; // out-of-scope for a simple example
}
 
Example #18
Source File: MockTracer.java    From opentracing-java with Apache License 2.0 4 votes vote down vote up
public MockTracer(ScopeManager scopeManager) {
    this(scopeManager, Propagator.TEXT_MAP);
}
 
Example #19
Source File: MockTracer.java    From opentracing-java with Apache License 2.0 4 votes vote down vote up
public MockTracer(ScopeManager scopeManager, Propagator propagator) {
    this.scopeManager = scopeManager;
    this.propagator = propagator;
}
 
Example #20
Source File: MockTracer.java    From opentracing-java with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
    return this.scopeManager;
}
 
Example #21
Source File: NoopTracer.java    From opentracing-java with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
    return NoopScopeManager.INSTANCE;
}
 
Example #22
Source File: GlobalTracer.java    From opentracing-java with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
    return tracer.scopeManager();
}
 
Example #23
Source File: ForwardingTracer.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@Override
default ScopeManager scopeManager() {
    return delegate().scopeManager();
}
 
Example #24
Source File: ProxyScopeManager.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@Override
public ScopeManager delegate() {
    return delegate;
}
 
Example #25
Source File: ProxyTracer.java    From opentracing-toolbox with MIT License 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
    return new ProxyScopeManager(
            ForwardingTracer.super.scopeManager(), registry);
}
 
Example #26
Source File: ThresholdLogTracer.java    From couchbase-jvm-core with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
    return scopeManager;
}
 
Example #27
Source File: OpenTracingContextTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testUnwrapUnsupportedClass() {
    context.unwrap(ScopeManager.class);
}
 
Example #28
Source File: DelegateTracer.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
  return target.scopeManager();
}
 
Example #29
Source File: TracerShim.java    From opentelemetry-java with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
  return scopeManagerShim;
}
 
Example #30
Source File: RewritableTracer.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Override
public ScopeManager scopeManager() {
  return target.scopeManager();
}