Skip to content

v3.0.0

Latest

Choose a tag to compare

@lyrixx lyrixx released this 09 Sep 11:46
· 22 commits to 3.x since this release
bd85fb9

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 (UpDownCounter for measure()/increment()/decrement(), Histogram for timing(), Gauge for gauge()).
  • InfluxDbV2: writes points to an InfluxDB 2.x/3.x bucket through influxdata/influxdb-client-php.
  • CloudWatch: publishes metric data through AWS CloudWatch's PutMetricData API via aws/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 CollectorInterface method is strictly typed, returns void, and every metric method accepts an additional array $tags = [] argument.
  • timing() accepts int|float milliseconds: 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')], or CollectorInterface for the default one.
  • All collectors are tagged kernel.reset (clean state in long-running workers) and Beberlei\Metrics\Collector\CollectorInterface.
  • Optional collector services are registered lazily.
  • The collectors root key is no longer required: an empty configuration registers a single null collector.

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\Collector to Collector\CollectorInterface and Collector\GaugeableCollector to Collector\GaugeableCollectorInterface.
  • Remove TaggableCollector (and setTags()), the deprecated Null class, InlineTaggableGaugeableCollector, InlineTaggableGaugeableNullCollector and the null_inlinetaggable factory type.
  • All CollectorInterface methods are strictly typed, return void and accept $tags; custom implementations must be updated.
  • All collector classes and Factory are now final. Factory error messages have been reworded.
  • Remove the Zabbix and Librato collectors, with no replacement.
  • Rename the InfluxDB collector to InfluxDbV1 (factory type influxdb_v1), now built on influxdb/influxdb-php instead of the abandoned corley/influxdb-sdk.
  • Prometheus is now built on promphp/prometheus_client_php instead of the abandoned jimdo/prometheus_client_php.
  • Bundle: remove the beberlei_metrics.collector service alias (inject CollectorInterface or use #[Target]), the influxdb_client and prometheus_collector_registry options (use service), and the XML services file (prototypes are registered programmatically).
  • Bundle: configuring several collectors without a default key always throws.
  • DoctrineDBAL: the created column now stores a full datetime (Y-m-d H:i:s), and the measurement column 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.md file.

Installation

composer require beberlei/metrics:^3.0

Full Changelog: v2.11.0...v3.0.0