pub struct TraceContext {
pub request_id: String,
pub trace_id: Option<String>,
pub span_id: Option<String>,
pub parent_span_id: Option<String>,
pub device_id: Option<String>,
pub protocol: Option<String>,
pub operation: Option<String>,
pub fields: HashMap<String, String>,
pub created_at: u64,
}Expand description
Trace context for distributed tracing.
This struct carries context information that should be propagated across async boundaries and potentially across service boundaries.
Fields§
§request_id: StringUnique request/correlation ID.
trace_id: Option<String>Trace ID (for distributed tracing systems).
span_id: Option<String>Span ID (for distributed tracing systems).
parent_span_id: Option<String>Parent span ID.
device_id: Option<String>Device ID (if applicable).
protocol: Option<String>Protocol name (if applicable).
operation: Option<String>Operation name.
fields: HashMap<String, String>Custom fields.
created_at: u64Timestamp when context was created.
Implementations§
Source§impl TraceContext
impl TraceContext
Sourcepub fn with_request_id(request_id: impl Into<String>) -> Self
pub fn with_request_id(request_id: impl Into<String>) -> Self
Create a trace context with a specific request ID.
Sourcepub fn with_device_id(self, device_id: impl Into<String>) -> Self
pub fn with_device_id(self, device_id: impl Into<String>) -> Self
Set the device ID.
Sourcepub fn with_protocol(self, protocol: impl Into<String>) -> Self
pub fn with_protocol(self, protocol: impl Into<String>) -> Self
Set the protocol.
Sourcepub fn with_operation(self, operation: impl Into<String>) -> Self
pub fn with_operation(self, operation: impl Into<String>) -> Self
Set the operation name.
Sourcepub fn with_trace_id(self, trace_id: impl Into<String>) -> Self
pub fn with_trace_id(self, trace_id: impl Into<String>) -> Self
Set the trace ID (for integration with distributed tracing).
Sourcepub fn with_field(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_field( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add a custom field.
Sourcepub fn with_fields(
self,
fields: impl IntoIterator<Item = (String, String)>,
) -> Self
pub fn with_fields( self, fields: impl IntoIterator<Item = (String, String)>, ) -> Self
Add multiple custom fields.
Sourcepub fn create_span(&self, name: &'static str) -> Span
pub fn create_span(&self, name: &'static str) -> Span
Create a tracing span with this context.
Sourcepub fn create_debug_span(&self, name: &'static str) -> Span
pub fn create_debug_span(&self, name: &'static str) -> Span
Create a debug-level span (for less critical operations).
Sourcepub fn is_older_than_ms(&self, ms: u64) -> bool
pub fn is_older_than_ms(&self, ms: u64) -> bool
Check if this context is older than the given milliseconds.
Sourcepub fn from_headers(headers: &HashMap<String, String>) -> Self
pub fn from_headers(headers: &HashMap<String, String>) -> Self
Parse from HTTP headers (for distributed tracing).
Sourcepub fn to_headers(&self) -> HashMap<String, String>
pub fn to_headers(&self) -> HashMap<String, String>
Convert to HTTP headers (for distributed tracing).
Trait Implementations§
Source§impl Clone for TraceContext
impl Clone for TraceContext
Source§fn clone(&self) -> TraceContext
fn clone(&self) -> TraceContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more