Class ExtendedSpanBuilder

java.lang.Object
io.opentelemetry.api.incubator.trace.ExtendedSpanBuilder
All Implemented Interfaces:
io.opentelemetry.api.trace.SpanBuilder

public final class ExtendedSpanBuilder extends Object implements io.opentelemetry.api.trace.SpanBuilder
  • Method Details

    • setParent

      public ExtendedSpanBuilder setParent(io.opentelemetry.context.Context context)
      Specified by:
      setParent in interface io.opentelemetry.api.trace.SpanBuilder
    • setNoParent

      public ExtendedSpanBuilder setNoParent()
      Specified by:
      setNoParent in interface io.opentelemetry.api.trace.SpanBuilder
    • addLink

      public ExtendedSpanBuilder addLink(io.opentelemetry.api.trace.SpanContext spanContext)
      Specified by:
      addLink in interface io.opentelemetry.api.trace.SpanBuilder
    • addLink

      public ExtendedSpanBuilder addLink(io.opentelemetry.api.trace.SpanContext spanContext, io.opentelemetry.api.common.Attributes attributes)
      Specified by:
      addLink in interface io.opentelemetry.api.trace.SpanBuilder
    • setAttribute

      public ExtendedSpanBuilder setAttribute(String key, String value)
      Specified by:
      setAttribute in interface io.opentelemetry.api.trace.SpanBuilder
    • setAttribute

      public ExtendedSpanBuilder setAttribute(String key, long value)
      Specified by:
      setAttribute in interface io.opentelemetry.api.trace.SpanBuilder
    • setAttribute

      public ExtendedSpanBuilder setAttribute(String key, double value)
      Specified by:
      setAttribute in interface io.opentelemetry.api.trace.SpanBuilder
    • setAttribute

      public ExtendedSpanBuilder setAttribute(String key, boolean value)
      Specified by:
      setAttribute in interface io.opentelemetry.api.trace.SpanBuilder
    • setAttribute

      public <T> ExtendedSpanBuilder setAttribute(io.opentelemetry.api.common.AttributeKey<T> key, T value)
      Specified by:
      setAttribute in interface io.opentelemetry.api.trace.SpanBuilder
    • setAllAttributes

      public ExtendedSpanBuilder setAllAttributes(io.opentelemetry.api.common.Attributes attributes)
      Specified by:
      setAllAttributes in interface io.opentelemetry.api.trace.SpanBuilder
    • setSpanKind

      public ExtendedSpanBuilder setSpanKind(io.opentelemetry.api.trace.SpanKind spanKind)
      Specified by:
      setSpanKind in interface io.opentelemetry.api.trace.SpanBuilder
    • setStartTimestamp

      public ExtendedSpanBuilder setStartTimestamp(long startTimestamp, TimeUnit unit)
      Specified by:
      setStartTimestamp in interface io.opentelemetry.api.trace.SpanBuilder
    • setStartTimestamp

      public ExtendedSpanBuilder setStartTimestamp(Instant startTimestamp)
      Specified by:
      setStartTimestamp in interface io.opentelemetry.api.trace.SpanBuilder
    • setParentFrom

      public 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
    • startSpan

      public io.opentelemetry.api.trace.Span startSpan()
      Specified by:
      startSpan in interface io.opentelemetry.api.trace.SpanBuilder
    • startAndCall

      public <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

      public <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

      public <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

      public <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