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 new() -> TraceContext
pub fn new() -> TraceContext
Create a new trace context with a generated request ID.
Sourcepub fn with_request_id(request_id: impl Into<String>) -> TraceContext
pub fn with_request_id(request_id: impl Into<String>) -> TraceContext
Create a trace context with a specific request ID.
Sourcepub fn child(&self) -> TraceContext
pub fn child(&self) -> TraceContext
Create a child context (new span under same trace).
Sourcepub fn with_device_id(self, device_id: impl Into<String>) -> TraceContext
pub fn with_device_id(self, device_id: impl Into<String>) -> TraceContext
Set the device ID.
Sourcepub fn with_protocol(self, protocol: impl Into<String>) -> TraceContext
pub fn with_protocol(self, protocol: impl Into<String>) -> TraceContext
Set the protocol.
Sourcepub fn with_operation(self, operation: impl Into<String>) -> TraceContext
pub fn with_operation(self, operation: impl Into<String>) -> TraceContext
Set the operation name.
Sourcepub fn with_trace_id(self, trace_id: impl Into<String>) -> TraceContext
pub fn with_trace_id(self, trace_id: impl Into<String>) -> TraceContext
Set the trace ID (for integration with distributed tracing).
Sourcepub fn with_field(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> TraceContext
pub fn with_field( self, key: impl Into<String>, value: impl Into<String>, ) -> TraceContext
Add a custom field.
Sourcepub fn with_fields(
self,
fields: impl IntoIterator<Item = (String, String)>,
) -> TraceContext
pub fn with_fields( self, fields: impl IntoIterator<Item = (String, String)>, ) -> TraceContext
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>) -> TraceContext
pub fn from_headers(headers: &HashMap<String, String>) -> TraceContext
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 moreSource§impl Debug for TraceContext
impl Debug for TraceContext
Source§impl Default for TraceContext
impl Default for TraceContext
Source§fn default() -> TraceContext
fn default() -> TraceContext
Source§impl<'de> Deserialize<'de> for TraceContext
impl<'de> Deserialize<'de> for TraceContext
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<TraceContext, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<TraceContext, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for TraceContext
impl Serialize for TraceContext
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for TraceContext
impl RefUnwindSafe for TraceContext
impl Send for TraceContext
impl Sync for TraceContext
impl Unpin for TraceContext
impl UnwindSafe for TraceContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more