| Crates.io | sqlx-tracing |
| lib.rs | sqlx-tracing |
| version | 0.1.0 |
| created_at | 2025-09-07 14:14:14.384839+00 |
| updated_at | 2025-09-07 14:14:14.384839+00 |
| description | OpenTelemetry-compatible tracing for SQLx database operations in Rust. |
| homepage | https://github.com/jdrouet/sqlx-tracing |
| repository | https://github.com/jdrouet/sqlx-tracing |
| max_upload_size | |
| id | 1828162 |
| size | 118,740 |
sqlx-tracing is a Rust library that provides OpenTelemetry-compatible tracing for SQLx database operations. It wraps SQLx connection pools and queries with tracing spans, enabling detailed observability of database interactions in distributed systems.
Add sqlx-tracing to your Cargo.toml:
[dependencies]
sqlx-tracing = "0.1"
sqlx = { version = "0.8", default-features = false, features = ["derive"] }
tracing = "0.1"
Enable the desired database feature:
features = ["postgres"]features = ["sqlite"]Wrap your SQLx pool:
let pool = sqlx::PgPool::connect(&url).await?;
let traced_pool = sqlx_tracing::Pool::from(pool);
Use the traced pool as you would a normal SQLx pool:
let result: Option<i32> = sqlx::query_scalar("select 1")
.fetch_optional(&traced_pool)
.await?;
To export traces, set up an OpenTelemetry collector and configure the tracing subscriber with the appropriate layers. See the tests/common.rs for a full example using opentelemetry, opentelemetry-otlp, and tracing-opentelemetry.
Integration tests are provided for both PostgreSQL and SQLite, using testcontainers and a local OpenTelemetry collector.
Licensed under MIT.
Contributions and issues are welcome! Please open a PR or issue on GitHub.