New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

nwidart/laravel-metrics

OpenTelemetry metrics for Laravel that work under PHP-FPM and Laravel Octane, with zero-code HTTP, database, queue and cache instrumentation.
774 1
Install
composer require nwidart/laravel-metrics
Latest Version:1.1.0
PHP:^8.2
Laravel:12 · 13
License:MIT
Last Updated:Nov 23, 2026
Links: GitHub  ·  Packagist
Maintainer: nWidart
Laravel Metrics

CI Latest version License

OpenTelemetry metrics for Laravel that work under PHP-FPM and Laravel Octane.

The package records HTTP requests, queries, transactions, Eloquent models, queue jobs, cache operations, scheduled tasks and exceptions with no code. Each request records in memory and merges into Redis after the response. Serve the metrics to Prometheus, or push them over OTLP.

Read the documentation: https://nwidart.github.io/laravel-metrics/

Installation

composer require nwidart/laravel-metrics

The service provider registers itself, and recording starts at once. You need PHP 8.2 or later, Laravel 12 or 13, and Redis in production. See Installation for production settings and the OTLP setup.

Quick demo

Keep the metrics in the cache instead of Redis, and turn on the Prometheus route, in .env:

METRICS_STORE=cache
METRICS_CACHE_STORE=file
METRICS_PROMETHEUS=true

Record a metric of your own:

use Nwidart\Metrics\Facades\Metrics;

Route::get('/orders/place', function () {
    Metrics::meter()->createCounter('orders.placed', '{order}')->add(1, ['channel' => 'web']);

    return 'Order placed.';
});

Call the route, then read the metrics:

curl -s http://127.0.0.1:8000/orders/place
curl -s http://127.0.0.1:8000/metrics | grep -E '^(orders_placed_total|http_server_request_duration_seconds_count)'
http_server_request_duration_seconds_count{http_request_method="GET",http_response_status_code="200",http_route="/orders/place",network_protocol_version="1.1",otel_scope_name="nwidart/laravel-metrics",url_scheme="http"} 1
orders_placed_total{channel="web",otel_scope_name="app"} 1

In production, protect GET /metrics. The tutorial goes through these steps and adds a test.

Development

Requirements: PHP 8.2 or later, Composer, and a Redis server for the tests.

composer install
docker run -d --name laravel-metrics-redis -p 6379:6379 redis:7.4-alpine
composer test
composer lint
composer analyse

The tests use Redis database 15. Set REDIS_HOST and REDIS_PORT to use another server.

Changelog

See CHANGELOG.md.

License

MIT. See LICENSE.md.

Related Packages

kevariable/laravel-metrics

Send app metrics from Laravel to Prometheus, StatsD, OpenTelemetry, CloudWatch a...

52 0
cboxdk/laravel-telemetry

Collector-free telemetry for Laravel: Prometheus metrics, OTLP traces and events...

21,342 3
renoki-co/octane-exporter

Export Laravel Octane metrics using this Prometheus exporter.

128,898 30
spiti/octane-exporter

Export Laravel Octane metrics using this Prometheus exporter.

1 0
lovlyx/octane-exporter

Export Laravel Octane metrics using this Prometheus exporter.

0 0

Version History

Version Released PHP Laravel License
1.1.0 ^8.2 ^12.0|^13.0 MIT
1.0.0 ^8.2 ^12.0|^13.0 MIT
0.3.0 ^8.2 ^12.0|^13.0 MIT
0.2.0 ^8.2 ^12.0|^13.0 MIT
0.1.0 ^8.2 ^12.0|^13.0 MIT