Skip to content

feat: otel hook #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 27, 2022
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
28 changes: 16 additions & 12 deletions .github/workflows/php-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-version: ['7.4', '8.0', '8.1']
project: ['Flagd', 'Split', 'CloudBees']
php-version: ['7.4', '8.0', '8.1', '8.2']
project-dir:
- hooks/OpenTelemetry
- providers/Flagd
- providers/Split
- providers/CloudBees

# todo exclude some matrix combinations based on php version requirements
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#excluding-matrix-configurations
Expand All @@ -40,55 +44,55 @@ jobs:
id: composer-cache
uses: actions/cache@v3
with:
path: src/${{ matrix.project }}/vendor
path: ${{ matrix.project-dir }}/vendor
key: ${{ runner.os }}-${{ matrix.php-version }}-php-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-${{ matrix.php-version }}-php-

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
working-directory: src/${{ matrix.project }}
working-directory: ${{ matrix.project-dir }}
run: composer install --prefer-dist --no-progress --no-suggest

- name: Validate Packages composer.json
working-directory: src/${{ matrix.project }}
working-directory: ${{ matrix.project-dir }}
run: composer validate

- name: Check Style
working-directory: src/${{ matrix.project }}
working-directory: ${{ matrix.project-dir }}
run: vendor/bin/phpcs

- name: Run Phan
working-directory: src/${{ matrix.project }}
working-directory: ${{ matrix.project-dir }}
env:
PHAN_DISABLE_XDEBUG_WARN: 1
run: vendor/bin/phan

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

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

- name: Run PHPUnit (unit tests)
working-directory: src/${{ matrix.project }}
working-directory: ${{ matrix.project-dir }}
run: |
composer run dev:test:unit:setup
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover --testsuite unit
composer run dev:test:unit:teardown

- name: Run PHPUnit (integration tests)
working-directory: src/${{ matrix.project }}
working-directory: ${{ matrix.project-dir }}
run: |
composer run dev:test:integration:setup
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover --testsuite integration
composer run dev:test:integration:teardown

### TODO: Enable codecov support
# - name: Code Coverage
# working-directory: src/${{ matrix.project }}
# working-directory: ${{ matrix.project-dir }}
# run: bash <(curl -s https://codecov.io/bash) -F ${{ matrix.php-version }}

### TODO: Replicate any necessary package checks
Expand Down
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "schemas"]
path = src/Flagd/schemas
path = providers/Flagd/schemas
url = https://github.com/tcarrio/schemas/
[submodule "providers/Flagd/schemas"]
path = providers/Flagd/schemas
url = https://github.com/tcarrio/schemas/
8 changes: 5 additions & 3 deletions .gitsplit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ project_url: "https://github.com/open-feature/php-sdk-contrib.git"

# List of splits.
splits:
- prefix: "src/Flagd"
- prefix: "hooks/OpenTelemetry"
target: "https://${GH_TOKEN}@github.com/open-feature-php/otel-hook.git"
- prefix: "providers/Flagd"
target: "https://${GH_TOKEN}@github.com/open-feature-php/flagd-provider.git"
- prefix: "src/Split"
- prefix: "providers/Split"
target: "https://${GH_TOKEN}@github.com/open-feature-php/split-provider.git"
- prefix: "src/CloudBees"
- prefix: "providers/CloudBees"
target: "https://${GH_TOKEN}@github.com/open-feature-php/cloudbees-provider.git"

# List of references to split (defined as regexp)
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

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

- [Flagd](./src/Flagd/README.md)
- [Split](./src/Split/README.md)
- [CloudBees](./src/CloudBees/README.md)
- Providers
- [Flagd](./providers/Flagd/README.md)
- [Split](./providers/Split/README.md)
- [CloudBees](./providers/CloudBees/README.md)
- Hooks
- [OpenTelemetry](./hooks/OpenTelemetry/README.md)

### Status

Expand Down
Empty file added hooks/.gitkeep
Empty file.
File renamed without changes.
56 changes: 56 additions & 0 deletions hooks/OpenTelemetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# OpenFeature OpenTelemetry Hook

[![a](https://img.shields.io/badge/slack-%40cncf%2Fopenfeature-brightgreen?style=flat&logo=slack)](https://cloud-native.slack.com/archives/C0344AANLA1)
[![Latest Stable Version](http://poser.pugx.org/open-feature/otel-hook/v)](https://packagist.org/packages/open-feature/otel-hook)
[![Total Downloads](http://poser.pugx.org/open-feature/otel-hook/downloads)](https://packagist.org/packages/open-feature/otel-hook)
![PHP 7.4+](https://img.shields.io/badge/php->=7.4-blue.svg)
[![License](http://poser.pugx.org/open-feature/otel-hook/license)](https://packagist.org/packages/open-feature/otel-hook)

## Overview

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.

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).

### OpenTelemetry Package Status

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.

## Installation

```
$ composer require open-feature/otel-hook // installs the latest version
```

## Usage

The `OpenTelemetryHook` should be registered to the OpenFeatureAPI globally for use across all evaluations.

It makes use of the `open-telemetry/api` packages `Globals` utility for current span retrieval, thus has
no dependency on configuration or injection of tracers.

```php
use OpenFeature\Hooks\OpenTelemetry\OpenTelemetryHook;

OpenTelemetryHook::register();
```

For more information on OpenTelemetry, check out [their documentation](https://opentelemetry.io/docs/instrumentation/php/).

## Development

### PHP Versioning

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.

This package also has a `.tool-versions` file for use with PHP version managers like `asdf`.

### Installation and Dependencies

Install dependencies with `composer install`. `composer install` will update the `composer.lock` with the most recent compatible versions.

We value having as few runtime dependencies as possible. The addition of any dependencies requires careful consideration and review.

### Testing

Run tests with `composer run test`.
136 changes: 136 additions & 0 deletions hooks/OpenTelemetry/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"name": "open-feature/split-provider",
"description": "The Split provider package for OpenFeature",
"license": "Apache-2.0",
"type": "library",
"keywords": [
"featureflags",
"featureflagging",
"openfeature",
"split",
"splitio",
"provider"
],
"authors": [
{
"name": "OpenFeature PHP Maintainers",
"homepage": "https://github.com/orgs/open-feature/teams/php-maintainer"
},
{
"name": "open-feature/php-sdk-contrib Contributors",
"homepage": "https://github.com/open-feature/php-sdk-contrib/graphs/contributors"
}
],
"require": {
"php": "^7.4 || ^8",
"open-feature/sdk": "^1.1.0",
"open-telemetry/api": "^0.0.17",
"splitsoftware/split-sdk-php": "^7.1"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.25",
"friendsofphp/php-cs-fixer": "^3.13",
"hamcrest/hamcrest-php": "^2.0",
"mdwheele/zalgo": "^0.3.1",
"mikey179/vfsstream": "v1.6.11",
"mockery/mockery": "^1.5",
"phan/phan": "^5.4",
"php-parallel-lint/php-console-highlighter": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "~1.9.0",
"phpstan/phpstan-mockery": "^1.0",
"phpstan/phpstan-phpunit": "^1.1",
"psalm/plugin-mockery": "^0.9.1",
"psalm/plugin-phpunit": "^0.18.0",
"ramsey/coding-standard": "^2.0.3",
"ramsey/composer-repl": "^1.4",
"ramsey/conventional-commits": "^1.3",
"roave/security-advisories": "dev-latest",
"spatie/phpunit-snapshot-assertions": "^4.2",
"vimeo/psalm": "~4.30.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"OpenFeature\\Hooks\\OpenTelemetry\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"OpenFeature\\Hooks\\OpenTelemetry\\Test\\": "tests"
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true,
"captainhook/plugin-composer": true,
"ramsey/composer-repl": true
},
"sort-packages": true
},
"extra": {
"captainhook": {
"force-install": false
}
},
"scripts": {
"dev:analyze": [
"@dev:analyze:phpstan",
"@dev:analyze:psalm"
],
"dev:analyze:phpstan": "phpstan analyse --ansi --debug --memory-limit=512M",
"dev:analyze:psalm": "psalm",
"dev:build:clean": "git clean -fX build/",
"dev:lint": [
"@dev:lint:syntax",
"@dev:lint:style"
],
"dev:lint:fix": "phpcbf",
"dev:lint:style": "phpcs --colors",
"dev:lint:syntax": "parallel-lint --colors src/ tests/",
"dev:test": [
"@dev:lint",
"@dev:analyze",
"@dev:test:unit",
"@dev:test:integration"
],
"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",
"dev:test:coverage:html": "phpunit --colors=always --coverage-html build/coverage/coverage-html/",
"dev:test:unit": [
"@dev:test:unit:setup",
"phpunit --colors=always --testdox --testsuite=unit",
"@dev:test:unit:teardown"
],
"dev:test:unit:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
"dev:test:unit:setup": "echo 'Setup for unit tests...'",
"dev:test:unit:teardown": "echo 'Tore down for unit tests...'",
"dev:test:integration": [
"@dev:test:integration:setup",
"echo 'No integration tests to run'",
"@dev:test:integration:teardown"
],
"dev:test:integration:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
"dev:test:integration:setup": "echo 'Setup for integration tests...'",
"dev:test:integration:teardown": "echo 'Tore down integration tests...'",
"test": "@dev:test"
},
"scripts-descriptions": {
"dev:analyze": "Runs all static analysis checks.",
"dev:analyze:phpstan": "Runs the PHPStan static analyzer.",
"dev:analyze:psalm": "Runs the Psalm static analyzer.",
"dev:build:clean": "Cleans the build/ directory.",
"dev:lint": "Runs all linting checks.",
"dev:lint:fix": "Auto-fixes coding standards issues, if possible.",
"dev:lint:style": "Checks for coding standards issues.",
"dev:lint:syntax": "Checks for syntax errors.",
"dev:test": "Runs linting, static analysis, and unit tests.",
"dev:test:coverage:ci": "Runs unit tests and generates CI coverage reports.",
"dev:test:coverage:html": "Runs unit tests and generates HTML coverage report.",
"dev:test:unit": "Runs unit tests.",
"test": "Runs linting, static analysis, and unit tests."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# OpenFeature OpenTelemetry Hook example

This example provides an example of bootstrapping and using the OpenTelemetry hook for OpenFeature.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "open-feature/otel-manual-instrumentation-example",
"description": "An example of using the OpenTelemetry hook for OpenFeature with manual instrumentation",
"type": "project",
"license": "Apache-2.0",
"autoload": {
"psr-4": {
"OpenFeature\\Providers\\Examples\\SplitSdkExample\\": "src/"
}
},
"authors": [
{
"name": "Tom Carrio",
"email": "[email protected]"
}
],
"require": {
"open-feature/sdk": "^1.1.2",
"open-telemetry/api": "^0.0.17"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// 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.
Loading