Runtime and observability
Rent emits structured tracing spans for pool connection, transactions, queries, and migrations. It records the dialect, operation, bind count, and statement length without recording bound values.
Install your preferred subscriber in the application:
tracing_subscriber::fmt()
.with_env_filter("rent=debug")
.try_init()?;Configure the pool explicitly for production workloads:
use std::time::Duration;
use rent::driver::{DatabasePool, PoolOptions};
use rent::sql::Dialect;
let pool = DatabasePool::connect_with(
Dialect::Postgres,
&database_url,
PoolOptions {
max_connections: 32,
min_connections: 4,
acquire_timeout: Duration::from_secs(3),
idle_timeout: Some(Duration::from_secs(10 * 60)),
max_lifetime: Some(Duration::from_secs(30 * 60)),
test_before_acquire: true,
},
)
.await?;DatabasePool::connect uses conservative defaults when an application does not need custom settings.
For transactions that can safely be repeated after a serialization failure or deadlock, use the generated retry helper:
let post = client
.transaction_retry(3, async |tx| {
tx.create_post()
.title("A retryable write")
.save()
.await
})
.await?;Rent retries only database errors classified as serialization conflicts, deadlocks, or backend lock contention.
That classification applies to transaction setup, the operation, and commit. Validation, authorization, application,
and rollback failures return immediately. Retry warnings include the completed attempt, total attempt budget, and
chosen backoff delay without recording query values; TransactionRetryPolicy controls the delay and jitter.