From f9fa6db41bf3496ff51a5f5cde66ef9e57cc43e5 Mon Sep 17 00:00:00 2001 From: DJ Spatoulas Date: Mon, 17 Nov 2025 17:03:00 -0500 Subject: [PATCH 1/2] Fix `Clone` support (cherry picked from commit f7258e6dba4db332a3a6538b3a0c8dddda6d504e) --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5784858..a689999 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2560,7 +2560,7 @@ dependencies = [ [[package]] name = "sqlx-tracing" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "futures", diff --git a/Cargo.toml b/Cargo.toml index 5c94ea7..97d6e41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqlx-tracing" -version = "0.2.0" +version = "0.2.1" edition = "2024" description = "OpenTelemetry-compatible tracing for SQLx database operations in Rust." license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index ee99dbc..851aab5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -110,7 +110,7 @@ impl PoolBuilder { /// An asynchronous pool of SQLx database connections with tracing instrumentation. /// /// Wraps a SQLx [`Pool`] and propagates tracing attributes to all acquired connections. -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct Pool where DB: sqlx::Database, @@ -119,6 +119,18 @@ where attributes: Arc, } +impl Clone for Pool +where + DB: sqlx::Database, +{ + fn clone(&self) -> Self { + Self { + inner: self.inner.clone(), + attributes: Arc::clone(&self.attributes), + } + } +} + impl From> for Pool where DB: sqlx::Database, @@ -126,7 +138,7 @@ where { /// Convert a SQLx [`Pool`] into a tracing-instrumented [`Pool`]. fn from(inner: sqlx::Pool) -> Self { - PoolBuilder::from(inner).build() + PoolBuilder::from(inner.into()).build() } } From 117afb4211c8533061136e6085dbaaedd797ffad Mon Sep 17 00:00:00 2001 From: DJ Spatoulas Date: Mon, 17 Nov 2025 17:03:00 -0500 Subject: [PATCH 2/2] Add test for Clone impl --- tests/postgres.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/postgres.rs b/tests/postgres.rs index 0b2d0c6..7a788d7 100644 --- a/tests/postgres.rs +++ b/tests/postgres.rs @@ -3,6 +3,7 @@ use std::time::Duration; use sqlx::Postgres; +use sqlx_tracing::Pool; use testcontainers::{ GenericImage, ImageExt, core::{ContainerPort, WaitFor}, @@ -78,3 +79,9 @@ async fn execute() { .await; } } + +#[test] +fn pool_postgres_is_clone() { + fn assert_clone() {} + assert_clone::>(); +}