NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

RoundlyConsulting\Metrics\Events\MetricCalculated fires every time a metric resolves — ad-hoc or registered, computed or served from cache. Its readonly properties:

PropertyTypeMeaning
key?stringThe registry key, or null for ad-hoc metrics.
rangestringThe resolved range value.
durationMsfloatTime to compute, in milliseconds.
fromCacheboolWhether 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 crypto

By 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.