---
title: "Events — Metrics for Laravel | Roundly"
description: "MetricCalculated fires on every resolution with the key, range, duration and cache-hit flag — ready for slow-metric logging."
url: https://roundly-consulting.com/open-source/docs/metrics-for-laravel/events
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Metrics for Laravel](https://roundly-consulting.com/open-source/docs/metrics-for-laravel.md)

# Events

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

```php
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

```php
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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

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

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/metrics-for-laravel.md)
