DatabaseInstrumentation
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
Supplies fresh totals to one synchronous consumer and always releases the active capture.
Measures one execution attempt only while a consumer is active, preserving its return or exception.
Measures connection setup only for an observer; it never contributes to SQL aggregates.
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.
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.
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.