Skip to content

Commit d2b1a04

Browse files
authored
feat: dd-trace hook (#26)
* feat: dd-trace-hook for Datadog APM Signed-off-by: Tom Carrio <[email protected]> * style: apply phpcbf fixes Signed-off-by: Tom Carrio <[email protected]> * style: apply fixes for phpstan Signed-off-by: Tom Carrio <[email protected]>
1 parent 789a95c commit d2b1a04

20 files changed

+611
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
name: Run Release Please
7+
jobs:
8+
release-please:
9+
runs-on: ubuntu-latest
10+
11+
# Release-please creates a PR that tracks all changes
12+
steps:
13+
- uses: google-github-actions/release-please-action@v3
14+
id: release
15+
with:
16+
command: manifest
17+
token: ${{secrets.GITHUB_TOKEN}}
18+
default-branch: main

hooks/DDTrace/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/composer.lock
2+
/vendor
3+
/build
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.0.1"
3+
}

hooks/DDTrace/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# OpenFeature DDTrace 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/dd-trace-hook/v)](https://packagist.org/packages/open-feature/dd-trace-hook)
5+
[![Total Downloads](http://poser.pugx.org/open-feature/dd-trace-hook/downloads)](https://packagist.org/packages/open-feature/dd-trace-hook)
6+
![PHP 7.4+](https://img.shields.io/badge/php->=7.4-blue.svg)
7+
[![License](http://poser.pugx.org/open-feature/dd-trace-hook/license)](https://packagist.org/packages/open-feature/dd-trace-hook)
8+
9+
## Overview
10+
11+
`dd-trace` is the Datadog tracing library for PHP. It is built on the OpenTracing specification.
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+
### Design
16+
17+
OpenTracing is now an archived project of the CNCF, with suggestions to move towards DDTrace. Feel free to check out our [DDTrace hook for OpenFeature](../DDTrace/README.md) as well. DDTrace defines a semantic convention for feature flagging which is utilized in this hook to report flag evaluations, which is the basis for the log events being performed in this library for `dd-trace`.
18+
19+
### Autoloading
20+
21+
This package supports Composer autoloading. Thus, simply installing the package is all you need in order to immediately get started with Datadog's DDTrace for OpenFeature! Examples are provided that showcase the simple setup as well. Check out the **Usage** section for more info.
22+
23+
## Installation
24+
25+
```
26+
$ composer require open-feature/dd-trace-hook // installs the latest version
27+
```
28+
29+
## Usage
30+
31+
The `DDTraceHook` should be registered to the OpenFeatureAPI globally for use across all evaluations.
32+
33+
It makes use of the `dd-trace` packages `Globals` utility for current span retrieval, thus has
34+
no dependency on configuration or injection of tracers.
35+
36+
```php
37+
use OpenFeature\Hooks\DDTrace\DDTraceHook;
38+
39+
DDTraceHook::register();
40+
```
41+
42+
For more information on DDTrace, check out [their documentation](https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/php?tab=containers).
43+
44+
For more examples, see the [examples](./examples/).
45+
46+
## Development
47+
48+
### PHP Versioning
49+
50+
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.
51+
52+
This package also has a `.tool-versions` file for use with PHP version managers like `asdf`.
53+
54+
### Installation and Dependencies
55+
56+
Install dependencies with `composer install`. `composer install` will update the `composer.lock` with the most recent compatible versions.
57+
58+
We value having as few runtime dependencies as possible. The addition of any dependencies requires careful consideration and review.
59+
60+
### Testing
61+
62+
Run tests with `composer run test`.

hooks/DDTrace/composer.json

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"name": "open-feature/dd-trace-hook",
3+
"description": "The Datadog dd-trace hook package for OpenFeature",
4+
"license": "Apache-2.0",
5+
"type": "library",
6+
"keywords": [
7+
"featureflags",
8+
"featureflagging",
9+
"openfeature",
10+
"dd-trace",
11+
"ddtrace",
12+
"datadog",
13+
"provider"
14+
],
15+
"authors": [
16+
{
17+
"name": "OpenFeature PHP Maintainers",
18+
"homepage": "https://github.com/orgs/open-feature/teams/php-maintainer"
19+
},
20+
{
21+
"name": "open-feature/php-sdk-contrib Contributors",
22+
"homepage": "https://github.com/open-feature/php-sdk-contrib/graphs/contributors"
23+
}
24+
],
25+
"require": {
26+
"php": "^7.4 || ^8",
27+
"open-feature/sdk": "^1.2.0"
28+
},
29+
"require-dev": {
30+
"datadog/dd-trace": "^0.82.0",
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\\DDTrace\\": "src"
58+
},
59+
"files": [
60+
"src/_autoload.php"
61+
]
62+
},
63+
"autoload-dev": {
64+
"psr-4": {
65+
"OpenFeature\\Hooks\\DDTrace\\Test\\": "tests"
66+
}
67+
},
68+
"config": {
69+
"allow-plugins": {
70+
"phpstan/extension-installer": true,
71+
"dealerdirect/phpcodesniffer-composer-installer": true,
72+
"ergebnis/composer-normalize": true,
73+
"captainhook/plugin-composer": true,
74+
"ramsey/composer-repl": true
75+
},
76+
"sort-packages": true
77+
},
78+
"extra": {
79+
"captainhook": {
80+
"force-install": false
81+
}
82+
},
83+
"scripts": {
84+
"dev:analyze": [
85+
"@dev:analyze:phpstan",
86+
"@dev:analyze:psalm"
87+
],
88+
"dev:analyze:phpstan": "phpstan analyse --ansi --debug --memory-limit=512M",
89+
"dev:analyze:psalm": "psalm",
90+
"dev:build:clean": "git clean -fX build/",
91+
"dev:lint": [
92+
"@dev:lint:syntax",
93+
"@dev:lint:style"
94+
],
95+
"dev:lint:fix": "phpcbf",
96+
"dev:lint:style": "phpcs --colors",
97+
"dev:lint:syntax": "parallel-lint --colors src/ tests/",
98+
"dev:test": [
99+
"@dev:lint",
100+
"@dev:analyze",
101+
"@dev:test:unit",
102+
"@dev:test:integration"
103+
],
104+
"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",
105+
"dev:test:coverage:html": "phpunit --colors=always --coverage-html build/coverage/coverage-html/",
106+
"dev:test:unit": [
107+
"@dev:test:unit:setup",
108+
"phpunit --colors=always --testdox --testsuite=unit",
109+
"@dev:test:unit:teardown"
110+
],
111+
"dev:test:unit:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
112+
"dev:test:unit:setup": "echo 'Setup for unit tests...'",
113+
"dev:test:unit:teardown": "echo 'Tore down for unit tests...'",
114+
"dev:test:integration": [
115+
"@dev:test:integration:setup",
116+
"phpunit --colors=always --testdox --testsuite=integration",
117+
"@dev:test:integration:teardown"
118+
],
119+
"dev:test:integration:debug": "phpunit --colors=always --testdox -d xdebug.profiler_enable=on",
120+
"dev:test:integration:setup": "echo 'Setup for integration tests...'",
121+
"dev:test:integration:teardown": "echo 'Tore down integration tests...'",
122+
"test": "@dev:test"
123+
},
124+
"scripts-descriptions": {
125+
"dev:analyze": "Runs all static analysis checks.",
126+
"dev:analyze:phpstan": "Runs the PHPStan static analyzer.",
127+
"dev:analyze:psalm": "Runs the Psalm static analyzer.",
128+
"dev:build:clean": "Cleans the build/ directory.",
129+
"dev:lint": "Runs all linting checks.",
130+
"dev:lint:fix": "Auto-fixes coding standards issues, if possible.",
131+
"dev:lint:style": "Checks for coding standards issues.",
132+
"dev:lint:syntax": "Checks for syntax errors.",
133+
"dev:test": "Runs linting, static analysis, and unit tests.",
134+
"dev:test:coverage:ci": "Runs unit tests and generates CI coverage reports.",
135+
"dev:test:coverage:html": "Runs unit tests and generates HTML coverage report.",
136+
"dev:test:unit": "Runs unit tests.",
137+
"test": "Runs linting, static analysis, and unit tests."
138+
}
139+
}

hooks/DDTrace/examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*/vendor
2+
/*/composer.lock
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# OpenFeature DDTrace Hook example
2+
3+
This example provides an example of bootstrapping and using the DDTrace hook for OpenFeature.
4+
5+
It showcases the auto-instrumentation functionality of OpenFeature and DDTrace, neither of which requiring imperative interactions with DDTrace to bootstrap, configure, and utilize it.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "open-feature/dd-trace-manual-instrumentation-example",
3+
"description": "An example of using the DDTrace hook for OpenFeature with manual instrumentation",
4+
"type": "project",
5+
"license": "Apache-2.0",
6+
"authors": [
7+
{
8+
"name": "Tom Carrio",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"open-feature/sdk": "^1.2.0",
14+
"datadog/dd-trace": "^0.82.0"
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use OpenFeature\OpenFeatureAPI;
6+
7+
echo 'autoloading SDK example starting...' . PHP_EOL;
8+
9+
// Composer autoloader will execute SDK/_autoload.php which will register global instrumentation from environment configuration
10+
require dirname(__DIR__) . '/vendor/autoload.php';
11+
12+
$client = OpenFeatureAPI::getInstance()->getClient('dev.openfeature.contrib.php.demo', '1.0.0');
13+
14+
$version = $client->getStringValue('dev.openfeature.contrib.php.version-value', 'unknown');
15+
16+
echo 'Version is ' . $version;

hooks/DDTrace/phpcs.xml.dist

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
3+
4+
<arg name="extensions" value="php"/>
5+
<arg name="colors"/>
6+
<arg value="sp"/>
7+
8+
<file>./src</file>
9+
<file>./tests</file>
10+
11+
<exclude-pattern>*/tests/fixtures/*</exclude-pattern>
12+
<exclude-pattern>*/tests/*/fixtures/*</exclude-pattern>
13+
14+
<rule ref="Ramsey">
15+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
16+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousErrorNaming"/>
17+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
18+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
19+
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/>
20+
21+
<exclude name="Generic.Files.LineLength.TooLong"/>
22+
<exclude name="Generic.Commenting.Todo.TaskFound"/>
23+
24+
<!-- Ignore this for PHP 7.4 -->
25+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
26+
</rule>
27+
28+
</ruleset>

0 commit comments

Comments
 (0)