pub struct RequestContext {
pub request_id: Uuid,
pub correlation_id: Uuid,
pub parent_id: Option<Uuid>,
pub session_id: Option<Uuid>,
pub user_id: Option<Uuid>,
pub started_at: DateTime<Utc>,
pub source: String,
pub operation: Option<String>,
pub metadata: HashMap<String, String>,
}Expand description
Request context for correlation across operations.
This struct carries context information that should be propagated through the system for tracing and debugging purposes.
Fields§
§request_id: UuidUnique request identifier.
correlation_id: UuidCorrelation ID for tracing related requests.
parent_id: Option<Uuid>Parent request ID if this is a sub-request.
session_id: Option<Uuid>Session ID if within a session.
user_id: Option<Uuid>User ID if authenticated.
started_at: DateTime<Utc>When the request started.
source: StringSource component that created this context.
operation: Option<String>Operation being performed.
metadata: HashMap<String, String>Additional metadata.
Implementations§
Source§impl RequestContext
impl RequestContext
Sourcepub fn child(&self, source: impl Into<String>) -> Self
pub fn child(&self, source: impl Into<String>) -> Self
Create a child context that inherits correlation info.
Sourcepub fn with_correlation_id(self, id: Uuid) -> Self
pub fn with_correlation_id(self, id: Uuid) -> Self
Set the correlation ID.
Sourcepub fn with_session_id(self, id: Uuid) -> Self
pub fn with_session_id(self, id: Uuid) -> Self
Set the session ID.
Sourcepub fn with_user_id(self, id: Uuid) -> Self
pub fn with_user_id(self, id: Uuid) -> Self
Set the user ID.
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_metadata(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add metadata.
Sourcepub fn elapsed_ms(&self) -> i64
pub fn elapsed_ms(&self) -> i64
Get elapsed time in milliseconds.
Sourcepub fn has_parent(&self) -> bool
pub fn has_parent(&self) -> bool
Check if this context has a parent.
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
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 RequestContext
impl Debug for RequestContext
Source§impl Default for RequestContext
impl Default for RequestContext
Source§impl<'de> Deserialize<'de> for RequestContext
impl<'de> Deserialize<'de> for RequestContext
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for RequestContext
impl RefUnwindSafe for RequestContext
impl Send for RequestContext
impl Sync for RequestContext
impl Unpin for RequestContext
impl UnsafeUnpin for RequestContext
impl UnwindSafe for RequestContext
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