Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Metrics Laravel Package

beberlei/metrics

A lightweight PHP metrics library for instrumenting applications with counters, gauges, and timings. Pluggable collectors send measurements to backends like StatsD and Graphite, keeping monitoring code decoupled from your application logic.

View on GitHub
Deep Wiki
Context7

Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics (functional) API that doesn't cause vendor lock-in.

Frequently asked questions about Metrics
How do I integrate beberlei/metrics into a Laravel application?
There is no Laravel service provider, config file, facade, or test helper, so integration is manual: bind the Metrics instance in a service provider and inject it through an app-owned interface. Register a singleton that wires your chosen reporter (StatsD, Graphite, logger, or a chain) and pass it to the Metrics facade. Keeping the upstream class behind your own interface also lets you add Laravel context, sampling, and cardinality guards.
Does beberlei/metrics 3.0 work on PHP 8.2 or 8.3?
No. Version 3.0 requires PHP 8.4 or higher, so it cannot be installed on 8.2 or 8.3 runtimes at all. If your fleet is on 8.2 or 8.3 with no near-term 8.4 plan, the package is effectively unavailable and the decision is deferred rather than evaluated. Check your target runtime before planning any adoption.
Which Laravel versions are compatible with beberlei/metrics?
The package is framework-agnostic and depends on psr/log ^3.0, which is compatible with Laravel 10, 11, and 12. That dependency rules out Laravel 9. The binding constraint, though, is PHP 8.4, which sits above Laravel's own supported PHP matrix, so confirm your runtime first.
How do I record timers, counters, and gauges with beberlei/metrics?
Use the Metrics facade: timing() records durations with fractional millisecond precision, while increment() and decrement() and gauge() handle counters and point-in-time values. Each call accepts a tags array for dimensions such as route or tenant. Measurements are forwarded to whatever collectors you registered, so call sites stay backend-agnostic.
How do I send metrics to StatsD or Graphite with beberlei/metrics?
Instantiate the built-in StatsD or Graphite collector with your client or connection settings and register it on the Metrics facade, either alone or alongside other collectors. You can swap backends at runtime without touching instrumented code. Because the Factory and collectors are final, do your configuration wiring in your own service provider rather than subclassing.
Does beberlei/metrics support OpenTelemetry?
There is an OpenTelemetry collector, but it is a bridge rather than a full OTel integration: it maps timings to histograms and counters and gauges to the corresponding instruments on a MeterProviderInterface. Aggregation, views, resource attributes, exporters, exemplars, and span correlation remain the OTel SDK's responsibility. You still need a configured OpenTelemetry SDK behind it.
How do I add tags like tenant or route to metrics in beberlei/metrics?
Every collector method takes an array $tags = [] parameter, so dimensions are expressed natively per call without backend-specific hacks. Pass arrays such as tenant and route keys when recording a timing or counter. Tag cardinality is your responsibility, so guard high-cardinality values inside your own wrapper.
Can a failing metrics backend break my Laravel application?
The package documents that collectors never let an error or exception from the underlying client reach the instrumented application, making it fail-safe by contract. That said, verify the behavior empirically for each collector you enable, especially custom ones. Wrapping calls in your own reporter decorator remains a cheap safety net.
Can I extend or subclass the beberlei/metrics collectors?
No. Collectors and the Factory are final in 3.x, so subclassing is no longer an extension path and composition is the only option. Implement your own Reporter or CollectorInterface and wrap the upstream Metrics instance to add sampling, cardinality guards, or Laravel context. This makes an app-owned metrics interface a structural necessity rather than a nicety.
How do I upgrade from beberlei/metrics 2.x to 3.x?
Treat it as a hard break: 3.0 raises the PHP floor to 8.4, makes collectors and Factory final, and changes CollectorInterface to a strictly typed, void-returning, tag-native signature. Replace any inheritance-based customizations with composition and move configuration into your own wiring code. The Chain collector helps you dual-write while migrating between backends.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo