Skip to content

Introduction

Laravel Metrics records OpenTelemetry metrics in a Laravel application, and it works under PHP-FPM. Install it, and it answers the questions that you ask about a running application:

  • How many requests does it serve, and how fast? Per route, method and status code.
  • How much time goes to the database? Per connection and operation, with the transactions that roll back.
  • Which routes and jobs run too many queries? The queries per request and per job, where N+1 queries show up.
  • How many Eloquent models does it load and change? Per model class.
  • Do the queue jobs keep up? Jobs sent and processed, with their duration and their failures.
  • Does the cache help? Hits, misses, writes and deletes, per store.
  • Do the scheduled tasks run, and do they fail?
  • Which exceptions does it report, and how often?
  • How does the server look? OPcache, PHP-FPM workers, load average and disk space, the database server’s connections, and the migrations that have not run.

You write no code for these. You can add metrics of your own through the OpenTelemetry API.

The OpenTelemetry SDK keeps metrics in the memory of one process. Under PHP-FPM, every request starts with an empty process, so a counter starts at zero on each request. Laravel Metrics adds the missing part: each request merges what it recorded into a shared store, Redis in production, after the response is sent. The store holds the totals of every worker and every host. How it works tells the full story.

Metric Records Reference
http.server.request.duration Each HTTP request HTTP requests
db.client.operation.duration Each successful query Database queries
laravel.db.transaction.duration Each outer transaction Database transactions
laravel.db.queries The queries of each request and job Queries per request and per job
laravel.eloquent.models, laravel.eloquent.models.pruned Each model retrieved, created, updated, deleted, restored or pruned Eloquent models
messaging.process.duration, messaging.client.sent.messages Each job attempt, each job sent Queue jobs
laravel.cache.operations Each cache read, write and delete Cache operations
laravel.scheduler.task.duration Each run of a scheduled task Scheduled tasks
laravel.exceptions Each reported exception Exceptions
laravel.info, php.opcache.*, php.fpm.*, system.* Read when the metrics are exported Metrics read on export
laravel.db.server.connections, laravel.db.migrations.pending Read when the metrics are exported Database server and migrations

The names follow the OpenTelemetry semantic conventions where they define the metric. Each group has its own switch.

The package records from the first request. To send the metrics out, pick one way, or both:

  • Prometheus scrapes them. Turn on GET /metrics, which serves the Prometheus text format. See Scrape with Prometheus.
  • The application pushes them over OTLP, to an OpenTelemetry Collector or a backend that accepts OTLP. Schedule php artisan metrics:push. See Push over OTLP.

Scrape or push compares the two.

  • It records metrics only: no traces and no logs.
  • It is not tested with Laravel Octane or Redis Cluster. See Limits.
  • PHP 8.2 or later
  • Laravel 12 or 13
  • Redis in production, with phpredis or predis. Development can run without it.

Installation has the details.

The documentation has four parts. Each part serves a different need.