Skip to content
Search
DSL · Pg query

traceable_postgresql_client

Definition

/**
 * Wrap a PostgreSQL client with telemetry instrumentation.
 *
 * Returns a decorator that adds spans, metrics, and logs to all
 * query and transaction operations following OpenTelemetry conventions.
 *
 * @param Client\Client $client The PostgreSQL client to instrument
 * @param PostgreSqlTelemetryConfig $telemetryConfig Telemetry configuration
 *
 * @example
 * $client = pgsql_client(pgsql_connection('host=localhost dbname=mydb'));
 *
 * $traceableClient = traceable_postgresql_client(
 *     $client,
 *     postgresql_telemetry_config(
 *         telemetry(resource(['service.name' => 'my-app'])),
 *         new SystemClock(),
 *         postgresql_telemetry_options(
 *             traceQueries: true,
 *             traceTransactions: true,
 *             collectMetrics: true,
 *             logQueries: true,
 *             maxQueryLength: 500,
 *         ),
 *     ),
 * );
 *
 * // All operations now traced
 * $traceableClient->transaction(function (Client $client) {
 *     $user = $client->fetchSingle('SELECT * FROM users WHERE id = $1', [123]);
 *     $client->execute('UPDATE users SET last_login = NOW() WHERE id = $1', [123]);
 * });
 */
traceable_postgresql_client(Client $client, PostgreSqlTelemetryConfig $telemetryConfig) : TraceableClient

Contributors

Built in the open.

Join us on GitHub
scroll back to top