Introduction
PHPUnit Telemetry Bridge
PHPUnit extension allowing to collect test suite telemetry and export to OTEL collector.
Table of Contents
Installation
composer require flow-php/phpunit-telemetry-bridge:~0.32.0
Configuration
Add the extension to your phpunit.xml.dist:
<extensions>
<bootstrap class="Flow\Bridge\PHPUnit\Telemetry\TelemetryExtension">
<parameter name="service_name" value="my-test-suite"/>
<parameter name="otel_collector_url" value="http://localhost:4318"/>
<parameter name="emit_traces" value="true"/>
<parameter name="emit_metrics" value="true"/>
<parameter name="emit_test_spans" value="false"/>
<parameter name="emit_test_case_spans" value="false"/>
</bootstrap>
</extensions>
Configuration Parameters
| Parameter | Default | Description |
|---|---|---|
service_name |
phpunit |
Service name used in telemetry data |
otel_collector_url |
http://localhost:4318 |
OTLP HTTP endpoint URL |
emit_traces |
true |
Enable/disable trace emission |
emit_metrics |
true |
Enable/disable metric emission |
emit_test_spans |
true |
Create individual spans for each test |
emit_test_case_spans |
true |
Create spans for test case classes |
Features
Traces
When enabled, the extension creates spans for:
- Test suite runs (root span)
- Individual test suites
- Test case classes (optional)
- Individual tests (optional)
Each span includes attributes like:
test.suite- Test suite nametest.id- Test identifiertest.name- Test nametest.class- Test class nametest.method- Test method nametest.status- Test result status (passed, failed, errored, skipped, incomplete)
Metrics
When enabled, the extension records:
phpunit.suite.duration- Histogram of suite execution timephpunit.suite.test_count- Counter of tests per suitephpunit.test.duration- Histogram of individual test execution timephpunit.test.count- Counter of tests by status
Running with Docker Compose
To visualize test telemetry, run an OTEL collector with a backend like Jaeger:
services:
otel-collector:
image: otel/opentelemetry-collector:latest
ports:
- "4317:4317" # OTLP gRPC
- "4318:4318" # OTLP HTTP
volumes:
- ./otel-collector-config.yaml:/etc/otelcol/config.yaml
jaeger:
image: jaegertracing/all-in-one:latest
ports:
- "16686:16686" # UI
Then run your tests:
./vendor/bin/phpunit
View the traces in Jaeger at http://localhost:16686.