pub trait ObjectSafeSpan {
    // Required methods
    fn add_event_with_timestamp(
        &mut self,
        name: Cow<'static, str>,
        timestamp: SystemTime,
        attributes: Vec<KeyValue>
    );
    fn span_context(&self) -> &SpanContext;
    fn is_recording(&self) -> bool;
    fn set_attribute(&mut self, attribute: KeyValue);
    fn set_status(&mut self, status: Status);
    fn update_name(&mut self, new_name: Cow<'static, str>);
    fn end_with_timestamp(&mut self, timestamp: SystemTime);

    // Provided method
    fn end(&mut self) { ... }
}
Expand description

Allows a specific crate::trace::Span to be used generically by BoxedSpan instances by mirroring the interface and boxing the return types.

Required Methods§

source

fn add_event_with_timestamp( &mut self, name: Cow<'static, str>, timestamp: SystemTime, attributes: Vec<KeyValue> )

An API to record events at a specific time in the context of a given Span.

Events SHOULD preserve the order in which they’re set. This will typically match the ordering of the events’ timestamps.

Note that the OpenTelemetry project documents certain “standard event names and keys” which have prescribed semantic meanings.

source

fn span_context(&self) -> &SpanContext

Returns the SpanContext for the given Span. The returned value may be used even after the Span is finished. The returned value MUST be the same for the entire Span` lifetime.

source

fn is_recording(&self) -> bool

Returns true if this Span is recording information like events with the add_event operation, attributes using set_attributes, status with set_status, etc.

This flag SHOULD be used to avoid expensive computations of a Span attributes or events in case when a Span is definitely not recorded. Note that any child span’s recording is determined independently from the value of this flag (typically based on the sampled flag of a TraceFlag on SpanContext).

This flag may be true despite the entire trace being sampled out. This allows to record and process information about the individual Span without sending it to the backend. An example of this scenario may be recording and processing of all incoming requests for the processing and building of SLA/SLO latency charts while sending only a subset - sampled spans - to the backend. See also the sampling section of SDK design.

Users of the API should only access the is_recording property when instrumenting code and never access SampledFlag unless used in context propagators.

source

fn set_attribute(&mut self, attribute: KeyValue)

An API to set a single Attribute where the attribute properties are passed as arguments. To avoid extra allocations some implementations may offer a separate API for each of the possible value types.

An Attribute is defined as a KeyValue pair.

Attributes SHOULD preserve the order in which they’re set. Setting an attribute with the same key as an existing attribute SHOULD overwrite the existing attribute’s value.

Note that the OpenTelemetry project documents certain “standard attributes” that have prescribed semantic meanings.

source

fn set_status(&mut self, status: Status)

Sets the status of the Span. message MUST be ignored when the status is OK or Unset.

The order of status is Ok > Error > Unset. That’s means set the status to Unset will always be ignore, set the status to Error only works when current status is Unset, set the status to Ok will be consider final and any further call to this function will be ignore.

source

fn update_name(&mut self, new_name: Cow<'static, str>)

Updates the Span’s name. After this update, any sampling behavior based on the name will depend on the implementation.

It is highly discouraged to update the name of a Span after its creation. Span name is often used to group, filter and identify the logical groups of spans. Often, filtering logic will be implemented before the Span creation for performance reasons, and the name update may interfere with this logic.

The method name is called update_name to differentiate this method from the regular property. It emphasizes that this operation signifies a major change for a Span and may lead to re-calculation of sampling or filtering decisions made previously depending on the implementation.

source

fn end_with_timestamp(&mut self, timestamp: SystemTime)

Finishes the Span with given timestamp

For more details, refer to Span::end

Provided Methods§

source

fn end(&mut self)

Finishes the Span.

Implementations MUST ignore all subsequent calls to end (there might be exceptions when the tracer is streaming events and has no mutable state associated with the Span).

Calls to end a Span MUST not have any effects on child Spans as they may still be running and can be ended later.

This API MUST be non-blocking.

Implementors§