Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ component_management:
name: adapter-postgresql
paths:
- src/adapter/etl-adapter-postgresql/**
- component_id: bridge-phpunit-telemetry
name: bridge-phpunit-telemetry
paths:
- src/bridge/phpunit/telemetry/**
2 changes: 2 additions & 0 deletions .github/workflows/monorepo-split.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ jobs:
split_repository: 'symfony-telemetry-bundle'
- local_path: 'src/bridge/telemetry/otlp'
split_repository: 'telemetry-otlp-bridge'
- local_path: 'src/bridge/phpunit/telemetry'
split_repository: 'phpunit-telemetry-bridge'

- local_path: 'src/extension/pg-query-ext'
split_repository: 'pg-query-ext'
Expand Down
2 changes: 0 additions & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
__DIR__ . '/web/landing/tests',
__DIR__ . '/web/landing/bin',
__DIR__ . '/tools/rector/src',
__DIR__ . '/tools/phpunit/extension/telemetry/src',
__DIR__ . '/tools/phpunit/extension/telemetry/tests',
])
->exclude([
'Flow/Parquet/ThriftModel',
Expand Down
16 changes: 7 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
"flow-php/telemetry": "self.version",
"flow-php/telemetry-otlp-bridge": "self.version",
"flow-php/types": "self.version",
"flow-php/phpunit-telemetry": "self.version"
"flow-php/phpunit-telemetry": "self.version",
"flow-php/phpunit-telemetry-bridge": "self.version"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down Expand Up @@ -145,6 +146,7 @@
"src/bridge/symfony/http-foundation/src/Flow",
"src/bridge/symfony/telemetry-bundle/src/Flow",
"src/bridge/telemetry/otlp/src/Flow",
"src/bridge/phpunit/telemetry/src/Flow",
"src/cli/src/Flow",
"src/core/etl/src/Flow",
"src/lib/array-dot/src/Flow",
Expand All @@ -165,9 +167,6 @@
],
"Flow\\ETL\\Adapter\\Doctrine\\": [
"src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine"
],
"Flow\\Tool\\PHPUnit\\Telemetry\\": [
"tools/phpunit/extension/telemetry/src/Flow/Tool/PHPUnit/Telemetry"
]
},
"files": [
Expand Down Expand Up @@ -238,6 +237,7 @@
"src/bridge/symfony/http-foundation/tests/Flow",
"src/bridge/symfony/telemetry-bundle/tests/Flow",
"src/bridge/telemetry/otlp/tests/Flow",
"src/bridge/phpunit/telemetry/tests/Flow",
"src/cli/tests/Flow",
"src/core/etl/tests/Flow",
"src/lib/array-dot/tests/Flow",
Expand All @@ -258,9 +258,6 @@
],
"Flow\\ETL\\Adapter\\Doctrine\\Tests\\": [
"src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests"
],
"Flow\\Tool\\PHPUnit\\Telemetry\\Tests\\": [
"tools/phpunit/extension/telemetry/tests/Flow/Tool/PHPUnit/Telemetry/Tests"
]
}
},
Expand Down Expand Up @@ -307,6 +304,7 @@
"@test:bridge:monolog-http",
"@test:bridge:monolog-telemetry",
"@test:bridge:openapi-specification",
"@test:bridge:phpunit-telemetry",
"@test:bridge:psr7-telemetry",
"@test:bridge:psr18-telemetry",
"@test:bridge:symfony-http-foundation",
Expand Down Expand Up @@ -462,8 +460,8 @@
"tools/phpunit/vendor/bin/phpunit --testsuite=adapter-postgresql-unit --log-junit ./var/phpunit/logs/adapter-postgresql-unit.junit.xml --coverage-clover=./var/phpunit/coverage/clover/adapter-postgresql-unit.coverage.xml",
"tools/phpunit/vendor/bin/phpunit --testsuite=adapter-postgresql-integration --log-junit ./var/phpunit/logs/adapter-postgresql-integration.junit.xml --coverage-clover=./var/phpunit/coverage/clover/adapter-postgresql-integration.coverage.xml"
],
"test:tool:phpunit-telemetry": [
"tools/phpunit/vendor/bin/phpunit --testsuite=tool-phpunit-telemetry-unit --log-junit ./var/phpunit/logs/tool-phpunit-telemetry-unit.junit.xml --coverage-clover=./var/phpunit/coverage/clover/tool-phpunit-telemetry-unit.coverage.xml"
"test:bridge:phpunit-telemetry": [
"tools/phpunit/vendor/bin/phpunit --testsuite=bridge-phpunit-telemetry-unit --log-junit ./var/phpunit/logs/bridge-phpunit-telemetry-unit.junit.xml --coverage-clover=./var/phpunit/coverage/clover/bridge-phpunit-telemetry-unit.coverage.xml"
],
"test:docs": [
"docker run -t --rm -v $PWD:/app norberttech/md-link-linter --exclude=vendor --exclude=.scratchpad --exclude=documentation ."
Expand Down
98 changes: 98 additions & 0 deletions documentation/components/bridges/phpunit-telemetry-bridge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# PHPUnit Telemetry Bridge

PHPUnit extension allowing to collect test suite telemetry and export to OTEL collector.

- [Back](/documentation/introduction.md)
- [Packagist](https://packagist.org/packages/flow-php/phpunit-telemetry-bridge)
- [GitHub](https://github.com/flow-php/phpunit-telemetry-bridge)
- [API Reference](/documentation/api/bridge/phpunit/telemetry)

[TOC]

## Installation

```bash
composer require flow-php/phpunit-telemetry-bridge:~--FLOW_PHP_VERSION--
```

## Configuration

Add the extension to your `phpunit.xml.dist`:

```xml
<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 name
- `test.id` - Test identifier
- `test.name` - Test name
- `test.class` - Test class name
- `test.method` - Test method name
- `test.status` - Test result status (passed, failed, errored, skipped, incomplete)

### Metrics

When enabled, the extension records:
- `phpunit.suite.duration` - Histogram of suite execution time
- `phpunit.suite.test_count` - Counter of tests per suite
- `phpunit.test.duration` - Histogram of individual test execution time
- `phpunit.test.count` - Counter of tests by status

## Running with Docker Compose

To visualize test telemetry, run an OTEL collector with a backend like Jaeger:

```yaml
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:

```bash
./vendor/bin/phpunit
```

View the traces in Jaeger at `http://localhost:16686`.
5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
"name" : "flow-php/postgresql",
"path": "src/lib/postgresql",
"type": "lib"
},
{
"name": "flow-php/phpunit-telemetry-bridge",
"path": "src/bridge/phpunit/telemetry",
"type": "bridge"
}
]
}
24 changes: 24 additions & 0 deletions phpdoc/bridge.phpunit.telemetry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
>
<title>Flow PHP</title>
<paths>
<output>./../web/landing/build/documentation/api/bridge/phpunit/telemetry</output>
<cache>./../var/phpdocumentor/cache/bridge/phpunit/telemetry</cache>
</paths>
<version number="1.x">
<api format="php">
<source dsn="./../">
<path>src/bridge/phpunit/telemetry/src</path>
</source>
<output>telemetry</output>
<default-package-name>PHPUnit Telemetry</default-package-name>
<visibility>public</visibility>
<include-source>false</include-source>
</api>
</version>
<setting name="template.color" value="orange"/>
</phpdocumentor>
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ parameters:
- src/lib/types/src
- src/lib/postgresql/src
- src/tools/documentation/src
- tools/phpunit/extension/telemetry/src
- tools/phpunit/extension/telemetry/tests
- src/bridge/phpunit/telemetry/src
- src/bridge/phpunit/telemetry/tests
- src/core/etl/tests
- src/cli/tests
- src/adapter/etl-adapter-avro/tests
Expand Down
6 changes: 3 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@
<testsuite name="adapter-xml-integration">
<directory>src/adapter/etl-adapter-xml/tests/Flow/ETL/Adapter/XML/Tests/Integration</directory>
</testsuite>
<testsuite name="tool-phpunit-telemetry-unit">
<directory>tools/phpunit/extension/telemetry/tests/Flow/Tool/PHPUnit/Telemetry/Tests/Unit</directory>
<testsuite name="bridge-phpunit-telemetry-unit">
<directory>src/bridge/phpunit/telemetry/tests/Flow/Bridge/PHPUnit/Telemetry/Tests/Unit</directory>
</testsuite>
</testsuites>
<source>
Expand Down Expand Up @@ -271,7 +271,7 @@
</exclude>
</source>
<extensions>
<bootstrap class="Flow\Tool\PHPUnit\Telemetry\TelemetryExtension">
<bootstrap class="Flow\Bridge\PHPUnit\Telemetry\TelemetryExtension">
<parameter name="service_name" value="flow-php-test-suite"/>
<parameter name="otel_collector_url" value="http://localhost:4318"/>
<parameter name="emit_traces" value="true"/>
Expand Down
1 change: 0 additions & 1 deletion rector.src.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
__DIR__ . '/src/adapter/*/src',
__DIR__ . '/src/bridge/*/*/src',
__DIR__ . '/src/tools/*/src',
__DIR__ . '/tools/phpunit/extension/telemetry/src',
__DIR__ . '/web/landing/src',
])
->withSkip([
Expand Down
1 change: 0 additions & 1 deletion rector.tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
__DIR__ . '/src/adapter/*/*/tests',
__DIR__ . '/src/bridge/*/*/tests',
__DIR__ . '/src/tools/*/*/tests',
__DIR__ . '/tools/phpunit/extension/telemetry/tests',
__DIR__ . '/web/landing/tests',
])
->withSets([
Expand Down
9 changes: 9 additions & 0 deletions src/bridge/phpunit/telemetry/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.php text eol=lf

/.github export-ignore
/tests export-ignore

/README.md export-ignore

/.gitattributes export-ignore
/.gitignore export-ignore
17 changes: 17 additions & 0 deletions src/bridge/phpunit/telemetry/.github/workflows/readonly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Readonly

on:
pull_request_target:
types: [opened]

jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
comment: |
Hi, thank you for your contribution.
Unfortunately, this repository is read-only. It's a split from our main monorepo repository.
In order to proceed with this PR please open it against https://github.com/flow-php/flow repository.
Thank you.
6 changes: 6 additions & 0 deletions src/bridge/phpunit/telemetry/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Contributing

This repo is **READ ONLY**, in order to contribute to Flow PHP project, please
open PR against [flow](https://github.com/flow-php/flow) monorepo.

Changes merged to monorepo are automatically propagated into sub repositories.
19 changes: 19 additions & 0 deletions src/bridge/phpunit/telemetry/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2020-present Flow PHP

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions src/bridge/phpunit/telemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Flow PHP - PHPUnit Telemetry Bridge

PHPUnit extension allowing to collect test suite telemetry and export to OTEL collector.

> [!IMPORTANT]
> This repository is a subtree split from our monorepo. If you'd like to contribute,
> please visit our main monorepo [flow-php/flow](https://github.com/flow-php/flow).

## Installation

```bash
composer require flow-php/phpunit-telemetry-bridge
```

## Resources

- [Documentation](https://flow-php.com/documentation/components/bridges/phpunit-telemetry-bridge/)
- [Installation](https://flow-php.com/documentation/installation/)
- [Contributing](https://flow-php.com/documentation/contributing/)
- [Upgrading](https://flow-php.com/documentation/upgrading/)
Loading
Loading