Class MutinyTracingHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> io.smallrye.mutiny.Uni<T> wrapWithSpan(io.opentelemetry.api.trace.Tracer tracer, String spanName, io.smallrye.mutiny.Uni<T> pipeline) Wraps the given pipeline with a span with the given name.static <T> io.smallrye.mutiny.Uni<T> wrapWithSpan(io.opentelemetry.api.trace.Tracer tracer, Optional<io.opentelemetry.context.Context> parentContext, String spanName, io.smallrye.mutiny.Uni<T> pipeline) seewrapWithSpan(Tracer, String, Uni)use this method if you manually want to specify the parent context of the new span or if you want to ensure the new span is a root span.
-
Constructor Details
-
MutinyTracingHelper
public MutinyTracingHelper()
-
-
Method Details
-
wrapWithSpan
public static <T> io.smallrye.mutiny.Uni<T> wrapWithSpan(io.opentelemetry.api.trace.Tracer tracer, String spanName, io.smallrye.mutiny.Uni<T> pipeline) Wraps the given pipeline with a span with the given name. Ensures that subspans find the current span as context, by running on a duplicated context. The span will be closed when the pipeline completes. If there is already a span in the current context, it will be used as parent for the new span.Use as follows: Given this existing pipeline: ```java Uni.createFrom().item("Hello") .onItem().transform(s -> s + " World") .subscribe().with(System.out::println); ``` wrap like this: ```java Uni.createFrom().item("Hello") .onItem().transformToUni(s -> wrapWithSpan(tracer, "mySpan", Uni.createFrom().item(s + " World"))) .subscribe().with(System.out::println); ```
it also works with multi: ```java Multi.createFrom().items("Alice", "Bob", "Charlie") .onItem().transform(name -> "Hello " + name) .subscribe().with(System.out::println); ``` wrap like this: ```java Multi.createFrom().items("Alice", "Bob", "Charlie") .onItem().transformToUni(s -> wrapWithSpan(tracer, "mySpan", Uni.createFrom().item("Hello " + s) .onItem().transform(name -> "Hello " + name) )) .subscribe().with(System.out::println); ```
- Type Parameters:
T- the type of the result of the pipeline- Parameters:
spanName- the name of the span that should be createdpipeline- the pipeline to run within the span- Returns:
- the result of the pipeline
-
wrapWithSpan
public static <T> io.smallrye.mutiny.Uni<T> wrapWithSpan(io.opentelemetry.api.trace.Tracer tracer, Optional<io.opentelemetry.context.Context> parentContext, String spanName, io.smallrye.mutiny.Uni<T> pipeline) seewrapWithSpan(Tracer, String, Uni)use this method if you manually want to specify the parent context of the new span or if you want to ensure the new span is a root span.- Type Parameters:
T-- Parameters:
parentContext- the parent context to use for the new span. If empty, a new root span will be created.spanName- the name of the span that should be createdpipeline- the pipeline to run within the span- Returns:
- the result of the pipeline
-