Struct CurrentSpan
pub struct CurrentSpan;
Expand description
Utilities for working with the currently active span.
This struct provides static methods for interacting with the current span in the thread-local context. It allows adding events, links, and attributes to the currently active span without needing a direct reference to it.
§Examples
use veecle_telemetry::{CurrentSpan, span};
let span = span!("operation");
let _guard = span.entered();
// Add an event to the current span
CurrentSpan::add_event("milestone", &[]);
Implementations§
§impl CurrentSpan
impl CurrentSpan
pub fn add_event(name: &'static str, attributes: &[KeyValue<'static>])
pub fn add_event(name: &'static str, attributes: &[KeyValue<'static>])
Adds an event to the current span.
Events represent point-in-time occurrences within a span’s lifetime.
§Arguments
name
- The name of the eventattributes
- Key-value attributes providing additional context
§Examples
use veecle_telemetry::{CurrentSpan, KeyValue, Value, span};
let _guard = span!("operation").entered();
CurrentSpan::add_event("checkpoint", &[]);
CurrentSpan::add_event("milestone", &[KeyValue::new("progress", 75)]);
Does nothing if there’s no active span.
pub fn add_link(link: SpanContext)
pub fn add_link(link: SpanContext)
Creates a link from the current span to another span. Does nothing if there’s no active span.
Links connect spans across different traces, allowing you to represent relationships between spans that are not parent-child relationships.
§Examples
use veecle_telemetry::{CurrentSpan, Span, SpanContext, SpanId, TraceId};
let _guard = Span::new("my_span", &[]).entered();
let external_context = SpanContext::new(TraceId(0x123), SpanId(0x456));
CurrentSpan::add_link(external_context);
pub fn set_attribute(attribute: KeyValue<'static>)
pub fn set_attribute(attribute: KeyValue<'static>)
Sets an attribute on the current span.
Attributes provide additional context about the work being performed in the span.
§Arguments
attribute
- The key-value attribute to set
§Examples
use veecle_telemetry::{CurrentSpan, KeyValue, Value, span};
let _guard = span!("operation").entered();
CurrentSpan::set_attribute(KeyValue::new("user_id", 123));
CurrentSpan::set_attribute(KeyValue::new("status", "success"));
Does nothing if there’s no active span.