Expand description
PostgreSQL through tokio-postgres, and deadpool-postgres pools.
tokio-postgres doesn’t say what SQL a prepared statement holds, and its traits are sealed, so instrumenting it means wrapping the client. Wrap it where the connection is made:
let config: tokio_postgres::Config = "host=localhost user=app dbname=shop".parse()?;
let (client, connection) = config.connect(tokio_postgres::NoTls).await?;
tokio::spawn(connection);
let client = oxtel_sql::postgres::Client::new(client, &config);
let rows = client.query("SELECT name FROM users WHERE id = $1", &[&7i32]).await?;Client and Transaction have tokio-postgres’s query,
query_one, query_opt, execute, batch_execute and simple_query,
each recorded as one database call: a client span named by the query
summary, with db.namespace, server.address and server.port from the
connection’s configuration, and db.client.operation.duration. A call
that fails records the error’s SQLSTATE as db.response.status_code and
error.type. Starting, committing and rolling back a transaction are
calls too.
prepare returns a Statement that keeps its text,
so calls running it are named like any other. Preparing isn’t recorded
as a call of its own. Both types dereference to tokio-postgres’s, so
anything else, such as copy_in or query_raw, still works, without
telemetry.
Helpers that should take either a client or a transaction can be generic
over GenericClient. With the deadpool-postgres feature, Pool
wraps a pool so that every client taken from it is instrumented, and
records the conventions’ connection pool metrics.
Structs§
- Client
- An instrumented tokio-postgres client, or a pooled one (see
AsClient). It dereferences to tokio-postgres’sClient, so methods it doesn’t wrap still work, without telemetry. - Database
- Where a client’s connections go, for
db.namespace,server.addressandserver.port. Cheap to clone. - Pool
- A deadpool-postgres pool whose clients are instrumented. It
dereferences to deadpool’s
Pool. - Statement
- A statement prepared through an instrumented client: tokio-postgres’s
Statement, keeping its text so the calls that run it are named. It dereferences to tokio-postgres’s. - Transaction
- An instrumented transaction, from
Client::transaction. Like tokio-postgres’s, dropping it without committing rolls it back, but that rollback isn’t recorded. It dereferences to tokio-postgres’sTransaction.
Traits§
- AsClient
- The clients a
Clientcan wrap: tokio-postgres’s own, and with thedeadpool-postgresfeature, a client taken from a deadpool pool. - Generic
Client - The instrumented calls of a
Clientor aTransaction, for helpers that take either. tokio-postgres’s ownGenericClientis sealed. - Query
- A statement the instrumented clients run: SQL text, a
Statementprepared through them, or one of tokio-postgres’s own, which is recorded without a name or text.