Class MutinyTracingHelper

java.lang.Object
io.quarkus.opentelemetry.runtime.tracing.mutiny.MutinyTracingHelper

public class MutinyTracingHelper extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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)
    see wrapWithSpan(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 created
      pipeline - 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)
      see wrapWithSpan(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 created
      pipeline - the pipeline to run within the span
      Returns:
      the result of the pipeline