pub struct QueryAnnotations { /* private fields */ }Expand description
Per-query annotation values that enrich OpenTelemetry spans with semantic-convention attributes the library cannot derive automatically (because it does not parse SQL).
Use the builder methods to set whichever attributes apply to a given query, then pass the result through one of the equivalent annotation surfaces:
- Executor-side –
Pool::with_annotations,PoolConnection::with_annotations, orTransaction::with_annotations. Returns a borrowed wrapper that is itself ansqlx::Executor. - Query-side –
QueryAnnotateExt::with_annotationson the builder produced bysqlx::query,sqlx::query_as,sqlx::query_scalar, or their_!macro forms.
Both surfaces produce identical telemetry; pick whichever keeps the annotation closer to the thing it describes.
§Example
use sqlx::Executor as _;
use sqlx_otel::QueryAnnotations;
pool.with_annotations(
QueryAnnotations::new()
.operation("SELECT")
.collection("users"),
)
.fetch_all("SELECT * FROM users")
.await?;Implementations§
Source§impl QueryAnnotations
impl QueryAnnotations
Sourcepub fn operation(self, operation: impl Into<String>) -> Self
pub fn operation(self, operation: impl Into<String>) -> Self
Set the db.operation.name attribute – the database operation being performed
(e.g. "SELECT", "INSERT", "findAndModify").
The OpenTelemetry semantic conventions require this value to be low cardinality,
since it is used to construct span names when query_summary
is not set. Callers who cannot guarantee low cardinality should set
query_summary instead – the library uses that path without a low-cardinality
assumption.
Sourcepub fn collection(self, collection: impl Into<String>) -> Self
pub fn collection(self, collection: impl Into<String>) -> Self
Set the db.collection.name attribute – the table or collection being operated on
(e.g. "users", "orders").
Sourcepub fn query_summary(self, summary: impl Into<String>) -> Self
pub fn query_summary(self, summary: impl Into<String>) -> Self
Set the db.query.summary attribute – a low-cardinality summary of the query
(e.g. "SELECT users", "INSERT orders").
When set, this value also drives the span name (level 1 of the OpenTelemetry
database span name hierarchy), overriding the {operation} {collection}
synthesis. Cardinality control is the caller’s responsibility – a high-cardinality
summary will produce high-cardinality span names.
Sourcepub fn stored_procedure(self, name: impl Into<String>) -> Self
pub fn stored_procedure(self, name: impl Into<String>) -> Self
Set the db.stored_procedure.name attribute – the name of a stored procedure
being called (e.g. "get_user", "sp_update_orders").
Trait Implementations§
Source§impl Clone for QueryAnnotations
impl Clone for QueryAnnotations
Source§fn clone(&self) -> QueryAnnotations
fn clone(&self) -> QueryAnnotations
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QueryAnnotations
impl Debug for QueryAnnotations
Source§impl Default for QueryAnnotations
impl Default for QueryAnnotations
Source§fn default() -> QueryAnnotations
fn default() -> QueryAnnotations
Source§impl PartialEq for QueryAnnotations
impl PartialEq for QueryAnnotations
impl Eq for QueryAnnotations
impl StructuralPartialEq for QueryAnnotations
Auto Trait Implementations§
impl Freeze for QueryAnnotations
impl RefUnwindSafe for QueryAnnotations
impl Send for QueryAnnotations
impl Sync for QueryAnnotations
impl Unpin for QueryAnnotations
impl UnsafeUnpin for QueryAnnotations
impl UnwindSafe for QueryAnnotations
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
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> 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> 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