-
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.
finish off psr-18 auto-instrumentation (#88)
- add tests - replace enum with class for php8.0 compatibility - set up auto-registration via composer autoloader - mention sdk autoloading in readme - document some todos/questions
- Loading branch information
Showing
15 changed files
with
415 additions
and
109 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
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,43 @@ | ||
<?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,32 @@ | ||
# OpenTelemetry PSR-18 auto-instrumentation | ||
|
||
## Requirements | ||
|
||
* OpenTelemetry extension | ||
* OpenTelemetry SDK an exporter (required to actually export traces) | ||
* A psr-18 client | ||
* (optional) OpenTelemetry [SDK Autoloading](https://github.com/open-telemetry/opentelemetry-php/blob/main/examples/autoload_sdk.php) configured | ||
|
||
## Overview | ||
Auto-instrumentation hooks are registered via composer, which will: | ||
|
||
* create spans automatically for each PSR-18 request that is sent | ||
* add a `traceparent` header to the request to facilitate distributed tracing. | ||
|
||
## Manual configuration | ||
If you are not using SDK autoloading, you will need to create and register a `TracerProvider` early in your application's lifecycle: | ||
|
||
```php | ||
<?php | ||
require_once 'vendor/autoload.php'; | ||
|
||
$tracerProvider = /*create tracer provider*/; | ||
$scope = \OpenTelemetry\API\Common\Instrumentation\Configurator::create() | ||
->withTracerProvider($tracerProvider) | ||
->activate(); | ||
|
||
$client->sendRequest($request); | ||
|
||
$scope->detach(); | ||
$tracerProvider->shutdown(); | ||
``` |
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,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
\OpenTelemetry\Contrib\Instrumentation\Psr18\Psr18Instrumentation::register(); |
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
{ | ||
"name": "open-telemetry/opentelemetry-auto-psr18", | ||
"description": "OpenTelemetry auto-instrumentation for psr18 http clients.", | ||
"keywords": ["opentelemetry", "otel", "open-telemetry", "tracing", "psr18", "instrumentation"], | ||
"type": "library", | ||
"homepage": "https://opentelemetry.io/docs/php", | ||
"readme": "./README.md", | ||
"license": "Apache-2.0", | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": "^8.0", | ||
"ext-otel_instrumentation": "*", | ||
"open-telemetry/api": "^0", | ||
"psr/http-client": "^1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"OpenTelemetry\\Contrib\\Instrumentation\\Psr18\\": "src/" | ||
}, | ||
"files": [ | ||
"_register.php" | ||
] | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^3", | ||
"nyholm/psr7": "*", | ||
"phan/phan": "^5.0", | ||
"php-http/mock-client": "*", | ||
"phpstan/phpstan": "^1.1", | ||
"phpstan/phpstan-phpunit": "^1.0", | ||
"psalm/plugin-phpunit": "^0.16", | ||
"open-telemetry/sdk": "^0", | ||
"phpunit/phpunit": "^9.5", | ||
"vimeo/psalm": "^4.0" | ||
} | ||
} |
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,9 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-phpunit/extension.neon | ||
|
||
parameters: | ||
tmpDir: var/cache/phpstan | ||
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,47 @@ | ||
<?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" | ||
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,15 @@ | ||
<?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"/> | ||
</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
Oops, something went wrong.