Interface ExtendedSpanBuilder

All Superinterfaces:
io.opentelemetry.api.trace.SpanBuilder

public interface ExtendedSpanBuilder extends io.opentelemetry.api.trace.SpanBuilder
Extended SpanBuilder with experimental APIs.
  • Method Details

    • setParentFrom

      ExtendedSpanBuilder setParentFrom(io.opentelemetry.context.propagation.ContextPropagators propagators, Map<String,String> carrier)
      Extract a span context from the given carrier and set it as parent of the span for startAndCall(SpanCallable) and startAndRun(SpanRunnable).

      The span context will be extracted from the carrier, which you usually get from HTTP headers of the metadata of a message you're processing.

      A typical usage would be: ExtendedTracer.create(tracer) .setSpanKind(SpanKind.SERVER) .setParentFrom(propagators, carrier) .run("my-span", () -> { ... });

      Parameters:
      propagators - provide the propagators from OpenTelemetry.getPropagators()
      carrier - the string map where to extract the span context from
    • startAndCall

      <T, E extends Throwable> T startAndCall(SpanCallable<T,E> spanCallable) throws E
      Runs the given SpanCallable inside of the span created by the given SpanBuilder. The span will be ended at the end of the SpanCallable.

      If an exception is thrown by the SpanCallable, the span will be marked as error, and the exception will be recorded.

      Type Parameters:
      T - the type of the result
      E - the type of the exception
      Parameters:
      spanCallable - the SpanCallable to call
      Returns:
      the result of the SpanCallable
      Throws:
      E extends Throwable
    • startAndCall

      <T, E extends Throwable> T startAndCall(SpanCallable<T,E> spanCallable, BiConsumer<io.opentelemetry.api.trace.Span,Throwable> handleException) throws E
      Runs the given SpanCallable inside of the span created by the given SpanBuilder. The span will be ended at the end of the SpanCallable.

      If an exception is thrown by the SpanCallable, the handleException consumer will be called, giving you the opportunity to handle the exception and span in a custom way, e.g. not marking the span as error.

      Type Parameters:
      T - the type of the result
      E - the type of the exception
      Parameters:
      spanCallable - the SpanCallable to call
      handleException - the consumer to call when an exception is thrown
      Returns:
      the result of the SpanCallable
      Throws:
      E extends Throwable
    • startAndRun

      <E extends Throwable> void startAndRun(SpanRunnable<E> runnable) throws E
      Runs the given SpanRunnable inside of the span created by the given SpanBuilder. The span will be ended at the end of the SpanRunnable.

      If an exception is thrown by the SpanRunnable, the span will be marked as error, and the exception will be recorded.

      Type Parameters:
      E - the type of the exception
      Parameters:
      runnable - the SpanRunnable to run
      Throws:
      E extends Throwable
    • startAndRun

      <E extends Throwable> void startAndRun(SpanRunnable<E> runnable, BiConsumer<io.opentelemetry.api.trace.Span,Throwable> handleException) throws E
      Runs the given SpanRunnable inside of the span created by the given SpanBuilder. The span will be ended at the end of the SpanRunnable.

      If an exception is thrown by the SpanRunnable, the handleException consumer will be called, giving you the opportunity to handle the exception and span in a custom way, e.g. not marking the span as error.

      Type Parameters:
      E - the type of the exception
      Parameters:
      runnable - the SpanRunnable to run
      Throws:
      E extends Throwable