pub struct RequestContext { /* private fields */ }Expand description
The one and only context passed to every handler.
Carries a full W3C distributed-tracing context:
trace_id(16 bytes) – preserved across the entire distributed call chain.span_id(8 bytes) – this server hop’s span; becomesparent-iddownstream.parent_span_id– the upstream caller’s span (all-zeros = root span).
Use traceparent to generate the header for outgoing calls.
Implementations§
Source§impl RequestContext
impl RequestContext
pub fn method(&self) -> &Method
pub fn path(&self) -> &str
pub fn query_string(&self) -> Option<&str>
pub fn body(&self) -> &Bytes
pub fn trace_id(&self) -> [u8; 16]
Sourcepub fn parent_span_id(&self) -> Option<[u8; 8]>
pub fn parent_span_id(&self) -> Option<[u8; 8]>
The incoming caller’s span ID, or None for root (origin) spans.
pub fn claims(&self) -> Option<&Claims>
Sourcepub fn session(&self) -> Option<&Arc<Session>>
pub fn session(&self) -> Option<&Arc<Session>>
The server-side session loaded for this request, if any.
Some only when SessionManager is provided in the DI container and
the session-ID cookie was present, valid, and found in the store.
Sourcepub fn tenant(&self) -> Option<&TenantConfig>
pub fn tenant(&self) -> Option<&TenantConfig>
The tenant resolved for this request, if any.
Some only when a TenantRegistry is provided in the DI container and
the configured strategy (header / subdomain) matched a known tenant
(or a fallback tenant is configured). Enforce presence + JWT-claim
consistency with web::tenant::TENANT.check(&ctx)?.
pub fn header(&self, key: &str) -> Option<&str>
pub fn param(&self, name: &str) -> Option<&str>
Sourcepub fn inject<T: Send + Sync + 'static>(&self) -> &'static T
pub fn inject<T: Send + Sync + 'static>(&self) -> &'static T
Resolve a singleton service. O(1), no locks, no allocation.
Panics if T was not provided into the DI container.
Sourcepub fn try_inject<T: Send + Sync + 'static>(&self) -> Option<&'static T>
pub fn try_inject<T: Send + Sync + 'static>(&self) -> Option<&'static T>
Non-panicking variant of Self::inject. Returns None when T is not
in the DI container. Used by optional guards and middleware.
Sourcepub fn route(&self) -> &'static str
pub fn route(&self) -> &'static str
Matched route pattern (e.g. /users/:id). Use this — not path() — as a
metrics/trace label to prevent high-cardinality from path parameters.
Sourcepub fn route_spec(&self) -> Option<&'static RouteSpec>
pub fn route_spec(&self) -> Option<&'static RouteSpec>
Static route metadata for the matched route, if any.
Sourcepub fn traceparent(&self) -> String
pub fn traceparent(&self) -> String
Generate the W3C traceparent header value suitable for forwarding to
downstream HTTP services. Uses this hop’s span_id as the parent-id
field so the downstream span correctly chains to this one.
Format: 00-{trace_id_hex}-{span_id_hex}-01
Sourcepub fn trace_id_hex(&self) -> String
pub fn trace_id_hex(&self) -> String
The trace ID as a lowercase hex string — for log/audit correlation.
Replaces app-level calls to lean_telemetry::hex_encode(&ctx.trace_id()).
Trait Implementations§
Source§impl Clone for RequestContext
impl Clone for RequestContext
Source§fn clone(&self) -> RequestContext
fn clone(&self) -> RequestContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for RequestContext
impl !RefUnwindSafe for RequestContext
impl !UnwindSafe for RequestContext
impl Send for RequestContext
impl Sync for RequestContext
impl Unpin for RequestContext
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
T in a tonic::Request