Java Code Examples for io.opentracing.util.GlobalTracer#get()
The following examples show how to use
io.opentracing.util.GlobalTracer#get() .
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: TracingContextProvider.java From thorntail with Apache License 2.0 | 6 votes |
@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 2
Source File: MonoAgentIntercept.java From java-specialagent with Apache License 2.0 | 6 votes |
public static void enter() { if (inited.get()) return; synchronized (inited) { if (inited.get()) return; try { Operators.class.getMethod("liftPublisher", BiFunction.class); } catch (final NoSuchMethodException e) { logger.warning("Reactor version is not supported"); inited.set(true); return; } final Tracer tracer = GlobalTracer.get(); Hooks.onEachOperator(TracedSubscriber.asOperator(tracer)); Hooks.onLastOperator(TracedSubscriber.asOperator(tracer)); inited.set(true); } }
Example 3
Source File: FluxAgentIntercept.java From java-specialagent with Apache License 2.0 | 6 votes |
public static void enter() { if (inited.get()) return; synchronized (inited) { if (inited.get()) return; try { Operators.class.getMethod("liftPublisher", BiFunction.class); } catch (final NoSuchMethodException e) { logger.warning("Reactor version is not supported"); inited.set(true); return; } final Tracer tracer = GlobalTracer.get(); Hooks.onEachOperator(TracedSubscriber.asOperator(tracer)); Hooks.onLastOperator(TracedSubscriber.asOperator(tracer)); inited.set(true); } }
Example 4
Source File: TracingMethodInvocation.java From java-specialagent with Apache License 2.0 | 6 votes |
@Override public Object proceed() throws Throwable { final Tracer tracer = GlobalTracer.get(); final Span span = tracer .buildSpan(invocation.getMethod().getName()) .withTag(Tags.COMPONENT.getKey(), "spring-async") .withTag("class", invocation.getMethod().getDeclaringClass().getSimpleName()) .withTag("method", invocation.getMethod().getName()) .start(); try (final Scope ignored = tracer.activateSpan(span)) { return invocation.proceed(); } catch (final Exception e) { OpenTracingApiUtil.setErrorTag(span, e); throw e; } finally { span.finish(); } }
Example 5
Source File: FeignAgentIntercept.java From java-specialagent with Apache License 2.0 | 6 votes |
public static Object onRequest(final Object arg1, final Object arg2) { final Request request = (Request)arg1; final Tracer tracer = GlobalTracer.get(); final Span span = tracer .buildSpan(request.method()) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CLIENT) .withTag(Tags.COMPONENT, COMPONENT_NAME) .start(); for (final FeignSpanDecorator decorator : Configuration.spanDecorators) decorator.onRequest(request, (Options)arg2, span); final Scope scope = tracer.activateSpan(span); LocalSpanContext.set(COMPONENT_NAME, span, scope); return inject(tracer, span.context(), request); }
Example 6
Source File: SpringKafkaAgentIntercept.java From java-specialagent with Apache License 2.0 | 6 votes |
public static void onMessageEnter(final Object record) { if (LocalSpanContext.get(COMPONENT_NAME) != null) { LocalSpanContext.get(COMPONENT_NAME).increment(); return; } final Tracer tracer = GlobalTracer.get(); final SpanBuilder builder = tracer .buildSpan("onMessage") .withTag(Tags.COMPONENT, COMPONENT_NAME) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER); if (record instanceof ConsumerRecord) { final ConsumerRecord<?,?> consumerRecord = (ConsumerRecord<?,?>)record; final SpanContext spanContext = TracingKafkaUtils.extractSpanContext(consumerRecord.headers(), tracer); if (spanContext != null) builder.addReference(References.FOLLOWS_FROM, spanContext); } final Span span = builder.start(); LocalSpanContext.set(COMPONENT_NAME, span, tracer.activateSpan(span)); }
Example 7
Source File: FixedDelayAgentRule.java From java-specialagent with Apache License 2.0 | 6 votes |
@Advice.OnMethodEnter public static void exit(final @ClassName String className, final @Advice.Origin String origin, @Advice.Argument(value = 0, readOnly = false, typing = Typing.DYNAMIC) Runnable arg) throws Exception { if (!isAllowed(className, origin)) return; final Tracer tracer = GlobalTracer.get(); if (isVerbose(className)) { final Span span = tracer .buildSpan("scheduleWithFixedDelay") .withTag(Tags.COMPONENT, "java-concurrent") .start(); arg = WrapperProxy.wrap(arg, new TracedRunnable(arg, span, true)); span.finish(); } else if (tracer.activeSpan() != null) { arg = WrapperProxy.wrap(arg, new TracedRunnable(arg, tracer.activeSpan(), false)); } }
Example 8
Source File: SpringJmsAgentIntercept.java From java-specialagent with Apache License 2.0 | 6 votes |
public static void onMessageEnter(final Object msg) { if (LocalSpanContext.get(COMPONENT_NAME) != null) { LocalSpanContext.get(COMPONENT_NAME).increment(); return; } final Tracer tracer = GlobalTracer.get(); final SpanBuilder builder = tracer .buildSpan("onMessage") .withTag(Tags.COMPONENT, COMPONENT_NAME) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER); SpanContext spanContext = null; if (msg instanceof SpanContextContainer) spanContext = ((SpanContextContainer)msg).getSpanContext(); if (spanContext == null) spanContext = TracingMessageUtils.extract((Message)msg, tracer); if (spanContext != null) builder.addReference(References.FOLLOWS_FROM, spanContext); final Span span = builder.start(); LocalSpanContext.set(COMPONENT_NAME, span, tracer.activateSpan(span)); }
Example 9
Source File: RxJava3AgentIntercept.java From java-specialagent with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static Object enter(final Object thiz, final int argc, final Object arg0, final Object arg1, final Object arg2) { if (arg0 == null || arg0.getClass().getName().startsWith("io.reactivex.rxjava3.internal") || arg0 instanceof TracingConsumer) return NULL; if (!isTracingEnabled) { isTracingEnabled = true; TracingRxJava3Utils.enableTracing(); } if (arg0 instanceof Observer) return new TracingObserver<>((Observer<?>)arg0, "observer", GlobalTracer.get()); if (!(arg0 instanceof Consumer)) return NULL; final TracingConsumer<Object> tracingConsumer; if (argc == 1) tracingConsumer = new TracingConsumer<>((Consumer<Object>)arg0, "consumer", GlobalTracer.get()); else if (argc == 2) tracingConsumer = new TracingConsumer<>((Consumer<Object>)arg0, (Consumer<Throwable>)arg1, "consumer", GlobalTracer.get()); else if (argc == 3) tracingConsumer = new TracingConsumer<>((Consumer<Object>)arg0, (Consumer<Throwable>)arg1, (Action)arg2, "consumer", GlobalTracer.get()); else tracingConsumer = null; if (tracingConsumer != null) ((Observable<Object>)thiz).subscribe(tracingConsumer); return null; }
Example 10
Source File: TracingContextProvider.java From smallrye-fault-tolerance with Apache License 2.0 | 5 votes |
@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 11
Source File: TraceUtil.java From qmq with Apache License 2.0 | 5 votes |
public static void recordEvent(String event, Tracer tracer) { if (tracer == null) { tracer = GlobalTracer.get(); } Scope scope = tracer.scopeManager().active(); if (scope == null) return; scope.span().log(event); }
Example 12
Source File: ServletAgentIntercept.java From java-specialagent with Apache License 2.0 | 5 votes |
public static void serviceEnter(final Object thiz, final Object req, final Object res) { try { final ServletContext context = getServletContext((HttpServlet)thiz); if (context == null) return; final TracingFilter tracingFilter = getFilter(context, true); // If the tracingFilter instance is not a TracingProxyFilter, then it was // created with ServletContext#addFilter. Therefore, the intercept of the // Filter#doFilter method is not necessary. if (!(tracingFilter instanceof TracingProxyFilter)) return; // If `servletRequestToState` contains the request key, then this request // has been handled by doFilter final HttpServletRequest request = (HttpServletRequest)req; if (request.getAttribute(TracingFilter.SERVER_SPAN_CONTEXT) != null) return; if (LocalSpanContext.get(COMPONENT_NAME) != null) return; if (!Configuration.isTraced(request)) return; final Tracer tracer = GlobalTracer.get(); final Span span = TracingFilterUtil.buildSpan(request, tracer, spanDecorators); LocalSpanContext.set(COMPONENT_NAME, span, tracer.activateSpan(span)); if (logger.isLoggable(Level.FINER)) logger.finer("<< ServletAgentIntercept#service(" + AgentRuleUtil.getSimpleNameId(req) + "," + AgentRuleUtil.getSimpleNameId(res) + "," + AgentRuleUtil.getSimpleNameId(context) + ")"); } catch (final Exception e) { logger.log(Level.WARNING, e.getMessage(), e); } }
Example 13
Source File: AkkaAgentIntercept.java From java-specialagent with Apache License 2.0 | 5 votes |
public static Object aroundReceiveStart(final Object thiz, final Object message) { if (!(message instanceof TracedMessage) && LocalSpanContext.get(COMPONENT_NAME) != null) { LocalSpanContext.get(COMPONENT_NAME).increment(); return message; } final Tracer tracer = GlobalTracer.get(); final SpanBuilder spanBuilder = tracer .buildSpan("receive") .withTag(Tags.COMPONENT, COMPONENT_NAME) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER); final TracedMessage<?> tracedMessage; if (message instanceof TracedMessage) { tracedMessage = (TracedMessage<?>)message; spanBuilder.addReference(References.FOLLOWS_FROM, tracedMessage.spanContext(tracer)); } else { tracedMessage = null; spanBuilder.withTag(Tags.MESSAGE_BUS_DESTINATION, ((AbstractActor)thiz).getSelf().path().toString()); } final Span span = spanBuilder.start(); final Scope scope = tracer.activateSpan(span); LocalSpanContext.set(COMPONENT_NAME, span, scope); return tracedMessage != null ? tracedMessage.getMessage() : message; }
Example 14
Source File: JmsAgentIntercept.java From java-specialagent with Apache License 2.0 | 5 votes |
public static Object createProducer(final Object thiz) { try { Class.forName("javax.jms.JMSContext", false, thiz.getClass().getClassLoader()); return new io.opentracing.contrib.jms2.TracingMessageProducer((MessageProducer)thiz, GlobalTracer.get()); } catch (final ClassNotFoundException e) { return new io.opentracing.contrib.jms.TracingMessageProducer((MessageProducer)thiz, GlobalTracer.get()); } }
Example 15
Source File: JmsAgentIntercept.java From java-specialagent with Apache License 2.0 | 4 votes |
public static Object createConsumer(final Object thiz) { return new TracingMessageConsumer((MessageConsumer)thiz, GlobalTracer.get(), true); }
Example 16
Source File: TracingDriver.java From java-jdbc with Apache License 2.0 | 4 votes |
Tracer getTracer() { if (tracer == null) { return GlobalTracer.get(); } return tracer; }
Example 17
Source File: TracingFilter.java From java-web-servlet-filter with Apache License 2.0 | 4 votes |
/** * Tracer instance has to be registered with {@link GlobalTracer#register(Tracer)}. */ public TracingFilter() { this(GlobalTracer.get()); }
Example 18
Source File: TracingKafkaClientSupplier.java From java-kafka-client with Apache License 2.0 | 4 votes |
/** * GlobalTracer is used to get tracer */ public TracingKafkaClientSupplier() { this(GlobalTracer.get(), null, null, null); }
Example 19
Source File: TracingDataSource.java From che with Eclipse Public License 2.0 | 4 votes |
@Override public Connection getConnection(String username, String password) throws SQLException { return new TracingConnection( delegate.getConnection(username, password), connectionInfo, true, null, GlobalTracer.get()); }
Example 20
Source File: ShardingTracer.java From shardingsphere with Apache License 2.0 | 2 votes |
/** * Get tracer. * * @return tracer */ public static Tracer get() { return GlobalTracer.get(); }