Class ReactorSleuth
- 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 Summary
Fields Modifier and Type Field Description static Function<reactor.util.context.Context,reactor.util.context.Context>contextWrappingFunctionFunction that does additional wrapping of the Reactor context.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static reactor.util.context.ContextenhanceContext(Tracer tracer, CurrentTraceContext currentTraceContext, reactor.util.context.Context context, String childSpanName)Updates the Reactor context with tracing information.static reactor.util.context.ContextenhanceContext(Tracer tracer, CurrentTraceContext currentTraceContext, reactor.util.context.Context context, String childSpanName, Function<Span,Span> spanSupplier)Updates the Reactor context with tracing information.static TraceContextgetParentTraceContext(reactor.util.context.Context context, TraceContext fallback)Retreives theTraceContextfrom the current context.static AtomicReference<Span>getPendingSpan(reactor.util.context.ContextView context)Retreives the pending span from the current context.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 notScannable.Attr.RunStyle.SYNCPublishers.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.static reactor.util.context.ContextputPendingSpan(reactor.util.context.Context context, AtomicReference<Span> span)Mutates theContextto include a mutable reference to a span.static reactor.util.context.ContextputSpanInScope(Tracer tracer, reactor.util.context.Context context, Span span)Puts the provided span in scope and in Reactor context.static Function<Runnable,Runnable>scopePassingOnScheduleHook(org.springframework.context.ConfigurableApplicationContext springContext)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.static SpanspanFromContext(Tracer tracer, CurrentTraceContext currentTraceContext, reactor.util.context.ContextView context)Retrieves span from Reactor context.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.static <T> reactor.core.publisher.Flux<T>tracedFlux(Tracer tracer, CurrentTraceContext currentTraceContext, String childSpanName, Supplier<reactor.core.publisher.Flux<T>> supplier)Wraps the given Flux in a trace representation.static <T> reactor.core.publisher.Flux<T>tracedFlux(Tracer tracer, CurrentTraceContext currentTraceContext, String childSpanName, Supplier<reactor.core.publisher.Flux<T>> supplier, BiConsumer<T,Span> spanCustomizer)Wraps the given Flux in a trace representation.static <T> reactor.core.publisher.Flux<T>tracedFlux(Tracer tracer, CurrentTraceContext currentTraceContext, String childSpanName, Supplier<reactor.core.publisher.Flux<T>> supplier, BiConsumer<T,Span> spanCustomizer, Function<Span,Span> spanFunction)Wraps the given Flux in a trace representation.static <T> reactor.core.publisher.Flux<T>tracedFlux(Tracer tracer, Span span, Supplier<reactor.core.publisher.Flux<T>> supplier)Wraps the given Flux in a trace representation.static <T> reactor.core.publisher.Mono<T>tracedMono(Tracer tracer, CurrentTraceContext currentTraceContext, String childSpanName, Supplier<reactor.core.publisher.Mono<T>> supplier)Wraps the given Mono in a trace representation.static <T> reactor.core.publisher.Mono<T>tracedMono(Tracer tracer, CurrentTraceContext currentTraceContext, String childSpanName, Supplier<reactor.core.publisher.Mono<T>> supplier, BiConsumer<T,Span> spanCustomizer)Wraps the given Mono in a trace representation.static <T> reactor.core.publisher.Mono<T>tracedMono(Tracer tracer, CurrentTraceContext currentTraceContext, String childSpanName, Supplier<reactor.core.publisher.Mono<T>> supplier, BiConsumer<T,Span> spanCustomizer, Function<Span,Span> spanFunction)Wraps the given Mono in a trace representation.static <T> reactor.core.publisher.Mono<T>tracedMono(Tracer tracer, Span span, Supplier<reactor.core.publisher.Mono<T>> supplier)Wraps the given Mono in a trace representation.static Queue<?>traceQueue(org.springframework.context.ConfigurableApplicationContext springContext, Queue<?> queue)static reactor.util.context.ContextwrapContext(reactor.util.context.Context context)Mutates the Reactor context depending on the classpath contents.
-
-
-
Field Detail
-
contextWrappingFunction
public static Function<reactor.util.context.Context,reactor.util.context.Context> contextWrappingFunction
Function that does additional wrapping of the Reactor context.
-
-
Method Detail
-
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 viaFlux.transform(Function),Mono.transform(Function),Hooks.onLastOperator(Function)orHooks.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 notScannable.Attr.RunStyle.SYNCPublishers. Used byInstrumentationType#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 byInstrumentationType#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)forInstrumentationType#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 beancurrentTraceContext- - CurrentTraceContext beanchildSpanName- - name of the created child spansupplier- - supplier of aMonoto be wrapped in tracingspanCustomizer- - 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 beancurrentTraceContext- - CurrentTraceContext beanchildSpanName- - name of the created child spansupplier- - supplier of aMonoto be wrapped in tracingspanCustomizer- - customizer for the child spanspanFunction- - 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 beancurrentTraceContext- - CurrentTraceContext beanchildSpanName- - name of the created child spansupplier- - supplier of aMonoto 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 beanspan- - span to put in contextsupplier- - supplier of aMonoto 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 beancurrentTraceContext- - CurrentTraceContext beanchildSpanName- - name of the created child spansupplier- - supplier of aFluxto be wrapped in tracingspanCustomizer- - 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 beancurrentTraceContext- - CurrentTraceContext beanchildSpanName- - name of the created child spansupplier- - supplier of aFluxto be wrapped in tracingspanCustomizer- - customizer for the child spanspanFunction- - 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 beanspan- - span to put in contextsupplier- - supplier of aFluxto 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 beancurrentTraceContext- - CurrentTraceContext beanchildSpanName- - name of the created child spansupplier- - supplier of aFluxto 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- tracercurrentTraceContext- current trace contextcontext- Reactor contextchildSpanName- child span name when there is no span in contextspanSupplier- 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- tracercurrentTraceContext- current trace contextcontext- Reactor contextchildSpanName- 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- tracercontext- Reactor contextspan- 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 theTraceContextfrom the current context.- Parameters:
context- Reactor context- Returns:
TraceContextornullif 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:
AtomicReferenceto span ornullif none present- See Also:
putPendingSpan(Context, AtomicReference)
-
putPendingSpan
public static reactor.util.context.Context putPendingSpan(reactor.util.context.Context context, AtomicReference<Span> span)Mutates theContextto 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 contextspan- 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- tracercurrentTraceContext- current trace contextcontext- context view- Returns:
- span from Reactor context or creates a new one if missing
-
-