Skip to main content

QueryAnnotateExt

Trait QueryAnnotateExt 

Source
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§

Source

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§

Source

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.

Implementations on Foreign Types§

Source§

impl<DB: Database, A> QueryAnnotateExt for Query<'_, DB, A>

Source§

impl<DB: Database, F, A> QueryAnnotateExt for Map<'_, DB, F, A>

Source§

impl<DB: Database, O, A> QueryAnnotateExt for QueryAs<'_, DB, O, A>

Source§

impl<DB: Database, O, A> QueryAnnotateExt for QueryScalar<'_, DB, O, A>

Implementors§