Repository navigation
Conversation
Some SQLx APIs take nothing an instrumented `Pool` can provide today: `Migrator::run` is generic over `sqlx::Acquire`, and `PgListener::connect_with` accepts only a `sqlx::Pool`. - `&Pool<DB>` now implements `sqlx::Acquire`. Both methods acquire through `Pool::acquire`, so wait time, pending requests and timeouts are recorded. `acquire` returns the new `AcquiredConnection`, which dereferences to the backend connection and records `use_time` when dropped. `begin` returns a plain `sqlx::Transaction`, which cannot report its release, so that lease records no `use_time`. - `Pool::inner()` returns the wrapped `sqlx::Pool`. Work done through it is not instrumented. Queries run on the raw connection or pool are not instrumented; the docs, README and CHANGELOG say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some SQLx APIs cannot take an instrumented
Pooltoday:sqlx::migrate::Migrator::runis generic oversqlx::Acquire, which&Pooldoes not implement;sqlx::postgres::PgListener::connect_withaccepts only asqlx::Pool, and the wrapped pool is private.An application that wraps its pool therefore has to keep a second handle to the raw pool next to it, just for migrations and LISTEN/NOTIFY.
Changes
impl sqlx::Acquire for &Pool<DB>. Both methods acquire throughPool::acquire, sowait_time,pending_requestsandtimeoutsare recorded as on every other path.acquirereturns a newAcquiredConnection<DB>, which derefs to the backend connection (whatAcquire::Connectionrequires) and recordsuse_timewhen dropped.beginreturns a plainsqlx::Transaction. It cannot report when it releases its connection, so that lease records nouse_timerather than a wrong one.Pool::inner() -> &sqlx::Pool<DB>, for APIs that accept nothing else. Nothing done through it is instrumented.A separate
AcquiredConnectiontype, rather thanDerefonPoolConnection, keeps&mut *connfrom silently bypassing instrumentation on the connection type users already have.Docs, README and CHANGELOG cover both, including what is not instrumented.
Tests
pool_metrics.rs:Acquire::acquire(wait and use time, no spans),Acquire::begin(wait time only),Migrator::run(&pool), andinner()(no spans, no wait time).postgres.rs:PgListener::connect_with(pool.inner())receives aNOTIFY.cargo test --all-features, the async-stdpool_metricsrun, clippy-D warningsand fmt pass locally.sqlx/migrateis added to the dev-dependencies for theMigratortest.🤖 Generated with Claude Code