pub trait QueryAnnotateExt: Sealed + Sized {
// Required method
fn with_annotations(
self,
annotations: QueryAnnotations,
) -> AnnotatedQuery<Self>;
// Provided method
fn with_operation(
self,
operation: impl Into<String>,
collection: impl Into<String>,
) -> AnnotatedQuery<Self> { ... }
}Expand description
Extension trait that attaches OpenTelemetry per-query annotations to the function-form
SQLx query builders (sqlx::query(), sqlx::query_as(),
sqlx::query_scalar()) and to the Map returned by
Query::map / Query::try_map.
The trait is sealed and cannot be implemented downstream.
§Example
use sqlx_otel::QueryAnnotateExt;
sqlx::query("INSERT INTO orders (user_id) VALUES (?)")
.bind(42_i64)
.with_operation("INSERT", "orders")
.execute(&pool)
.await?;Required Methods§
Sourcefn with_annotations(self, annotations: QueryAnnotations) -> AnnotatedQuery<Self>
fn with_annotations(self, annotations: QueryAnnotations) -> AnnotatedQuery<Self>
Wrap the query with the given per-query annotations.
Returns an AnnotatedQuery that exposes the same execute/fetch* surface as the
inner query but threads the annotations through to OpenTelemetry span creation.
Provided Methods§
Sourcefn with_operation(
self,
operation: impl Into<String>,
collection: impl Into<String>,
) -> AnnotatedQuery<Self>
fn with_operation( self, operation: impl Into<String>, collection: impl Into<String>, ) -> AnnotatedQuery<Self>
Shorthand that sets db.operation.name and db.collection.name.
Equivalent to
self.with_annotations(QueryAnnotations::new().operation(op).collection(coll)).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.