final class DatabaseInstrumentation (View source)

internal  For synchronous sequential lifecycles. No collector or observer is retained outside collect(); nested or overlapping captures on one instance are rejected.
 

Lets long-lived connections report into a fresh, explicitly bounded SQL capture.

Methods

mixed
collect(callable $operation, DatabaseObserverInterface|null $observer = null)

Supplies fresh totals to one synchronous consumer and always releases the active capture.

mixed
mixed
query(string $sql, callable $operation, array $bindings = [], DatabaseDialect|null $dialect = null)

Measures one execution attempt only while a consumer is active, preserving its return or exception.

mixed
mixed
connection(callable $operation)

Measures connection setup only for an observer; it never contributes to SQL aggregates.

mixed

Details

collect

mixed collect(callable $operation, DatabaseObserverInterface|null $observer = null)

Supplies fresh totals to one synchronous consumer and always releases the active capture.

The consumer may copy totals into HttpMetrics before returning or in its own finally block. Root-owned drivers use this instance; the HTTP boundary is its runtime capture owner.

Parameters

callable $operation
DatabaseObserverInterface|null $observer

Return Value

mixed

Exceptions

LogicException
Throwable

query

mixed query(string $sql, callable $operation, array $bindings = [], DatabaseDialect|null $dialect = null)

Measures one execution attempt only while a consumer is active, preserving its return or exception.

Drivers must open the connection before this callback and fetch rows afterwards. Keep prepare, binding, execution and existing execution-result bookkeeping inside it.

Parameters

string $sql
callable $operation
array $bindings
DatabaseDialect|null $dialect

Return Value

mixed

Exceptions

Throwable

connection

mixed connection(callable $operation)

Measures connection setup only for an observer; it never contributes to SQL aggregates.

Call only when opening a connection, not when returning a cached native handle.

Parameters

callable $operation

Return Value

mixed

Exceptions

Throwable