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
18 changes: 18 additions & 0 deletions hooks/DDTrace/.github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
push:
branches:
- main

name: Run Release Please
jobs:
release-please:
runs-on: ubuntu-latest

# Release-please creates a PR that tracks all changes
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
command: manifest
token: ${{secrets.GITHUB_TOKEN}}
default-branch: main
3 changes: 3 additions & 0 deletions hooks/DDTrace/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/composer.lock
/vendor
/build
3 changes: 3 additions & 0 deletions hooks/DDTrace/.release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.0.1"
}
62 changes: 62 additions & 0 deletions hooks/DDTrace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# OpenFeature DDTrace 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/dd-trace-hook/v)](https://packagist.org/packages/open-feature/dd-trace-hook)
[![Total Downloads](http://poser.pugx.org/open-feature/dd-trace-hook/downloads)](https://packagist.org/packages/open-feature/dd-trace-hook)
![PHP 7.4+](https://img.shields.io/badge/php->=7.4-blue.svg)
[![License](http://poser.pugx.org/open-feature/dd-trace-hook/license)](https://packagist.org/packages/open-feature/dd-trace-hook)

## Overview

`dd-trace` is the Datadog tracing library for PHP. It is built on the OpenTracing specification.

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

### Design

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

### Autoloading

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.

## Installation

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

## Usage

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

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

```php
use OpenFeature\Hooks\DDTrace\DDTraceHook;

DDTraceHook::register();
```

For more information on DDTrace, check out [their documentation](https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/php?tab=containers).

For more examples, see the [examples](./examples/).

## 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`.
139 changes: 139 additions & 0 deletions hooks/DDTrace/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"name": "open-feature/dd-trace-hook",
"description": "The Datadog dd-trace hook package for OpenFeature",
"license": "Apache-2.0",
"type": "library",
"keywords": [
"featureflags",
"featureflagging",
"openfeature",
"dd-trace",
"ddtrace",
"datadog",
"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.2.0"
},
"require-dev": {
"datadog/dd-trace": "^0.82.0",
"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\\DDTrace\\": "src"
},
"files": [
"src/_autoload.php"
]
},
"autoload-dev": {
"psr-4": {
"OpenFeature\\Hooks\\DDTrace\\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",
"phpunit --colors=always --testdox --testsuite=integration",
"@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."
}
}
2 changes: 2 additions & 0 deletions hooks/DDTrace/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*/vendor
/*/composer.lock
5 changes: 5 additions & 0 deletions hooks/DDTrace/examples/AutoloadDDTrace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OpenFeature DDTrace Hook example

This example provides an example of bootstrapping and using the DDTrace hook for OpenFeature.

It showcases the auto-instrumentation functionality of OpenFeature and DDTrace, neither of which requiring imperative interactions with DDTrace to bootstrap, configure, and utilize it.
16 changes: 16 additions & 0 deletions hooks/DDTrace/examples/AutoloadDDTrace/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "open-feature/dd-trace-manual-instrumentation-example",
"description": "An example of using the DDTrace hook for OpenFeature with manual instrumentation",
"type": "project",
"license": "Apache-2.0",
"authors": [
{
"name": "Tom Carrio",
"email": "[email protected]"
}
],
"require": {
"open-feature/sdk": "^1.2.0",
"datadog/dd-trace": "^0.82.0"
}
}
16 changes: 16 additions & 0 deletions hooks/DDTrace/examples/AutoloadDDTrace/src/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use OpenFeature\OpenFeatureAPI;

echo 'autoloading SDK example starting...' . PHP_EOL;

// Composer autoloader will execute SDK/_autoload.php which will register global instrumentation from environment configuration
require dirname(__DIR__) . '/vendor/autoload.php';

$client = OpenFeatureAPI::getInstance()->getClient('dev.openfeature.contrib.php.demo', '1.0.0');

$version = $client->getStringValue('dev.openfeature.contrib.php.version-value', 'unknown');

echo 'Version is ' . $version;
28 changes: 28 additions & 0 deletions hooks/DDTrace/phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="extensions" value="php"/>
<arg name="colors"/>
<arg value="sp"/>

<file>./src</file>
<file>./tests</file>

<exclude-pattern>*/tests/fixtures/*</exclude-pattern>
<exclude-pattern>*/tests/*/fixtures/*</exclude-pattern>

<rule ref="Ramsey">
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousErrorNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming"/>

<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="Generic.Commenting.Todo.TaskFound"/>

<!-- Ignore this for PHP 7.4 -->
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
</rule>

</ruleset>
9 changes: 9 additions & 0 deletions hooks/DDTrace/phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
tmpDir: ./build/cache/phpstan
level: max
paths:
- ./src
- ./tests
excludePaths:
- */tests/fixtures/*
- */tests/*/fixtures/*
28 changes: 28 additions & 0 deletions hooks/DDTrace/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
cacheResultFile="./build/cache/phpunit.result.cache"
colors="true"
verbose="true">

<testsuites>
<testsuite name="unit">
<directory>./tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/integration</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>

<php>
<ini name="date.timezone" value="UTC"/>
</php>

</phpunit>
2 changes: 2 additions & 0 deletions hooks/DDTrace/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.9.5@0cfe565d0afbcd31eadcc281b9017b5692911661"/>
17 changes: 17 additions & 0 deletions hooks/DDTrace/psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<psalm xmlns="https://getpsalm.org/schema/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorLevel="1"
cacheDirectory="./build/cache/psalm"
errorBaseline="./psalm-baseline.xml">

<projectFiles>
<directory name="./src"/>
<ignoreFiles>
<directory name="./tests"/>
<directory name="./vendor"/>
</ignoreFiles>
</projectFiles>

</psalm>
12 changes: 12 additions & 0 deletions hooks/DDTrace/release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bootstrap-sha": "0a4beadbad2b40f14063f2ba9bcda258595119e9",
"packages": {
".": {
"release-type": "php",
"prerelease": false,
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"include-v-in-tag": false
}
}
}
Loading