msstc4symfony / metrics-bridge-logic
Exports msstc4symfony/logic-bundle Action outcomes and durations as msstc4symfony/metrics-bundle Prometheus metrics
Package info
github.com/msstc4symfony/metrics-bridge-logic
Type:symfony-bundle
pkg:composer/msstc4symfony/metrics-bridge-logic
Requires
- php: >=8.2
- composer-runtime-api: >=2.2
- monolog/monolog: ^3.5
- msstc4symfony/logic-bundle: ^1.3|^2.0
- msstc4symfony/metrics-bundle: ^2.0
- psr/log: ^2.0|^3.0
- symfony/config: ^7.4|^8.0
- symfony/dependency-injection: ^7.4|^8.0
- symfony/http-kernel: ^7.4|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.76
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: >=11.0
- promphp/prometheus_client_php: ^2.13
- rector/rector: ^2.1
- roave/security-advisories: dev-latest
- symfony/filesystem: ^7.4|^8.0
- symfony/framework-bundle: ^7.4|^8.0
- symfony/monolog-bundle: ^3.11|^4.0
- symfony/validator: ^7.4|^8.0
Suggests
None
Provides
None
Conflicts
Replaces
None
README
Records every logic-bundle Action run as an observation of a Prometheus histogram of metrics-bundle: how long it took and how it ended.
Compatibility
| Bundle | PHP | Symfony | logic-bundle | metrics-bundle |
|---|---|---|---|---|
| 2.0 | 8.2+ | 7.4, 8.x | ^1.3, ^2.0 | ^2.0 |
| 1.1 | 8.2+ | 7.4, 8.x | ^1.2 | ^1.4 |
| 1.0 | 8.4+ | 7.4, 8.x | ^1.1 | ^1.3 |
Symfony 8.x needs PHP 8.4; on PHP 8.2 and 8.3 Composer installs Symfony 7.4.
Installation
composer require msstc4symfony/metrics-bridge-logic
Register the bridge in config/bundles.php alongside the two bundles it connects (order does not matter):
Msstc4Symfony\MetricsBundle\MetricsBundle::class => ['all' => true], Msstc4Symfony\LogicBundle\LogicBundle::class => ['all' => true], Msstc4Symfony\MetricsBridgeLogic\MetricsBridgeLogicBundle::class => ['all' => true],
Nothing to configure. Without MetricsBundle the container fails to compile with a message naming it.
The metric
| Name | Type | Labels |
|---|---|---|
symfony_logic_action_duration_histogram_seconds |
histogram | application, component, action, outcome |
- Buckets (seconds):
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30. application/componentcome from the metrics-bundle configuration.outcomeissuccess,expected_failure(anExpectedFailureInterfaceexception or Symfony'sValidationFailedException) orerror(any other exception), as logic-bundle'sActionOutcomeclassifies it.actionis the name logic-bundle uses in its logs (ActionNameResolver): the Action class, unless anActionNameBuilderInterfaceservice supports it. Register one to get short, stable names such asorder.create.
The bridge is an Action middleware at priority 400, outside logging (300), validation (200) and lock (100):
the duration covers the whole pipeline the caller waits for, lock wait included. A failure to record the metric
is logged as an error to metrics-bundle's metrics_bundle channel (not counted by symfony_error) and never fails
the Action or replaces its exception.
PromQL
Success rate per Action:
sum by (action) (rate(symfony_logic_action_duration_histogram_seconds_count{outcome="success"}[5m]))
/ sum by (action) (rate(symfony_logic_action_duration_histogram_seconds_count[5m]))
p95 latency per Action:
histogram_quantile(0.95, sum by (le, action) (rate(symfony_logic_action_duration_histogram_seconds_bucket[5m])))
With metrics-bridge-profiling and
profiling-bridge-logic the same runs also appear as
spans in symfony_profiling_span_duration_histogram_seconds.
Public API
The bundle class Msstc4Symfony\MetricsBridgeLogic\MetricsBridgeLogicBundle and the metric definition
Msstc4Symfony\MetricsBridgeLogic\Infrastructure\Metrics\LogicMetric (its name, labels and buckets are what
dashboards rely on). The collector, the middleware and the compiler pass are @internal.
Local development
composer-ci.json installs logic-bundle and metrics-bundle; metrics-bundle needs ext-redis.
make install-ci # composer-ci.json profile with every CI tool COMPOSER=composer-ci.json make check # lint, PHPStan, CS, composer validate/audit, Rector, deptrac make test # unit + integration
License
MIT — see LICENSE.