Class DefaultTracer.NoopSpanBuilder

java.lang.Object
io.opentelemetry.api.trace.DefaultTracer.NoopSpanBuilder
All Implemented Interfaces:
SpanBuilder
Enclosing class:
DefaultTracer

private static final class DefaultTracer.NoopSpanBuilder extends Object implements SpanBuilder
  • Field Details

  • Constructor Details

    • NoopSpanBuilder

      private NoopSpanBuilder()
  • Method Details

    • create

    • startSpan

      public Span startSpan()
      Description copied from interface: SpanBuilder
      Starts a new Span.

      Users must manually call Span.end() to end this Span.

      Does not install the newly created Span to the current Context.

      IMPORTANT: This method can be called only once per SpanBuilder instance and as the last method called. After this method is called calling any method is undefined behavior.

      Example of usage:

      
       class MyClass {
         private final Tracer tracer;
      
         MyClass(OpenTelemetry openTelemetry) {
           tracer = openTelemetry.getTracer("com.example.rpc");
         }
      
         void doWork(Span parent) {
           Span childSpan = tracer.spanBuilder("MyChildSpan")
                .setParent(Context.current().with(parent))
                .startSpan();
           childSpan.addEvent("my event");
           try {
             doSomeWork(childSpan); // Manually propagate the new span down the stack.
           } finally {
             // To make sure we end the span even in case of an exception.
             childSpan.end();  // Manually end the span.
           }
         }
       }
       
      Specified by:
      startSpan in interface SpanBuilder
      Returns:
      the newly created Span.
    • setParent

      public DefaultTracer.NoopSpanBuilder setParent(Context context)
      Description copied from interface: SpanBuilder
      Sets the parent to use from the specified Context. If not set, the value of Span.current() at SpanBuilder.startSpan() time will be used as parent.

      If no Span is available in the specified Context, the resulting Span will become a root instance, as if SpanBuilder.setNoParent() had been called.

      If called multiple times, only the last specified value will be used. Observe that the state defined by a previous call to SpanBuilder.setNoParent() will be discarded.

      Specified by:
      setParent in interface SpanBuilder
      Parameters:
      context - the Context.
      Returns:
      this.
    • setNoParent

      public DefaultTracer.NoopSpanBuilder setNoParent()
      Description copied from interface: SpanBuilder
      Sets the option to become a root Span for a new trace. If not set, the value of Span.current() at SpanBuilder.startSpan() time will be used as parent.

      Observe that any previously set parent will be discarded.

      Specified by:
      setNoParent in interface SpanBuilder
      Returns:
      this.
    • addLink

      public DefaultTracer.NoopSpanBuilder addLink(SpanContext spanContext)
      Description copied from interface: SpanBuilder
      Adds a link to the newly created Span.

      Links are used to link Spans in different traces. Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces or the same trace.

      Implementations may ignore calls with an invalid span context.

      Specified by:
      addLink in interface SpanBuilder
      Parameters:
      spanContext - the context of the linked Span.
      Returns:
      this.
    • addLink

      public DefaultTracer.NoopSpanBuilder addLink(SpanContext spanContext, Attributes attributes)
      Description copied from interface: SpanBuilder
      Adds a link to the newly created Span.

      Links are used to link Spans in different traces. Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces or the same trace.

      Implementations may ignore calls with an invalid span context.

      Specified by:
      addLink in interface SpanBuilder
      Parameters:
      spanContext - the context of the linked Span.
      attributes - the attributes of the Link.
      Returns:
      this.
    • setAttribute

      public DefaultTracer.NoopSpanBuilder setAttribute(String key, String value)
      Description copied from interface: SpanBuilder
      Sets an attribute to the newly created Span. If SpanBuilder previously contained a mapping for the key, the old value is replaced by the specified value.

      If a null or empty String value is passed in, the behavior is undefined, and hence strongly discouraged.

      Note: It is strongly recommended to use SpanBuilder.setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.

      Specified by:
      setAttribute in interface SpanBuilder
      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
    • setAttribute

      public DefaultTracer.NoopSpanBuilder setAttribute(String key, long value)
      Description copied from interface: SpanBuilder
      Sets an attribute to the newly created Span. If SpanBuilder previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: It is strongly recommended to use SpanBuilder.setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.

      Specified by:
      setAttribute in interface SpanBuilder
      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
    • setAttribute

      public DefaultTracer.NoopSpanBuilder setAttribute(String key, double value)
      Description copied from interface: SpanBuilder
      Sets an attribute to the newly created Span. If SpanBuilder previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: It is strongly recommended to use SpanBuilder.setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.

      Specified by:
      setAttribute in interface SpanBuilder
      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
    • setAttribute

      public DefaultTracer.NoopSpanBuilder setAttribute(String key, boolean value)
      Description copied from interface: SpanBuilder
      Sets an attribute to the newly created Span. If SpanBuilder previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: It is strongly recommended to use SpanBuilder.setAttribute(AttributeKey, Object), and pre-allocate your keys, if possible.

      Specified by:
      setAttribute in interface SpanBuilder
      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
    • setAttribute

      public <T> DefaultTracer.NoopSpanBuilder setAttribute(AttributeKey<T> key, T value)
      Description copied from interface: SpanBuilder
      Sets an attribute to the newly created Span. If SpanBuilder previously contained a mapping for the key, the old value is replaced by the specified value.

      Note: the behavior of null values is undefined, and hence strongly discouraged.

      Specified by:
      setAttribute in interface SpanBuilder
      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
      Returns:
      this.
    • setAllAttributes

      public DefaultTracer.NoopSpanBuilder setAllAttributes(Attributes attributes)
      Description copied from interface: SpanBuilder
      Sets attributes to the SpanBuilder. If the SpanBuilder previously contained a mapping for any of the keys, the old values are replaced by the specified values.
      Specified by:
      setAllAttributes in interface SpanBuilder
      Parameters:
      attributes - the attributes
      Returns:
      this.
    • setSpanKind

      public DefaultTracer.NoopSpanBuilder setSpanKind(SpanKind spanKind)
      Description copied from interface: SpanBuilder
      Sets the SpanKind for the newly created Span. If not called, the implementation will provide a default value SpanKind.INTERNAL.
      Specified by:
      setSpanKind in interface SpanBuilder
      Parameters:
      spanKind - the kind of the newly created Span.
      Returns:
      this.
    • setStartTimestamp

      public DefaultTracer.NoopSpanBuilder setStartTimestamp(long startTimestamp, TimeUnit unit)
      Description copied from interface: SpanBuilder
      Sets an explicit start timestamp for the newly created Span.

      LIRInstruction.Use this method to specify an explicit start timestamp. If not called, the implementation will use the timestamp value at SpanBuilder.startSpan() time, which should be the default case.

      Important this is NOT equivalent with System.nanoTime().

      Specified by:
      setStartTimestamp in interface SpanBuilder
      Parameters:
      startTimestamp - the explicit start timestamp from the epoch of the newly created Span.
      unit - the unit of the timestamp.
      Returns:
      this.