pub struct RequestAuditContext {
pub actor: String,
pub correlation_id: String,
pub client_ip: String,
pub user_agent: String,
pub http_method: String,
pub resource_path: String,
}Expand description
Who and where one request’s writes are attributed to (ADR-0025).
Built by the composing service’s guard — the actor off a signed token, never the request body — and carried by the request scope alongside the fence variables, so every write of the request (a trigger fires on it) reads the same attribution. All fields are empty-string-when-unknown; see the module docs for how readers treat that.
Fields§
§actor: StringThe authenticated principal the capture function records as the actor. Empty falls back
to 'system' at capture time.
correlation_id: StringThe request correlation id — the join key between audit rows and the request that caused them.
client_ip: StringThe client’s IP as the edge proxy reported it (X-Forwarded-For’s first entry).
user_agent: StringThe request’s User-Agent.
http_method: StringThe HTTP method, upper-case as the router saw it.
resource_path: StringThe request path (no query string) as the router saw it.
Implementations§
Source§impl RequestAuditContext
impl RequestAuditContext
Sourcepub fn new(actor: impl Into<String>) -> Self
pub fn new(actor: impl Into<String>) -> Self
A context with only an actor — the minimum attribution a guarded request carries; every other field stays unset (reads NULL at capture time).
Sourcepub fn pairs(&self) -> [(&'static str, &str); 6]
pub fn pairs(&self) -> [(&'static str, &str); 6]
The (variable, value) pairs of the whole channel, in AUDIT_CONTEXT_VARS order —
the wire form bind and tests walk.
Sourcepub async fn bind_on(
&self,
conn: &mut PgConnection,
local: bool,
) -> Result<(), Error>
pub async fn bind_on( &self, conn: &mut PgConnection, local: bool, ) -> Result<(), Error>
Bind every audit variable on a connection.
local = true binds transaction-locally (the twin of
bind_org_scope_on, for hand-written write
services that manage their own transaction); local = false binds at session level on
a request-dedicated connection — the form the request scope uses, because the variables
must outlive any single statement for the whole request.
§Errors
Returns the sqlx error if any set_config fails (connection lost mid-bind).
Trait Implementations§
Source§impl Clone for RequestAuditContext
impl Clone for RequestAuditContext
Source§impl Debug for RequestAuditContext
impl Debug for RequestAuditContext
Source§impl Default for RequestAuditContext
impl Default for RequestAuditContext
impl Eq for RequestAuditContext
Source§impl PartialEq for RequestAuditContext
impl PartialEq for RequestAuditContext
impl StructuralPartialEq for RequestAuditContext
Auto Trait Implementations§
impl Freeze for RequestAuditContext
impl RefUnwindSafe for RequestAuditContext
impl Send for RequestAuditContext
impl Sync for RequestAuditContext
impl Unpin for RequestAuditContext
impl UnsafeUnpin for RequestAuditContext
impl UnwindSafe for RequestAuditContext
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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