Class RecordEventsSpanImpl

java.lang.Object
io.opencensus.trace.Span
io.opencensus.implcore.trace.RecordEventsSpanImpl
All Implemented Interfaces:
ConcurrentIntrusiveList.Element<RecordEventsSpanImpl>

@ThreadSafe public final class RecordEventsSpanImpl extends Span implements ConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
Implementation for the Span class that records trace events.
  • Method Details

    • startSpan

      public static RecordEventsSpanImpl startSpan(SpanContext context, String name, @Nullable Span.Kind kind, @Nullable SpanId parentSpanId, @Nullable Boolean hasRemoteParent, TraceParams traceParams, RecordEventsSpanImpl.StartEndHandler startEndHandler, @Nullable TimestampConverter timestampConverter, Clock clock)
      Creates and starts a span with the given configuration.
      Parameters:
      context - supplies the trace_id and span_id for the newly started span.
      name - the displayed name for the new span.
      parentSpanId - the span_id of the parent span, or null if the new span is a root span.
      hasRemoteParent - true if the parentContext is remote. null if this is a root span.
      traceParams - trace parameters like sampler and probability.
      startEndHandler - handler called when the span starts and ends.
      timestampConverter - null if the span is a root span or the parent is not sampled. If the parent is sampled, we should use the same converter to ensure ordering between tracing events.
      clock - the clock used to get the time.
      Returns:
      a new and started span.
    • getName

      public String getName()
      Returns the name of the Span.
      Returns:
      the name of the Span.
    • getStatus

      public Status getStatus()
      Returns the status of the Span. If not set defaults to Status.OK.
      Returns:
      the status of the Span.
    • getEndNanoTime

      public long getEndNanoTime()
      Returns the end nano time (see System.nanoTime()). If the current Span is not ended then returns Clock.nowNanos().
      Returns:
      the end nano time.
    • getLatencyNs

      public long getLatencyNs()
      Returns the latency of the Span in nanos. If still active then returns now() - start time.
      Returns:
      the latency of the Span in nanos.
    • getSampleToLocalSpanStore

      public boolean getSampleToLocalSpanStore()
      Returns if the name of this Span must be register to the SampledSpanStore.
      Returns:
      if the name of this Span must be register to the SampledSpanStore.
    • getKind

      @Nullable public Span.Kind getKind()
      Returns the kind of this Span.
      Returns:
      the kind of this Span.
    • toSpanData

      public SpanData toSpanData()
      Returns an immutable representation of all the data from this Span.
      Returns:
      an immutable representation of all the data from this Span.
      Throws:
      IllegalStateException - if the Span doesn't have RECORD_EVENTS option.
    • putAttribute

      public void putAttribute(String key, AttributeValue value)
      Description copied from class: Span
      Sets an attribute to the Span. If the Span previously contained a mapping for the key, the old value is replaced by the specified value.
      Overrides:
      putAttribute in class Span
      Parameters:
      key - the key for this attribute.
      value - the value for this attribute.
    • putAttributes

      public void putAttributes(Map<String, AttributeValue> attributes)
      Description copied from class: Span
      Sets a set of attributes to the Span. The effect of this call is equivalent to that of calling Span.putAttribute(String, AttributeValue) once for each element in the specified map.
      Overrides:
      putAttributes in class Span
      Parameters:
      attributes - the attributes that will be added and associated with the Span.
    • addAnnotation

      public void addAnnotation(String description, Map<String, AttributeValue> attributes)
      Description copied from class: Span
      Adds an annotation to the Span.
      Specified by:
      addAnnotation in class Span
      Parameters:
      description - the description of the annotation time event.
      attributes - the attributes that will be added; these are associated with this annotation, not the Span as for Span.putAttributes(Map).
    • addAnnotation

      public void addAnnotation(Annotation annotation)
      Description copied from class: Span
      Adds an annotation to the Span.
      Specified by:
      addAnnotation in class Span
      Parameters:
      annotation - the annotations to add.
    • addMessageEvent

      public void addMessageEvent(MessageEvent messageEvent)
      Description copied from class: Span
      Adds a MessageEvent to the Span.

      This function can be used by higher level applications to record messaging event.

      This method should always be overridden by users whose API versions are larger or equal to 0.12.

      Overrides:
      addMessageEvent in class Span
      Parameters:
      messageEvent - the message to add.
    • addLink

      public void addLink(Link link)
      Description copied from class: Span
      Adds a Link to the Span.

      Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces.

      Specified by:
      addLink in class Span
      Parameters:
      link - the link to add.
    • setStatus

      public void setStatus(Status status)
      Description copied from class: Span
      Sets the Status to the Span.

      If used, this will override the default Span status. Default is Status.OK.

      Only the value of the last call will be recorded, and implementations are free to ignore previous calls. If the status is set via EndSpanOptions.Builder.setStatus(Status) that will always be the last call.

      Overrides:
      setStatus in class Span
      Parameters:
      status - the Status to set.
    • end

      public void end(EndSpanOptions options)
      Description copied from class: Span
      Marks the end of Span execution with the given options.

      Only the timing of the first end call for a given Span will be recorded, and implementations are free to ignore all further calls.

      Specified by:
      end in class Span
      Parameters:
      options - the options to be used for the end of the Span.
    • getNext

      @Nullable public RecordEventsSpanImpl getNext()
      Description copied from interface: ConcurrentIntrusiveList.Element
      Returns a reference to the next element in the list.
      Specified by:
      getNext in interface ConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
      Returns:
      a reference to the next element in the list.
    • setNext

      public void setNext(@Nullable RecordEventsSpanImpl element)
      Description copied from interface: ConcurrentIntrusiveList.Element
      Sets the reference to the next element in the list.
      Specified by:
      setNext in interface ConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
      Parameters:
      element - the reference to the next element in the list.
    • getPrev

      @Nullable public RecordEventsSpanImpl getPrev()
      Description copied from interface: ConcurrentIntrusiveList.Element
      Returns a reference to the previous element in the list.
      Specified by:
      getPrev in interface ConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
      Returns:
      a reference to the previous element in the list.
    • setPrev

      public void setPrev(@Nullable RecordEventsSpanImpl element)
      Description copied from interface: ConcurrentIntrusiveList.Element
      Sets the reference to the previous element in the list.
      Specified by:
      setPrev in interface ConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
      Parameters:
      element - the reference to the previous element in the list.