-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Yii2 framework instrumentation (#212)
* Yii2 instrumentation * Address PR comments. * Fix psalm issue
1 parent
8665109
commit f3e21f4
Showing
16 changed files
with
680 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
$finder = PhpCsFixer\Finder::create() | ||
->exclude('vendor') | ||
->exclude('var/cache') | ||
->in(__DIR__); | ||
|
||
$config = new PhpCsFixer\Config(); | ||
return $config->setRules([ | ||
'concat_space' => ['spacing' => 'one'], | ||
'declare_equal_normalize' => ['space' => 'none'], | ||
'is_null' => true, | ||
'modernize_types_casting' => true, | ||
'ordered_imports' => true, | ||
'php_unit_construct' => true, | ||
'single_line_comment_style' => true, | ||
'yoda_style' => false, | ||
'@PSR2' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'blank_line_after_opening_tag' => true, | ||
'blank_line_before_statement' => true, | ||
'cast_spaces' => true, | ||
'declare_strict_types' => true, | ||
'function_typehint_space' => true, | ||
'include' => true, | ||
'lowercase_cast' => true, | ||
'new_with_braces' => true, | ||
'no_extra_blank_lines' => true, | ||
'no_leading_import_slash' => true, | ||
'echo_tag_syntax' => true, | ||
'no_unused_imports' => true, | ||
'no_useless_else' => true, | ||
'no_useless_return' => true, | ||
'phpdoc_order' => true, | ||
'phpdoc_scalar' => true, | ||
'phpdoc_types' => true, | ||
'short_scalar_cast' => true, | ||
'single_blank_line_before_namespace' => true, | ||
'single_quote' => true, | ||
'trailing_comma_in_multiline' => true, | ||
]) | ||
->setRiskyAllowed(true) | ||
->setFinder($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-auto-yii/releases) | ||
[![Issues](https://img.shields.io/badge/issues-pink)](https://github.com/open-telemetry/opentelemetry-php/issues) | ||
[![Source](https://img.shields.io/badge/source-contrib-green)](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Instrumentation/Yii) | ||
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-auto-yii) | ||
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-auto-yii/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-yii/) | ||
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-auto-yii/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-yii/) | ||
|
||
This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib. | ||
|
||
# OpenTelemetry Yii auto-instrumentation | ||
|
||
Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to | ||
install and configure the extension and SDK. | ||
|
||
## Overview | ||
|
||
Requires Yii 2.0.13+ | ||
|
||
## Configuration | ||
|
||
The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration): | ||
|
||
```shell | ||
OTEL_PHP_DISABLED_INSTRUMENTATIONS=yii | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use OpenTelemetry\Contrib\Instrumentation\Yii\YiiInstrumentation; | ||
use OpenTelemetry\SDK\Sdk; | ||
|
||
if (class_exists(Sdk::class) && Sdk::isInstrumentationDisabled(YiiInstrumentation::NAME) === true) { | ||
return; | ||
} | ||
|
||
if (extension_loaded('opentelemetry') === false) { | ||
trigger_error('The opentelemetry extension must be loaded in order to autoload the OpenTelemetry Yii auto-instrumentation', E_USER_WARNING); | ||
|
||
return; | ||
} | ||
|
||
YiiInstrumentation::register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "open-telemetry/opentelemetry-auto-yii", | ||
"description": "OpenTelemetry auto-instrumentation for Yii", | ||
"keywords": ["opentelemetry", "otel", "open-telemetry", "tracing", "yii", "instrumentation"], | ||
"type": "library", | ||
"homepage": "https://opentelemetry.io/docs/php", | ||
"readme": "./README.md", | ||
"license": "Apache-2.0", | ||
"require": { | ||
"php": "^8.0", | ||
"ext-opentelemetry": "*", | ||
"yiisoft/yii2": "^2.0.13", | ||
"open-telemetry/api": "^1", | ||
"open-telemetry/sem-conv": "^1.22" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^3", | ||
"open-telemetry/sdk": "^1.0", | ||
"phan/phan": "^5.0", | ||
"php-http/mock-client": "*", | ||
"phpstan/phpstan": "^1.1", | ||
"phpstan/phpstan-phpunit": "^1.0", | ||
"psalm/plugin-phpunit": "^0.16", | ||
"phpunit/phpunit": "^9.5", | ||
"vimeo/psalm": "^4.0" | ||
}, | ||
"repositories": [ | ||
{ | ||
"type": "composer", | ||
"url": "https://asset-packagist.org" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"OpenTelemetry\\Contrib\\Instrumentation\\Yii\\": "src/" | ||
}, | ||
"files": [ | ||
"_register.php" | ||
] | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"OpenTelemetry\\Tests\\Instrumentation\\Yii\\": "tests/" | ||
} | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"php-http/discovery": false, | ||
"yiisoft/yii2-composer": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-phpunit/extension.neon | ||
|
||
parameters: | ||
tmpDir: var/cache/phpstan | ||
bootstrapFiles: | ||
- tests/bootstrap.php | ||
level: 5 | ||
paths: | ||
- src | ||
- tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="tests/bootstrap.php" | ||
cacheResult="false" | ||
colors="false" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
forceCoversAnnotation="false" | ||
processIsolation="false" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
stopOnRisky="false" | ||
timeoutForSmallTests="1" | ||
timeoutForMediumTests="10" | ||
timeoutForLargeTests="60" | ||
verbose="true"> | ||
|
||
<coverage processUncoveredFiles="true" disableCodeCoverageIgnore="false"> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
</coverage> | ||
|
||
<php> | ||
<ini name="date.timezone" value="UTC" /> | ||
<ini name="display_errors" value="On" /> | ||
<ini name="display_startup_errors" value="On" /> | ||
<ini name="error_reporting" value="E_ALL" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="unit"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
<testsuite name="integration"> | ||
<directory>tests/Integration</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0"?> | ||
<psalm | ||
errorLevel="3" | ||
cacheDirectory="var/cache/psalm" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://getpsalm.org/schema/config" | ||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"> | ||
<projectFiles> | ||
<directory name="src"/> | ||
<directory name="tests"/> | ||
<ignoreFiles> | ||
<directory name="vendor/yiisoft/yii2" /> | ||
</ignoreFiles> | ||
</projectFiles> | ||
<plugins> | ||
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/> | ||
</plugins> | ||
</psalm> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Contrib\Instrumentation\Yii; | ||
|
||
use function assert; | ||
use OpenTelemetry\Context\Propagation\PropagationGetterInterface; | ||
use yii\web\Request; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class RequestPropagationGetter implements PropagationGetterInterface | ||
{ | ||
public static function instance(): self | ||
{ | ||
static $instance; | ||
|
||
return $instance ??= new self(); | ||
} | ||
|
||
/** @psalm-suppress InvalidReturnType */ | ||
public function keys($carrier): array | ||
{ | ||
assert($carrier instanceof Request); | ||
|
||
return array_keys($carrier->getHeaders()->toArray()); | ||
} | ||
|
||
public function get($carrier, string $key) : ?string | ||
{ | ||
assert($carrier instanceof Request); | ||
|
||
$result = $carrier->getHeaders()->get($key, null, true); | ||
|
||
if (is_array($result)) { | ||
return (string) array_values($result)[0]; | ||
} | ||
|
||
return $result; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Contrib\Instrumentation\Yii; | ||
|
||
use function assert; | ||
use OpenTelemetry\Context\Propagation\PropagationSetterInterface; | ||
use yii\web\Response; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ResponsePropagationSetter implements PropagationSetterInterface | ||
{ | ||
public static function instance(): self | ||
{ | ||
static $instance; | ||
|
||
return $instance ??= new self(); | ||
} | ||
|
||
/** @psalm-suppress InvalidReturnType */ | ||
public function keys($carrier): array | ||
{ | ||
assert($carrier instanceof Response); | ||
|
||
return array_keys($carrier->getHeaders()->toArray()); | ||
} | ||
|
||
public function set(&$carrier, string $key, string $value): void | ||
{ | ||
assert($carrier instanceof Response); | ||
|
||
$carrier->getHeaders()->set($key, $value); | ||
} | ||
} |
Oops, something went wrong.