Repository navigation
The biggest release in the project's history: PHP 8.4+, a strictly-typed and tag-native CollectorInterface, four new collectors (Chain, OpenTelemetry, InfluxDB v2 and AWS CloudWatch), a reworked Symfony bundle, and a full demo application with Grafana dashboards for every backend.
Important
Upgrading from 2.x? Read the UPGRADE guide first: it documents every breaking change with before/after examples.
Requirements
| Requirement | 2.x | 3.0 |
|---|---|---|
| PHP | >= 5.6 | >= 8.4 |
| Symfony (bundle) | any (best effort) | >= 6.4 |
| psr/log | ^1.0 || ^2.0 || ^3.0 |
^3.0 |
Highlights
Four new collectors
- Chain: dispatches every call to a list of other collectors, so the same metric can go to several backends at once.
gauge()is only forwarded to the collectors that support it. - OpenTelemetry: records measurements on an
OpenTelemetry\API\Metrics\MeterProviderInterface(UpDownCounterformeasure()/increment()/decrement(),Histogramfortiming(),Gaugeforgauge()). - InfluxDbV2: writes points to an InfluxDB 2.x/3.x bucket through
influxdata/influxdb-client-php. - CloudWatch: publishes metric data through AWS CloudWatch's
PutMetricDataAPI viaaws/aws-sdk-php.
All four are available through Factory::create() and as bundle collector types (chain, opentelemetry, influxdb_v2, cloudwatch).
A stricter, tag-native API
- Every
CollectorInterfacemethod is strictly typed, returnsvoid, and every metric method accepts an additionalarray $tags = []argument. timing()acceptsint|floatmilliseconds: fractional milliseconds are preserved by every collector.TaggableCollector::setTags()is gone. Tags are passed per call or fixed once in the collector constructor.- Collectors never let an error or exception from the underlying client reach the instrumented application.
- Telegraf emits the Influx StatsD dialect (
metric,key=value:value|type), with RFC 3986-encoded per-call tags merged over constructor defaults.
Symfony bundle
- Every configured collector gets an autowiring alias: inject a specific one with
#[Target('name')], orCollectorInterfacefor the default one. - All collectors are tagged
kernel.reset(clean state in long-running workers) andBeberlei\Metrics\Collector\CollectorInterface. - Optional collector services are registered lazily.
- The
collectorsroot key is no longer required: an empty configuration registers a singlenullcollector.
Demo application
The examples/ folder ships a Symfony application wired to every collector, backed by a Docker stack (Prometheus, Graphite/StatsD, InfluxDB 1.x and 2.x, PostgreSQL, LocalStack for CloudWatch) that provisions a Grafana dashboard for each backend. It runs in CI.
Breaking changes
- Drop support for PHP < 8.4 and Symfony < 6.4, require
psr/log ^3.0. - Rename
Collector\CollectortoCollector\CollectorInterfaceandCollector\GaugeableCollectortoCollector\GaugeableCollectorInterface. - Remove
TaggableCollector(andsetTags()), the deprecatedNullclass,InlineTaggableGaugeableCollector,InlineTaggableGaugeableNullCollectorand thenull_inlinetaggablefactory type. - All
CollectorInterfacemethods are strictly typed, returnvoidand accept$tags; custom implementations must be updated. - All collector classes and
Factoryare nowfinal. Factory error messages have been reworded. - Remove the Zabbix and Librato collectors, with no replacement.
- Rename the
InfluxDBcollector toInfluxDbV1(factory typeinfluxdb_v1), now built oninfluxdb/influxdb-phpinstead of the abandonedcorley/influxdb-sdk. - Prometheus is now built on
promphp/prometheus_client_phpinstead of the abandonedjimdo/prometheus_client_php. - Bundle: remove the
beberlei_metrics.collectorservice alias (injectCollectorInterfaceor use#[Target]), theinfluxdb_clientandprometheus_collector_registryoptions (useservice), and the XML services file (prototypes are registered programmatically). - Bundle: configuring several collectors without a
defaultkey always throws. - DoctrineDBAL: the
createdcolumn now stores a full datetime (Y-m-d H:i:s), and themeasurementcolumn must accept floating-point values.
Other changes
- DoctrineDBAL: fix DBAL deprecations, a rollback failure during
flush()no longer masks the original exception. - Telegraf: drop buffered metrics after a failed flush.
- Tooling: PHPUnit 13, PHPStan (level 8), PHP-CS-Fixer and GitHub Actions replace the Symfony PHPUnit bridge and Travis. Tests moved to their own folder and autoloader.
- Add a
LICENSE.mdfile.
Installation
composer require beberlei/metrics:^3.0
Full Changelog: v2.11.0...v3.0.0