Struct Span

pub struct Span { /* private fields */ }
Expand description

A distributed tracing span representing a unit of work.

Spans are the fundamental building blocks of distributed tracing. They represent a unit of work within a trace and can be nested to show relationships between different operations.

§Examples

use veecle_telemetry::{KeyValue, Span, Value};

// Create a span with attributes
let span = Span::new("database_query", &[
    KeyValue::new("table", Value::String("users".into())),
    KeyValue::new("operation", Value::String("SELECT".into())),
]);

// Enter the span to make it active
let _guard = span.enter();

// Add events to the span
span.add_event("query_executed", &[]);

§Conditional Compilation

When the enable feature is disabled, spans compile to no-ops with zero runtime overhead.

Implementations§

§

impl Span

pub fn noop() -> Span

Creates a no-op span that performs no tracing operations.

This is useful for creating spans that may be conditionally enabled or when telemetry is completely disabled.

pub fn new(name: &'static str, attributes: &[KeyValue<'static>]) -> Span

Creates a new span as a child of the current span.

If there is no current span, this returns a no-op span. Uses Span::root to create a root span with a specific context.

§Arguments
  • name - The name of the span
  • attributes - Key-value attributes to attach to the span
§Examples
use veecle_telemetry::{KeyValue, Span, Value};

let span = Span::new("operation", &[KeyValue::new("user_id", Value::I64(123))]);

pub fn root( name: &'static str, span_context: SpanContext, attributes: &[KeyValue<'static>], ) -> Span

Creates a new root span with the given context.

Unlike new(), this method does not use the current span from CURRENT_SPAN and creates a true root span with no parent using the provided SpanContext directly.

§Examples
use veecle_telemetry::{Span, SpanContext};

let context = SpanContext::generate();
let span = Span::root("root_span", context, &[]);

pub fn enter(&self) -> SpanGuardRef<'_>

Enters this span, making it the current active span.

This method returns a guard that will automatically exit the span when dropped. The guard borrows the span, so the span must remain alive while the guard exists.

§Examples
use veecle_telemetry::Span;

let span = Span::new("operation", &[]);
let _guard = span.enter();
// span is now active
// span is automatically exited when _guard is dropped

pub fn entered(self) -> SpanGuard

Enters this span by taking ownership of it.

This method consumes the span and returns a guard that owns the span. The span will be automatically exited and closed when the guard is dropped.

§Examples
use veecle_telemetry::Span;

let span = Span::new("operation", &[]);
let _guard = span.entered();
// span is now active and owned by the guard
// span is automatically exited and closed when _guard is dropped

pub fn add_event(&self, name: &'static str, attributes: &[KeyValue<'static>])

Adds an event to this span.

Events represent point-in-time occurrences within a span’s lifetime. They can include additional attributes for context.

§Arguments
  • name - The name of the event
  • attributes - Key-value attributes providing additional context
§Examples
use veecle_telemetry::{KeyValue, Span, Value};

let span = Span::new("database_query", &[]);
span.add_event("query_started", &[]);
span.add_event("query_completed", &[KeyValue::new("rows_returned", Value::I64(42))]);

Creates a link from this span to another span.

Links connect spans across different traces, allowing you to represent relationships between spans that are not parent-child relationships.

§Examples
use veecle_telemetry::{Span, SpanContext, SpanId, TraceId};

let span = Span::new("my_span", &[]);
let external_context = SpanContext::new(TraceId(0x123), SpanId(0x456));
span.add_link(external_context);

pub fn set_attribute(&self, attribute: KeyValue<'static>)

Adds an attribute to this span.

Attributes provide additional context about the work being performed in the span. They can be set at any time during the span’s lifetime.

§Arguments
  • attribute - The key-value attribute to set
§Examples
use veecle_telemetry::{KeyValue, Span, Value};

let span = Span::new("user_operation", &[]);
span.set_attribute(KeyValue::new("user_id", Value::I64(123)));
span.set_attribute(KeyValue::new("operation_type", Value::String("update".into())));

Trait Implementations§

§

impl Debug for Span

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for Span

§

fn default() -> Span

Returns the “default value” for a type. Read more
§

impl Drop for Span

§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Span

§

impl RefUnwindSafe for Span

§

impl Send for Span

§

impl Sync for Span

§

impl Unpin for Span

§

impl UnwindSafe for Span

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V