Skip to content

Commit c293fc3

Browse files
committed
feat: added OTel hook for OpenFeature
- new statically registerable OTel hook for OpenFeature - move hooks and providers into independent directories - enable PHP 8.2 runner - disable integration tests since none exist - utilize test wrapper script definition in CI Ref: #6 Signed-off-by: Tom Carrio <[email protected]> Signed-off-by: Tom Carrio <[email protected]>
1 parent 9a56d76 commit c293fc3

File tree

136 files changed

+571
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+571
-25
lines changed

Diff for: .github/workflows/php-ci.yaml

+18-18
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ jobs:
1212
strategy:
1313
matrix:
1414
operating-system: [ubuntu-latest]
15-
php-version: ['7.4', '8.0', '8.1']
16-
project: ['Flagd', 'Split', 'CloudBees']
15+
php-version: ['7.4', '8.0', '8.1', '8.2']
16+
project-dir:
17+
- hooks/OpenTelemetry
18+
- providers/Flagd
19+
- providers/Split
20+
- providers/CloudBees
1721

1822
# todo exclude some matrix combinations based on php version requirements
1923
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#excluding-matrix-configurations
@@ -40,55 +44,51 @@ jobs:
4044
id: composer-cache
4145
uses: actions/cache@v3
4246
with:
43-
path: src/${{ matrix.project }}/vendor
47+
path: ${{ matrix.project-dir }}/vendor
4448
key: ${{ runner.os }}-${{ matrix.php-version }}-php-${{ hashFiles('**/composer.json') }}
4549
restore-keys: |
4650
${{ runner.os }}-${{ matrix.php-version }}-php-
4751
4852
- name: Install dependencies
4953
if: steps.composer-cache.outputs.cache-hit != 'true'
50-
working-directory: src/${{ matrix.project }}
54+
working-directory: ${{ matrix.project-dir }}
5155
run: composer install --prefer-dist --no-progress --no-suggest
5256

5357
- name: Validate Packages composer.json
54-
working-directory: src/${{ matrix.project }}
58+
working-directory: ${{ matrix.project-dir }}
5559
run: composer validate
5660

5761
- name: Check Style
58-
working-directory: src/${{ matrix.project }}
62+
working-directory: ${{ matrix.project-dir }}
5963
run: vendor/bin/phpcs
6064

6165
- name: Run Phan
62-
working-directory: src/${{ matrix.project }}
66+
working-directory: ${{ matrix.project-dir }}
6367
env:
6468
PHAN_DISABLE_XDEBUG_WARN: 1
6569
run: vendor/bin/phan
6670

6771
- name: Run Psalm
68-
working-directory: src/${{ matrix.project }}
72+
working-directory: ${{ matrix.project-dir }}
6973
run: vendor/bin/psalm --output-format=github --php-version=${{ matrix.php-version }}
7074

7175
- name: Run Phpstan
72-
working-directory: src/${{ matrix.project }}
76+
working-directory: ${{ matrix.project-dir }}
7377
run: vendor/bin/phpstan analyse --error-format=github
7478

7579
- name: Run PHPUnit (unit tests)
76-
working-directory: src/${{ matrix.project }}
80+
working-directory: ${{ matrix.project-dir }}
7781
run: |
78-
composer run dev:test:unit:setup
79-
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover --testsuite unit
80-
composer run dev:test:unit:teardown
82+
composer run dev:test:unit
8183
8284
- name: Run PHPUnit (integration tests)
83-
working-directory: src/${{ matrix.project }}
85+
working-directory: ${{ matrix.project-dir }}
8486
run: |
85-
composer run dev:test:integration:setup
86-
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover --testsuite integration
87-
composer run dev:test:integration:teardown
87+
composer run dev:test:integration
8888
8989
### TODO: Enable codecov support
9090
# - name: Code Coverage
91-
# working-directory: src/${{ matrix.project }}
91+
# working-directory: ${{ matrix.project-dir }}
9292
# run: bash <(curl -s https://codecov.io/bash) -F ${{ matrix.php-version }}
9393

9494
### TODO: Replicate any necessary package checks

Diff for: .gitmodules

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "schemas"]
2-
path = src/Flagd/schemas
2+
path = providers/Flagd/schemas
3+
url = https://github.com/tcarrio/schemas/
4+
[submodule "providers/Flagd/schemas"]
5+
path = providers/Flagd/schemas
36
url = https://github.com/tcarrio/schemas/

Diff for: .gitsplit.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ project_url: "https://github.com/open-feature/php-sdk-contrib.git"
66

77
# List of splits.
88
splits:
9-
- prefix: "src/Flagd"
9+
- prefix: "hooks/OpenTelemetry"
10+
target: "https://${GH_TOKEN}@github.com/open-feature-php/otel-hook.git"
11+
- prefix: "providers/Flagd"
1012
target: "https://${GH_TOKEN}@github.com/open-feature-php/flagd-provider.git"
11-
- prefix: "src/Split"
13+
- prefix: "providers/Split"
1214
target: "https://${GH_TOKEN}@github.com/open-feature-php/split-provider.git"
13-
- prefix: "src/CloudBees"
15+
- prefix: "providers/CloudBees"
1416
target: "https://${GH_TOKEN}@github.com/open-feature-php/cloudbees-provider.git"
1517

1618
# List of references to split (defined as regexp)

Diff for: README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99

1010
The `php-contrib-sdk` repository is a monorepository containing various providers and hooks for OpenFeature's PHP SDK. Packages include:
1111

12-
- [Flagd](./src/Flagd/README.md)
13-
- [Split](./src/Split/README.md)
14-
- [CloudBees](./src/CloudBees/README.md)
12+
- Providers
13+
- [Flagd](./providers/Flagd/README.md)
14+
- [Split](./providers/Split/README.md)
15+
- [CloudBees](./providers/CloudBees/README.md)
16+
- Hooks
17+
- [OpenTelemetry](./hooks/OpenTelemetry/README.md)
1518

1619
### Status
1720

Diff for: hooks/.gitkeep

Whitespace-only changes.
File renamed without changes.

Diff for: hooks/OpenTelemetry/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# OpenFeature OpenTelemetry Hook
2+
3+
[![a](https://img.shields.io/badge/slack-%40cncf%2Fopenfeature-brightgreen?style=flat&logo=slack)](https://cloud-native.slack.com/archives/C0344AANLA1)
4+
[![Latest Stable Version](http://poser.pugx.org/open-feature/otel-hook/v)](https://packagist.org/packages/open-feature/otel-hook)
5+
[![Total Downloads](http://poser.pugx.org/open-feature/otel-hook/downloads)](https://packagist.org/packages/open-feature/otel-hook)
6+
![PHP 7.4+](https://img.shields.io/badge/php->=7.4-blue.svg)
7+
[![License](http://poser.pugx.org/open-feature/otel-hook/license)](https://packagist.org/packages/open-feature/otel-hook)
8+
9+
## Overview
10+
11+
OpenTelemetry is an open specification for distributed tracing, metrics, and logging. It defines a semantic convention for feature flagging which is utilized in this hook to report flag evaluations.
12+
13+
This package also builds on various PSRs (PHP Standards Recommendations) such as the Logger interfaces (PSR-3) and the Basic and Extended Coding Standards (PSR-1 and PSR-12).
14+
15+
### OpenTelemetry Package Status
16+
17+
The OpenTelemetry package for PHP is still in beta, so there could be changes required. However, it exposes global primitives for span retrieval that should not require any configuration upfront for the provider to just work.
18+
19+
## Installation
20+
21+
```
22+
$ composer require open-feature/otel-hook // installs the latest version
23+
```
24+
25+
## Usage
26+
27+
The `OpenTelemetryHook` should be registered to the OpenFeatureAPI globally for use across all evaluations.
28+
29+
It makes use of the `open-telemetry/api` packages `Globals` utility for current span retrieval, thus has
30+
no dependency on configuration or injection of tracers.
31+
32+
```php
33+
use OpenFeature\Hooks\OpenTelemetry\OpenTelemetryHook;
34+
35+
OpenTelemetryHook::register();
36+
```
37+
38+
For more information on OpenTelemetry, check out [their documentation](https://opentelemetry.io/docs/instrumentation/php/).
39+
40+
## Development
41+
42+
### PHP Versioning
43+
44+
This library targets PHP version 7.4 and newer. As long as you have any compatible version of PHP on your system you should be able to utilize the OpenFeature SDK.
45+
46+
This package also has a `.tool-versions` file for use with PHP version managers like `asdf`.
47+
48+
### Installation and Dependencies
49+
50+
Install dependencies with `composer install`. `composer install` will update the `composer.lock` with the most recent compatible versions.
51+
52+
We value having as few runtime dependencies as possible. The addition of any dependencies requires careful consideration and review.
53+
54+
### Testing
55+
56+
Run tests with `composer run test`.

Diff for: hooks/OpenTelemetry/composer.json

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"name": "open-feature/split-provider",
3+
"description": "The Split provider package for OpenFeature",
4+
"license": "Apache-2.0",
5+
"type": "library",
6+
"keywords": [
7+
"featureflags",
8+
"featureflagging",
9+
"openfeature",
10+
"split",
11+
"splitio",
12+
"provider"
13+
],
14+
"authors": [
15+
{
16+
"name": "OpenFeature PHP Maintainers",
17+
"homepage": "https://github.com/orgs/open-feature/teams/php-maintainer"
18+
},
19+
{
20+
"name": "open-feature/php-sdk-contrib Contributors",
21+
"homepage": "https://github.com/open-feature/php-sdk-contrib/graphs/contributors"
22+
}
23+
],
24+
"require": {
25+
"php": "^7.4 || ^8",
26+
"open-feature/sdk": "^1.1.0",
27+
"open-telemetry/api": "^0.0.17",
28+
"splitsoftware/split-sdk-php": "^7.1"
29+
},
30+
"require-dev": {
31+
"ergebnis/composer-normalize": "^2.25",
32+
"friendsofphp/php-cs-fixer": "^3.13",
33+
"hamcrest/hamcrest-php": "^2.0",
34+
"mdwheele/zalgo": "^0.3.1",
35+
"mikey179/vfsstream": "v1.6.11",
36+
"mockery/mockery": "^1.5",
37+
"phan/phan": "^5.4",
38+
"php-parallel-lint/php-console-highlighter": "^1.0",
39+
"php-parallel-lint/php-parallel-lint": "^1.3",
40+
"phpstan/extension-installer": "^1.1",
41+
"phpstan/phpstan": "~1.9.0",
42+
"phpstan/phpstan-mockery": "^1.0",
43+
"phpstan/phpstan-phpunit": "^1.1",
44+
"psalm/plugin-mockery": "^0.9.1",
45+
"psalm/plugin-phpunit": "^0.18.0",
46+
"ramsey/coding-standard": "^2.0.3",
47+
"ramsey/composer-repl": "^1.4",
48+
"ramsey/conventional-commits": "^1.3",
49+
"roave/security-advisories": "dev-latest",
50+
"spatie/phpunit-snapshot-assertions": "^4.2",
51+
"vimeo/psalm": "~4.30.0"
52+
},
53+
"minimum-stability": "dev",
54+
"prefer-stable": true,
55+
"autoload": {
56+
"psr-4": {
57+
"OpenFeature\\Hooks\\OpenTelemetry\\": "src"
58+
}
59+
},
60+
"autoload-dev": {
61+
"psr-4": {
62+
"OpenFeature\\Hooks\\OpenTelemetry\\Test\\": "tests"
63+
}
64+
},
65+
"config": {
66+
"allow-plugins": {
67+
"phpstan/extension-installer": true,
68+
"dealerdirect/phpcodesniffer-composer-installer": true,
69+
"ergebnis/composer-normalize": true,
70+
"captainhook/plugin-composer": true,
71+
"ramsey/composer-repl": true
72+
},
73+
"sort-packages": true
74+
},
75+
"extra": {
76+
"captainhook": {
77+
"force-install": false
78+
}
79+
},
80+
"scripts": {
81+
"dev:analyze": [
82+
"@dev:analyze:phpstan",
83+
"@dev:analyze:psalm"
84+
],
85+
"dev:analyze:phpstan": "phpstan analyse --ansi --debug --memory-limit=512M",
86+
"dev:analyze:psalm": "psalm",
87+
"dev:build:clean": "git clean -fX build/",
88+
"dev:lint": [
89+
"@dev:lint:syntax",
90+
"@dev:lint:style"
91+
],
92+
"dev:lint:fix": "phpcbf",
93+
"dev:lint:style": "phpcs --colors",
94+
"dev:lint:syntax": "parallel-lint --colors src/ tests/",
95+
"dev:test": [
96+
"@dev:lint",
97+
"@dev:analyze",
98+
"@dev:test:unit",
99+
"@dev:test:integration"
100+
],
101+
"dev:test:coverage:ci": "phpunit --colors=always --coverage-text --coverage-clover build/coverage/clover.xml --coverage-cobertura build/coverage/cobertura.xml --coverage-crap4j build/coverage/crap4j.xml --coverage-xml build/coverage/coverage-xml --log-junit build/junit.xml",
102+
"dev:test:coverage:html": "phpunit --colors=always --coverage-html build/coverage/coverage-html/",
103+
"dev:test:unit": [
104+
"@dev:test:unit:setup",
105+
"phpunit --colors=always --testdox --testsuite=unit",
106+
"@dev:test:unit:teardown"
107+
],
108+
"dev:test:unit:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
109+
"dev:test:unit:setup": "echo 'Setup for unit tests...'",
110+
"dev:test:unit:teardown": "echo 'Tore down for unit tests...'",
111+
"dev:test:integration": [
112+
"@dev:test:integration:setup",
113+
"echo 'No integration tests to run'",
114+
"@dev:test:integration:teardown"
115+
],
116+
"dev:test:integration:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
117+
"dev:test:integration:setup": "echo 'Setup for integration tests...'",
118+
"dev:test:integration:teardown": "echo 'Tore down integration tests...'",
119+
"test": "@dev:test"
120+
},
121+
"scripts-descriptions": {
122+
"dev:analyze": "Runs all static analysis checks.",
123+
"dev:analyze:phpstan": "Runs the PHPStan static analyzer.",
124+
"dev:analyze:psalm": "Runs the Psalm static analyzer.",
125+
"dev:build:clean": "Cleans the build/ directory.",
126+
"dev:lint": "Runs all linting checks.",
127+
"dev:lint:fix": "Auto-fixes coding standards issues, if possible.",
128+
"dev:lint:style": "Checks for coding standards issues.",
129+
"dev:lint:syntax": "Checks for syntax errors.",
130+
"dev:test": "Runs linting, static analysis, and unit tests.",
131+
"dev:test:coverage:ci": "Runs unit tests and generates CI coverage reports.",
132+
"dev:test:coverage:html": "Runs unit tests and generates HTML coverage report.",
133+
"dev:test:unit": "Runs unit tests.",
134+
"test": "Runs linting, static analysis, and unit tests."
135+
}
136+
}
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# OpenFeature OpenTelemetry Hook example
2+
3+
This example provides an example of bootstrapping and using the OpenTelemetry hook for OpenFeature.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "open-feature/otel-manual-instrumentation-example",
3+
"description": "An example of using the OpenTelemetry hook for OpenFeature with manual instrumentation",
4+
"type": "project",
5+
"license": "Apache-2.0",
6+
"autoload": {
7+
"psr-4": {
8+
"OpenFeature\\Providers\\Examples\\SplitSdkExample\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "Tom Carrio",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"require": {
18+
"open-feature/sdk": "^1.1.2",
19+
"open-telemetry/api": "^0.0.17"
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
// TODO: Pull in example from https://github.com/open-telemetry/opentelemetry-php/tree/main/examples/traces/demo
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)