Expand description
Type-safe wrapper to ensure one database operation per executor.
OneTimeExecutor also implements sqlx::Executor: every statement
executed through it is annotated with the active span’s traceparent as a
trailing SQL comment (see crate::sql_commenter). This is what allows
statements observed server-side (pg_stat_activity, Postgres logs) to be
matched to distributed traces.
The annotation rewrites the statement text only; bind arguments and row
mapping flow through unchanged, so it is transparent to sqlx::query!
macro-generated queries as well as dynamically built ones.
§Trade-off: annotated statements bypass the prepared statement cache
The trace context makes each annotated statement’s text unique, so it can
never match sqlx’s per-connection prepared statement cache. Annotated
statements are therefore executed with persistent(false) (the unnamed
statement) — bypassing the cache rather than thrashing it with single-use
entries. The cost is a server-side parse + plan per annotated execution.
Annotation only happens for sampled spans (see
crate::sql_commenter::current_traceparent), so un-sampled traffic keeps
full prepared-statement reuse.
When there is no sampled span context the original query is passed through untouched and the executor adds no overhead.
Structs§
- OneTime
Executor - A struct that owns an
sqlx::Executor.
Traits§
- Into
OneTime Executor - Marker trait for
IntoOneTimeExecutorAt<'a> + 'a. Do not implement directly. - Into
OneTime Executor At - A trait to signify that we can use an argument for 1 round trip to the database