java.lang.Object
org.springframework.cloud.sleuth.instrument.reactor.ReactorSleuth

public abstract class ReactorSleuth extends Object
Reactive Span pointcuts factories.
Since:
2.0.0
Author:
Stephane Maldini, Roman Matiushchenko
  • Field Details

    • contextWrappingFunction

      public static Function<reactor.util.context.Context,reactor.util.context.Context> contextWrappingFunction
      Function that does additional wrapping of the Reactor context.
  • Method Details

    • scopePassingSpanOperator

      public static <T> Function<? super org.reactivestreams.Publisher<T>,? extends org.reactivestreams.Publisher<T>> scopePassingSpanOperator(org.springframework.context.ConfigurableApplicationContext springContext)
      Return a span operator pointcut given a Tracing. This can be used in reactor via Flux.transform(Function), Mono.transform(Function), Hooks.onLastOperator(Function) or Hooks.onLastOperator(Function). The Span operator pointcut will pass the Scope of the Span without ever creating any new spans.
      Type Parameters:
      T - an arbitrary type that is left unchanged by the span operator
      Parameters:
      springContext - the Spring context.
      Returns:
      a new lazy span operator pointcut
    • onEachOperatorForOnEachInstrumentation

      public static <T> Function<? super org.reactivestreams.Publisher<T>,? extends org.reactivestreams.Publisher<T>> onEachOperatorForOnEachInstrumentation(org.springframework.context.ConfigurableApplicationContext springContext)
      Creates scope passing span operator which applies only to not Scannable.Attr.RunStyle.SYNC Publishers. Used by InstrumentationType#DECORATE_ON_EACH
      Type Parameters:
      T - an arbitrary type that is left unchanged by the span operator.
      Parameters:
      springContext - the Spring context.
      Returns:
      operator to apply to Hooks.onEachOperator(Function).
    • springContextSpanOperator

      public static <T> Function<? super org.reactivestreams.Publisher<T>,? extends org.reactivestreams.Publisher<T>> springContextSpanOperator(org.springframework.context.ConfigurableApplicationContext springContext)
      Creates a context with beans in it.
      Type Parameters:
      T - an arbitrary type that is left unchanged by the span operator
      Parameters:
      springContext - spring context
      Returns:
      a new operator pointcut that has beans in the context
    • onLastOperatorForOnEachInstrumentation

      public static <T> Function<? super org.reactivestreams.Publisher<T>,? extends org.reactivestreams.Publisher<T>> onLastOperatorForOnEachInstrumentation(org.springframework.context.ConfigurableApplicationContext springContext)
      Creates tracing context capturing reactor operator. Used by InstrumentationType#DECORATE_ON_EACH.
      Type Parameters:
      T - an arbitrary type that is left unchanged by the span operator.
      Parameters:
      springContext - the Spring context.
      Returns:
      operator to apply to Hooks.onLastOperator(Function) for InstrumentationType#DECORATE_ON_EACH
    • scopePassingOnScheduleHook

      public static Function<Runnable,Runnable> scopePassingOnScheduleHook(org.springframework.context.ConfigurableApplicationContext springContext)
    • tracedMono

      public static <T> reactor.core.publisher.Mono<T> tracedMono(@NonNull Tracer tracer, @NonNull CurrentTraceContext currentTraceContext, @NonNull String childSpanName, @NonNull Supplier<reactor.core.publisher.Mono<T>> supplier, @NonNull BiConsumer<T,Span> spanCustomizer)
      Wraps the given Mono in a trace representation. Retrieves the span from context, creates a child span with the given name.
      Type Parameters:
      T - - type returned by the Mono
      Parameters:
      tracer - - Tracer bean
      currentTraceContext - - CurrentTraceContext bean
      childSpanName - - name of the created child span
      supplier - - supplier of a Mono to be wrapped in tracing
      spanCustomizer - - customizer for the child span
      Returns:
      traced Mono
    • tracedMono

      public static <T> reactor.core.publisher.Mono<T> tracedMono(@NonNull Tracer tracer, @NonNull CurrentTraceContext currentTraceContext, @NonNull String childSpanName, @NonNull Supplier<reactor.core.publisher.Mono<T>> supplier, @NonNull BiConsumer<T,Span> spanCustomizer, @NonNull Function<Span,Span> spanFunction)
      Wraps the given Mono in a trace representation. Retrieves the span from context, creates a child span with the given name.
      Type Parameters:
      T - - type returned by the Mono
      Parameters:
      tracer - - Tracer bean
      currentTraceContext - - CurrentTraceContext bean
      childSpanName - - name of the created child span
      supplier - - supplier of a Mono to be wrapped in tracing
      spanCustomizer - - customizer for the child span
      spanFunction - - function that creates a new or child span
      Returns:
      traced Mono
    • tracedMono

      public static <T> reactor.core.publisher.Mono<T> tracedMono(@NonNull Tracer tracer, @NonNull CurrentTraceContext currentTraceContext, @NonNull String childSpanName, @NonNull Supplier<reactor.core.publisher.Mono<T>> supplier)
      Wraps the given Mono in a trace representation. Retrieves the span from context, creates a child span with the given name.
      Type Parameters:
      T - - type returned by the Mono
      Parameters:
      tracer - - Tracer bean
      currentTraceContext - - CurrentTraceContext bean
      childSpanName - - name of the created child span
      supplier - - supplier of a Mono to be wrapped in tracing
      Returns:
      traced Mono
    • tracedMono

      public static <T> reactor.core.publisher.Mono<T> tracedMono(@NonNull Tracer tracer, @NonNull Span span, @NonNull Supplier<reactor.core.publisher.Mono<T>> supplier)
      Wraps the given Mono in a trace representation. Puts the provided span to context.
      Type Parameters:
      T - - type returned by the Mono
      Parameters:
      tracer - - Tracer bean
      span - - span to put in context
      supplier - - supplier of a Mono to be wrapped in tracing
      Returns:
      traced Mono
    • tracedFlux

      public static <T> reactor.core.publisher.Flux<T> tracedFlux(@NonNull Tracer tracer, @NonNull CurrentTraceContext currentTraceContext, @NonNull String childSpanName, @NonNull Supplier<reactor.core.publisher.Flux<T>> supplier, @NonNull BiConsumer<T,Span> spanCustomizer)
      Wraps the given Flux in a trace representation. Retrieves the span from context, creates a child span with the given name.
      Type Parameters:
      T - - type returned by the Flux
      Parameters:
      tracer - - Tracer bean
      currentTraceContext - - CurrentTraceContext bean
      childSpanName - - name of the created child span
      supplier - - supplier of a Flux to be wrapped in tracing
      spanCustomizer - - customizer for the child span
      Returns:
      traced Flux
    • tracedFlux

      public static <T> reactor.core.publisher.Flux<T> tracedFlux(@NonNull Tracer tracer, @NonNull CurrentTraceContext currentTraceContext, @NonNull String childSpanName, @NonNull Supplier<reactor.core.publisher.Flux<T>> supplier, @NonNull BiConsumer<T,Span> spanCustomizer, @NonNull Function<Span,Span> spanFunction)
      Wraps the given Flux in a trace representation. Retrieves the span from context, creates a child span with the given name.
      Type Parameters:
      T - - type returned by the Flux
      Parameters:
      tracer - - Tracer bean
      currentTraceContext - - CurrentTraceContext bean
      childSpanName - - name of the created child span
      supplier - - supplier of a Flux to be wrapped in tracing
      spanCustomizer - - customizer for the child span
      spanFunction - - function that creates a new or child span
      Returns:
      traced Flux
    • tracedFlux

      public static <T> reactor.core.publisher.Flux<T> tracedFlux(@NonNull Tracer tracer, @NonNull Span span, @NonNull Supplier<reactor.core.publisher.Flux<T>> supplier)
      Wraps the given Flux in a trace representation. Retrieves the span from context, creates a child span with the given name.
      Type Parameters:
      T - - type returned by the Flux
      Parameters:
      tracer - - Tracer bean
      span - - span to put in context
      supplier - - supplier of a Flux to be wrapped in tracing
      Returns:
      traced Flux
    • tracedFlux

      public static <T> reactor.core.publisher.Flux<T> tracedFlux(@NonNull Tracer tracer, @NonNull CurrentTraceContext currentTraceContext, @NonNull String childSpanName, @NonNull Supplier<reactor.core.publisher.Flux<T>> supplier)
      Wraps the given Flux in a trace representation. Retrieves the span from context, creates a child span with the given name.
      Type Parameters:
      T - - type returned by the Flux
      Parameters:
      tracer - - Tracer bean
      currentTraceContext - - CurrentTraceContext bean
      childSpanName - - name of the created child span
      supplier - - supplier of a Flux to be wrapped in tracing
      Returns:
      traced Flux
    • enhanceContext

      public static reactor.util.context.Context enhanceContext(Tracer tracer, CurrentTraceContext currentTraceContext, reactor.util.context.Context context, String childSpanName, Function<Span,Span> spanSupplier)
      Updates the Reactor context with tracing information. Creates a new span if there is no current span. Creates a child span if there was an entry in the context already.
      Parameters:
      tracer - tracer
      currentTraceContext - current trace context
      context - Reactor context
      childSpanName - child span name when there is no span in context
      spanSupplier - function that creates a new or child span
      Returns:
      updated Reactor context
    • enhanceContext

      public static reactor.util.context.Context enhanceContext(Tracer tracer, CurrentTraceContext currentTraceContext, reactor.util.context.Context context, String childSpanName)
      Updates the Reactor context with tracing information. Creates a new span if there is no current span. Creates a child span if there was an entry in the context already.
      Parameters:
      tracer - tracer
      currentTraceContext - current trace context
      context - Reactor context
      childSpanName - child span name when there is no span in context
      Returns:
      updated Reactor context
    • putSpanInScope

      public static reactor.util.context.Context putSpanInScope(Tracer tracer, reactor.util.context.Context context, Span span)
      Puts the provided span in scope and in Reactor context.
      Parameters:
      tracer - tracer
      context - Reactor context
      span - span to put in Reactor context
      Returns:
      mutated context
    • wrapContext

      public static reactor.util.context.Context wrapContext(reactor.util.context.Context context)
      Mutates the Reactor context depending on the classpath contents.
      Parameters:
      context - Reactor context
      Returns:
      mutated context
    • getParentTraceContext

      public static TraceContext getParentTraceContext(reactor.util.context.Context context, TraceContext fallback)
      Retreives the TraceContext from the current context.
      Parameters:
      context - Reactor context
      Returns:
      TraceContext or null if none present
    • getPendingSpan

      public static AtomicReference<Span> getPendingSpan(reactor.util.context.ContextView context)
      Retreives the pending span from the current context.
      Parameters:
      context - Reactor context
      Returns:
      AtomicReference to span or null if none present
      See Also:
    • putPendingSpan

      public static reactor.util.context.Context putPendingSpan(reactor.util.context.Context context, AtomicReference<Span> span)
      Mutates the Context to include a mutable reference to a span. Can be used when you need to mutate the parent operator context with a span created by a child operator.
      Parameters:
      context - Reactor context
      span - atomic reference of a span
      Returns:
      mutated context
    • spanFromContext

      public static Span spanFromContext(Tracer tracer, CurrentTraceContext currentTraceContext, reactor.util.context.ContextView context)
      Retrieves span from Reactor context.
      Parameters:
      tracer - tracer
      currentTraceContext - current trace context
      context - context view
      Returns:
      span from Reactor context or creates a new one if missing
    • traceQueue

      public static Queue<?> traceQueue(org.springframework.context.ConfigurableApplicationContext springContext, Queue<?> queue)