RoundlyConsulting\Metrics\Events\MetricCalculated fires every time a metric resolves — ad-hoc or registered, computed or served from cache. Its readonly properties:
| Property | Type | Meaning |
|---|---|---|
key | ?string | The registry key, or null for ad-hoc metrics. |
range | string | The resolved range value. |
durationMs | float | Time to compute, in milliseconds. |
fromCache | bool | Whether the result was served from cache. |
Log slow metrics
use Illuminate\Support\Facades\Event;
use RoundlyConsulting\Metrics\Events\MetricCalculated;
Event::listen(function (MetricCalculated $event): void {
if ($event->durationMs > 500) {
logger()->warning("Slow metric [{$event->key}] took {$event->durationMs}ms");
}
});Measure cache hits
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
use RoundlyConsulting\Metrics\Events\MetricCalculated;
Event::listen(function (MetricCalculated $event): void {
Log::info('metric resolved', [
'key' => $event->key, // null for ad-hoc metrics
'range' => $event->range,
'ms' => round($event->durationMs, 1),
'cached' => $event->fromCache,
]);
});The event fires once per resolution — for a dashboard, once per metric.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.