-
Couldn't load subscription status.
- Fork 117
[aws-sdk]Added Initial auto-instrumentation library for aws-sdk #361
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
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
673f2f9
[aws-sdk]Added Initial auto-instrumentation library for aws-sdk
AsakerMohd 28a512e
Updated to use sem covs instead of hardcoding
AsakerMohd 057e7d1
Merge branch 'open-telemetry:main' into main
AsakerMohd 45224ce
added to gitsplit
AsakerMohd be7848e
added gitattributes file
AsakerMohd 1cdadb9
Merge branch 'open-telemetry:main' into main
AsakerMohd 5f3a9ed
Updated to use the latest semcov 1.32
AsakerMohd 660c52f
Merge branch 'open-telemetry:main' into main
AsakerMohd 500afb6
Added aws tests to php.yml
AsakerMohd ad6926c
Merge branch 'main' of https://github.com/AsakerMohd/opentelemetry-ph…
AsakerMohd ce36434
Merge branch 'open-telemetry:main' into main
AsakerMohd 9a94008
Updated composer for php 8.1 and fixed style issue
AsakerMohd 4fbd13e
Fixed psalm errors
AsakerMohd 1a01849
Merge branch 'open-telemetry:main' into main
AsakerMohd c24bd82
fixed styling again
AsakerMohd bfc0335
supress phan errors
AsakerMohd 3f94160
updated unit test to not require credentials
AsakerMohd 75e5033
updated comment messages
AsakerMohd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,12 @@ | ||
| * text=auto | ||
|
|
||
| *.md diff=markdown | ||
| *.php diff=php | ||
|
|
||
| /.gitattributes export-ignore | ||
| /.gitignore export-ignore | ||
| /.php-cs-fixer.php export-ignore | ||
| /phpstan.neon.dist export-ignore | ||
| /phpunit.xml.dist export-ignore | ||
| /psalm.xml.dist export-ignore | ||
| /tests export-ignore |
This file contains hidden or 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,2 @@ | ||
| /vendor/ | ||
| composer.lock |
This file contains hidden or 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,45 @@ | ||
| <?php | ||
| $finder = PhpCsFixer\Finder::create() | ||
| ->exclude('vendor') | ||
| ->exclude('tests/Unit81') //contains php8.1 syntax | ||
| ->exclude('var/cache') | ||
| ->exclude('tests/coverage') | ||
| ->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, | ||
| 'type_declaration_spaces' => true, | ||
| 'include' => true, | ||
| 'lowercase_cast' => true, | ||
| 'new_with_parentheses' => 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, | ||
| 'blank_lines_before_namespace' => true, | ||
| 'single_quote' => true, | ||
| 'trailing_comma_in_multiline' => true, | ||
| ]) | ||
| ->setRiskyAllowed(true) | ||
| ->setFinder($finder); | ||
|
|
This file contains hidden or 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 @@ | ||
| [](https://github.com/opentelemetry-php/contrib-auto-aws-sdk/releases) | ||
| [](https://github.com/open-telemetry/opentelemetry-php/issues) | ||
| [](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Instrumentation/AwsSdk) | ||
| [](https://github.com/opentelemetry-php/contrib-auto-aws-sdk) | ||
| [](https://packagist.org/packages/open-telemetry/opentelemetry-auto-aws-sdk/) | ||
| [](https://packagist.org/packages/open-telemetry/opentelemetry-auto-aws-sdk/) | ||
|
|
||
| This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib. | ||
|
|
||
| # OpenTelemetry AWS SDK auto-instrumentation | ||
| Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to | ||
| install and configure the extension and SDK. | ||
|
|
||
| ## Overview | ||
| Auto-instrumentation hooks are registered via composer. | ||
|
|
||
| * create spans automatically for each AWS SDK request that is sent | ||
|
|
||
| ## Configuration | ||
|
|
||
| The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration): | ||
|
|
||
| ```shell | ||
| OTEL_PHP_DISABLED_INSTRUMENTATIONS=aws-sdk | ||
| ``` |
This file contains hidden or 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,20 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| use OpenTelemetry\Contrib\Instrumentation\AwsSdk\AwsSdkInstrumentation; | ||
| use OpenTelemetry\SDK\Sdk; | ||
|
|
||
| if (class_exists(Sdk::class) | ||
| && Sdk::isInstrumentationDisabled(AwsSdkInstrumentation::NAME)) { | ||
| return; | ||
| } | ||
|
|
||
| if (!extension_loaded('opentelemetry')) { | ||
| trigger_error( | ||
| 'The opentelemetry extension must be loaded to use the AWS SDK auto‑instrumentation', | ||
| E_USER_WARNING | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| AwsSdkInstrumentation::register(); |
This file contains hidden or 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 @@ | ||
| { | ||
| "name": "open-telemetry/opentelemetry-auto-aws-sdk", | ||
| "description": "OpenTelemetry auto‑instrumentation for the AWS SDK", | ||
| "keywords": ["opentelemetry", "otel", "open-telemetry", "tracing", "aws-sdk", "instrumentation"], | ||
| "type": "library", | ||
| "homepage": "https://opentelemetry.io/docs/php", | ||
| "readme": "./README.md", | ||
| "license": "Apache-2.0", | ||
| "minimum-stability": "dev", | ||
| "prefer-stable": true, | ||
| "require": { | ||
| "php": "^8.2", | ||
| "aws/aws-sdk-php": "^3", | ||
| "ext-opentelemetry": "*", | ||
| "open-telemetry/api": "^1.0", | ||
| "open-telemetry/sem-conv": "^1.30" | ||
| }, | ||
| "require-dev": { | ||
| "friendsofphp/php-cs-fixer": "^3", | ||
| "guzzlehttp/promises": "^2", | ||
| "nyholm/psr7": "*", | ||
| "phan/phan": "^5.0", | ||
| "phpstan/phpstan-mockery": "^1.1.0", | ||
| "phpstan/phpstan": "^1.1", | ||
| "phpstan/phpstan-phpunit": "^1.0", | ||
| "psalm/plugin-phpunit": "^0.19.2", | ||
| "open-telemetry/sdk": "^1.0", | ||
| "phpunit/phpunit": "^9.5", | ||
| "vimeo/psalm": "6.4.0" | ||
| }, | ||
| "autoload": { | ||
| "psr-4": { | ||
| "OpenTelemetry\\Contrib\\Instrumentation\\AwsSdk\\": "src/" | ||
| }, | ||
| "files": ["_register.php"] | ||
| }, | ||
| "autoload-dev": { | ||
| "psr-4": { | ||
| "OpenTelemetry\\Tests\\Instrumentation\\AwsSdk\\": "tests/" | ||
| } | ||
| }, | ||
| "config": { | ||
| "allow-plugins": { | ||
| "php-http/discovery": false, | ||
| "tbachert/spi": true | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,12 @@ | ||
| includes: | ||
| - vendor/phpstan/phpstan-phpunit/extension.neon | ||
|
|
||
| parameters: | ||
| tmpDir: var/cache/phpstan | ||
| level: 5 | ||
| paths: | ||
| - src | ||
| - tests | ||
| excludePaths: | ||
| analyseAndScan: | ||
| - tests/Unit |
This file contains hidden or 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 hidden or 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 hidden or 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,90 @@ | ||
| <?php | ||
|
|
||
| // src/Instrumentation/AwsSdk/AwsSdkInstrumentation.php | ||
AsakerMohd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\Contrib\Instrumentation\AwsSdk; | ||
|
|
||
| use Aws\AwsClient; | ||
| use Aws\Exception\AwsException; | ||
| use Aws\ResultInterface; | ||
| use OpenTelemetry\API\Instrumentation\CachedInstrumentation; | ||
| use OpenTelemetry\API\Trace\Span; | ||
| use OpenTelemetry\API\Trace\SpanKind; | ||
| use OpenTelemetry\API\Trace\StatusCode; | ||
| use OpenTelemetry\Context\Context; | ||
| use function OpenTelemetry\Instrumentation\hook; | ||
| use OpenTelemetry\SemConv\TraceAttributes; | ||
|
|
||
| final class AwsSdkInstrumentation | ||
| { | ||
| public const NAME = 'aws-sdk'; | ||
|
|
||
| public static function register(): void | ||
| { | ||
| $inst = new CachedInstrumentation( | ||
| 'io.opentelemetry.contrib.php.aws-sdk', | ||
| null, | ||
| 'https://opentelemetry.io/schemas/1.30.0', | ||
| ); | ||
|
|
||
| /** | ||
| * ② Intercept the low‑level `execute` call that actually | ||
| * performs the HTTP request and has the Command object. | ||
AsakerMohd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| hook( | ||
| AwsClient::class, | ||
| 'execute', | ||
| pre: static function ( | ||
| AwsClient $c, | ||
| array $params, | ||
| string $class, | ||
| string $function, | ||
| ?string $filename, | ||
| ?int $lineno | ||
| ) use ($inst) { | ||
| $cmd = $params[0]; | ||
| $builder = $inst->tracer() | ||
| ->spanBuilder("{$c->getApi()->getServiceName()}.{$cmd->getName()}") | ||
| ->setSpanKind(SpanKind::KIND_CLIENT) | ||
brettmc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ->setAttribute(TraceAttributes::RPC_SYSTEM, 'aws-api') | ||
| ->setAttribute(TraceAttributes::RPC_METHOD, $cmd->getName()) | ||
| ->setAttribute(TraceAttributes::RPC_SERVICE, $c->getApi()->getServiceName()) | ||
| ->setAttribute(TraceAttributes::CLOUD_REGION, $c->getRegion()) | ||
| ->setAttribute(TraceAttributes::CODE_FUNCTION_NAME, $function) | ||
AsakerMohd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) | ||
| ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) | ||
| ->setAttribute(TraceAttributes::CODE_LINE_NUMBER, $lineno); | ||
|
|
||
| $span = $builder->startSpan(); | ||
| Context::storage()->attach($span->storeInContext(Context::getCurrent())); | ||
| }, | ||
| post: static function ( | ||
| AwsClient $c, | ||
| array $params, | ||
| mixed $result, | ||
| ?\Throwable $ex | ||
| ) { | ||
| $scope = Context::storage()->scope(); | ||
| if (!$scope) { | ||
| return; | ||
| } | ||
| $span = Span::fromContext($scope->context()); | ||
| $scope->detach(); | ||
|
|
||
| if ($result instanceof ResultInterface && isset($result['@metadata'])) { | ||
| $span->setAttribute(TraceAttributes::HTTP_RESPONSE_STATUS_CODE, $result['@metadata']['statusCode']); | ||
| $span->setAttribute(TraceAttributes::AWS_REQUEST_ID, $result['@metadata']['headers']['x-amz-request-id']); | ||
| } | ||
| if ($ex) { | ||
| if ($ex instanceof AwsException && $ex->getAwsRequestId() !== null) { | ||
| $span->setAttribute(TraceAttributes::AWS_REQUEST_ID, $ex->getAwsRequestId()); | ||
| } | ||
| $span->recordException($ex); | ||
| $span->setStatus(StatusCode::STATUS_ERROR, $ex->getMessage()); | ||
| } | ||
| $span->end(); | ||
| } | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created this empty repo in preparation.