Skip to main content
The Database instrumentation traces every SQL query executed through Laravel’s DB facade or Eloquent. Each query produces a dedicated CLIENT span, enabling you to identify slow queries and understand database usage patterns. Spans are only created when a trace is already active (i.e. within a traced request, job, or command). Standalone queries executed outside any active trace are ignored.

Span Details

  • Span name: The SQL operation name — SELECT, INSERT, UPDATE, or DELETE.
  • Span kind: CLIENT
  • Attributes captured: database system, database name, operation name, query text (truncated to 500 characters), server address, and server port.
Only queries with recognised operation keywords (SELECT, INSERT, UPDATE, DELETE) are traced. Raw statements with other leading keywords are skipped.

Configuration

In config/opentelemetry.php:
use Keepsuit\LaravelOpenTelemetry\Instrumentation;

'instrumentation' => [
    Instrumentation\QueryInstrumentation::class => env('OTEL_INSTRUMENTATION_QUERY', true),
],
This instrumentation does not have additional sub-options; it is either enabled or disabled.

Metrics

MetricTypeUnitDescription
db.client.operation.durationHistogramsecondsDuration of database client operations.
The histogram uses the following bucket boundaries (in seconds): 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0, 5.0, 10.0.

Disabling

Set the environment variable to false to disable this instrumentation:
OTEL_INSTRUMENTATION_QUERY=false
Alternatively, remove QueryInstrumentation::class from the instrumentation array in config/opentelemetry.php.

Build docs developers (and LLMs) love