pub struct TraceGenerator { /* private fields */ }Expand description
Trace ID generator and manager with sampling support
Implementations§
Source§impl TraceGenerator
impl TraceGenerator
Sourcepub fn with_sampling(sampling_config: SamplingConfig) -> Result<Self>
pub fn with_sampling(sampling_config: SamplingConfig) -> Result<Self>
Create a new trace generator with custom sampling
Sourcepub fn generate_trace_id() -> String
pub fn generate_trace_id() -> String
Generate a new trace ID with panic recovery
Sourcepub fn generate_span_id() -> String
pub fn generate_span_id() -> String
Generate a new span ID
Sourcepub async fn should_sample(&self, is_critical: bool) -> bool
pub async fn should_sample(&self, is_critical: bool) -> bool
Determine if a trace should be sampled based on configuration
Sourcepub fn parse_trace_context(header: &str) -> Result<PropagationContext>
pub fn parse_trace_context(header: &str) -> Result<PropagationContext>
Parse W3C Trace Context header
Sourcepub async fn create_span(
&self,
trace_id: String,
operation_name: impl Into<String>,
parent_span_id: Option<String>,
attributes: Option<HashMap<String, String>>,
) -> Result<TraceSpan>
pub async fn create_span( &self, trace_id: String, operation_name: impl Into<String>, parent_span_id: Option<String>, attributes: Option<HashMap<String, String>>, ) -> Result<TraceSpan>
Create a new trace span with optional sampling check
Sourcepub async fn add_span_event(
&self,
span_id: &str,
event_name: impl Into<String>,
attributes: HashMap<String, String>,
) -> Result<()>
pub async fn add_span_event( &self, span_id: &str, event_name: impl Into<String>, attributes: HashMap<String, String>, ) -> Result<()>
Add an event to a span
Sourcepub async fn mark_span_active(&self, span_id: &str) -> Result<()>
pub async fn mark_span_active(&self, span_id: &str) -> Result<()>
Mark a span as active
Sourcepub async fn complete_span(
&self,
span_id: &str,
error: Option<String>,
) -> Result<u64>
pub async fn complete_span( &self, span_id: &str, error: Option<String>, ) -> Result<u64>
Complete a span with optional error
Sourcepub async fn add_span_attribute(
&self,
span_id: &str,
key: String,
value: String,
) -> Result<()>
pub async fn add_span_attribute( &self, span_id: &str, key: String, value: String, ) -> Result<()>
Add attribute to a span
Sourcepub async fn add_span_attributes(
&self,
span_id: &str,
attributes: HashMap<String, String>,
) -> Result<()>
pub async fn add_span_attributes( &self, span_id: &str, attributes: HashMap<String, String>, ) -> Result<()>
Add multiple attributes to a span
Sourcepub async fn get_trace_spans(&self, trace_id: &str) -> Result<Vec<TraceSpan>>
pub async fn get_trace_spans(&self, trace_id: &str) -> Result<Vec<TraceSpan>>
Get all spans for a trace
Sourcepub async fn get_trace_metadata(&self, trace_id: &str) -> Result<TraceMetadata>
pub async fn get_trace_metadata(&self, trace_id: &str) -> Result<TraceMetadata>
Get trace metadata
Sourcepub async fn export_trace(&self, trace_id: &str) -> Result<String>
pub async fn export_trace(&self, trace_id: &str) -> Result<String>
Export trace in JSON format
Sourcepub async fn cleanup_old_spans(
&self,
older_than_ms: Option<u64>,
) -> Result<usize>
pub async fn cleanup_old_spans( &self, older_than_ms: Option<u64>, ) -> Result<usize>
Clean up old spans (older than specified milliseconds)
Sourcepub async fn get_statistics(&self) -> TraceStatistics
pub async fn get_statistics(&self) -> TraceStatistics
Get trace statistics
Trait Implementations§
Source§impl Clone for TraceGenerator
impl Clone for TraceGenerator
Source§fn clone(&self) -> TraceGenerator
fn clone(&self) -> TraceGenerator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TraceGenerator
impl Debug for TraceGenerator
Auto Trait Implementations§
impl Freeze for TraceGenerator
impl !RefUnwindSafe for TraceGenerator
impl Send for TraceGenerator
impl Sync for TraceGenerator
impl Unpin for TraceGenerator
impl !UnwindSafe for TraceGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].