Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<DB: sqlx::Database> PoolBuilder<DB> {
/// 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<DB>
where
DB: sqlx::Database,
Expand All @@ -119,14 +119,26 @@ where
attributes: Arc<Attributes>,
}

impl<DB> Clone for Pool<DB>
where
DB: sqlx::Database,
{
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
attributes: Arc::clone(&self.attributes),
}
}
}

impl<DB> From<sqlx::Pool<DB>> for Pool<DB>
where
DB: sqlx::Database,
PoolBuilder<DB>: From<sqlx::Pool<DB>>,
{
/// Convert a SQLx [`Pool`] into a tracing-instrumented [`Pool`].
fn from(inner: sqlx::Pool<DB>) -> Self {
PoolBuilder::from(inner).build()
PoolBuilder::from(inner.into()).build()
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::time::Duration;

use sqlx::Postgres;
use sqlx_tracing::Pool;
use testcontainers::{
GenericImage, ImageExt,
core::{ContainerPort, WaitFor},
Expand Down Expand Up @@ -78,3 +79,9 @@ async fn execute() {
.await;
}
}

#[test]
fn pool_postgres_is_clone() {
fn assert_clone<T: Clone>() {}
assert_clone::<Pool<Postgres>>();
}