pub struct OperationContext { /* private fields */ }Expand description
Tracks observability context for a single operation.
Mirrors Go’s observability.OperationContext.
Implementations§
Source§impl OperationContext
impl OperationContext
Sourcepub fn new(
service: impl Into<String>,
operation: impl Into<String>,
request_id: impl Into<String>,
user_id: impl Into<String>,
) -> Self
pub fn new( service: impl Into<String>, operation: impl Into<String>, request_id: impl Into<String>, user_id: impl Into<String>, ) -> Self
Create a new operation context.
Sourcepub fn with_metrics(self, metrics: Arc<MetricsHandle>) -> Self
pub fn with_metrics(self, metrics: Arc<MetricsHandle>) -> Self
Attach a metrics handle to this context.
Sourcepub fn service_name(&self) -> &str
pub fn service_name(&self) -> &str
Name of the service performing the operation.
Sourcepub fn operation_name(&self) -> &str
pub fn operation_name(&self) -> &str
Name of the operation being performed.
Sourcepub fn request_id(&self) -> &str
pub fn request_id(&self) -> &str
Unique request identifier for correlation.
Sourcepub fn user_id(&self) -> &str
pub fn user_id(&self) -> &str
Identifier of the user initiating the request.
This is retained for caller-side correlation and is not emitted to spans by default to avoid leaking user identifiers into telemetry backends.
Sourcepub fn start_span(&self, name: &str) -> Span
pub fn start_span(&self, name: &str) -> Span
Create a tracing span for a sub-operation.
Sourcepub fn end_operation(&self, status: &str, error: Option<&AppError>)
pub fn end_operation(&self, status: &str, error: Option<&AppError>)
Record the end of the operation with status and optional error.
Auto Trait Implementations§
impl !RefUnwindSafe for OperationContext
impl !UnwindSafe for OperationContext
impl Freeze for OperationContext
impl Send for OperationContext
impl Sync for OperationContext
impl Unpin for OperationContext
impl UnsafeUnpin for OperationContext
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request