Skip to content

Commit fe1f358

Browse files
authored
[aws-sdk]Added Initial auto-instrumentation library for aws-sdk (#361)
* [aws-sdk]Added Initial auto-instrumentation library for aws-sdk * Updated to use sem covs instead of hardcoding * added to gitsplit * added gitattributes file * Updated to use the latest semcov 1.32 * Added aws tests to php.yml * Updated composer for php 8.1 and fixed style issue * Fixed psalm errors * fixed styling again * supress phan errors * updated unit test to not require credentials * updated comment messages
1 parent c15360b commit fe1f358

File tree

15 files changed

+779
-0
lines changed

15 files changed

+779
-0
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
project: [
2323
'Aws',
2424
'Context/Swoole',
25+
'Instrumentation/AwsSdk',
2526
'Instrumentation/CakePHP',
2627
'Instrumentation/CodeIgniter',
2728
'Instrumentation/Curl',

.gitsplit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ splits:
6262
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-yii.git"
6363
- prefix: "src/Instrumentation/Doctrine"
6464
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-doctrine.git"
65+
- prefix: "src/Instrumentation/AwsSdk"
66+
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-aws-sdk.git"
6567
- prefix: "src/Context/Swoole"
6668
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/context-swoole.git"
6769
- prefix: "src/AutoInstrumentationInstaller"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* text=auto
2+
3+
*.md diff=markdown
4+
*.php diff=php
5+
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.php-cs-fixer.php export-ignore
9+
/phpstan.neon.dist export-ignore
10+
/phpunit.xml.dist export-ignore
11+
/psalm.xml.dist export-ignore
12+
/tests export-ignore
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor/
2+
composer.lock

src/Instrumentation/AwsSdk/.phan/config.php

Lines changed: 371 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
$finder = PhpCsFixer\Finder::create()
3+
->exclude('vendor')
4+
->exclude('tests/Unit81') //contains php8.1 syntax
5+
->exclude('var/cache')
6+
->exclude('tests/coverage')
7+
->in(__DIR__);
8+
9+
$config = new PhpCsFixer\Config();
10+
return $config->setRules([
11+
'concat_space' => ['spacing' => 'one'],
12+
'declare_equal_normalize' => ['space' => 'none'],
13+
'is_null' => true,
14+
'modernize_types_casting' => true,
15+
'ordered_imports' => true,
16+
'php_unit_construct' => true,
17+
'single_line_comment_style' => true,
18+
'yoda_style' => false,
19+
'@PSR2' => true,
20+
'array_syntax' => ['syntax' => 'short'],
21+
'blank_line_after_opening_tag' => true,
22+
'blank_line_before_statement' => true,
23+
'cast_spaces' => true,
24+
'declare_strict_types' => true,
25+
'type_declaration_spaces' => true,
26+
'include' => true,
27+
'lowercase_cast' => true,
28+
'new_with_parentheses' => true,
29+
'no_extra_blank_lines' => true,
30+
'no_leading_import_slash' => true,
31+
'echo_tag_syntax' => true,
32+
'no_unused_imports' => true,
33+
'no_useless_else' => true,
34+
'no_useless_return' => true,
35+
'phpdoc_order' => true,
36+
'phpdoc_scalar' => true,
37+
'phpdoc_types' => true,
38+
'short_scalar_cast' => true,
39+
'blank_lines_before_namespace' => true,
40+
'single_quote' => true,
41+
'trailing_comma_in_multiline' => true,
42+
])
43+
->setRiskyAllowed(true)
44+
->setFinder($finder);
45+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[![Releases](https://img.shields.io/badge/releases-purple)](https://github.com/opentelemetry-php/contrib-auto-aws-sdk/releases)
2+
[![Issues](https://img.shields.io/badge/issues-pink)](https://github.com/open-telemetry/opentelemetry-php/issues)
3+
[![Source](https://img.shields.io/badge/source-contrib-green)](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Instrumentation/AwsSdk)
4+
[![Mirror](https://img.shields.io/badge/mirror-opentelemetry--php--contrib-blue)](https://github.com/opentelemetry-php/contrib-auto-aws-sdk)
5+
[![Latest Version](http://poser.pugx.org/open-telemetry/opentelemetry-auto-aws-sdk/v/unstable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-aws-sdk/)
6+
[![Stable](http://poser.pugx.org/open-telemetry/opentelemetry-auto-aws-sdk/v/stable)](https://packagist.org/packages/open-telemetry/opentelemetry-auto-aws-sdk/)
7+
8+
This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.
9+
10+
# OpenTelemetry AWS SDK auto-instrumentation
11+
Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to
12+
install and configure the extension and SDK.
13+
14+
## Overview
15+
Auto-instrumentation hooks are registered via composer.
16+
17+
* create spans automatically for each AWS SDK request that is sent
18+
19+
## Configuration
20+
21+
The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration):
22+
23+
```shell
24+
OTEL_PHP_DISABLED_INSTRUMENTATIONS=aws-sdk
25+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use OpenTelemetry\Contrib\Instrumentation\AwsSdk\AwsSdkInstrumentation;
6+
use OpenTelemetry\SDK\Sdk;
7+
8+
if (class_exists(Sdk::class)
9+
&& Sdk::isInstrumentationDisabled(AwsSdkInstrumentation::NAME)) {
10+
return;
11+
}
12+
13+
if (!extension_loaded('opentelemetry')) {
14+
trigger_error(
15+
'The opentelemetry extension must be loaded to use the AWS SDK auto‑instrumentation',
16+
E_USER_WARNING
17+
);
18+
19+
return;
20+
}
21+
22+
AwsSdkInstrumentation::register();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "open-telemetry/opentelemetry-auto-aws-sdk",
3+
"description": "OpenTelemetry auto‑instrumentation for the AWS SDK",
4+
"keywords": ["opentelemetry", "otel", "open-telemetry", "tracing", "aws-sdk", "instrumentation"],
5+
"type": "library",
6+
"homepage": "https://opentelemetry.io/docs/php",
7+
"readme": "./README.md",
8+
"license": "Apache-2.0",
9+
"minimum-stability": "dev",
10+
"prefer-stable": true,
11+
"require": {
12+
"php": "^8.1",
13+
"aws/aws-sdk-php": "^3",
14+
"ext-opentelemetry": "*",
15+
"open-telemetry/api": "^1.0",
16+
"open-telemetry/sem-conv": "^1.32"
17+
},
18+
"require-dev": {
19+
"friendsofphp/php-cs-fixer": "^3",
20+
"guzzlehttp/promises": "^2",
21+
"nyholm/psr7": "*",
22+
"phan/phan": "^5.0",
23+
"phpstan/phpstan-mockery": "^1.1.0",
24+
"phpstan/phpstan": "^1.1",
25+
"phpstan/phpstan-phpunit": "^1.0",
26+
"psalm/plugin-phpunit": "^0.19.2",
27+
"open-telemetry/sdk": "^1.0",
28+
"phpunit/phpunit": "^9.5",
29+
"vimeo/psalm": "6.4.0"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"OpenTelemetry\\Contrib\\Instrumentation\\AwsSdk\\": "src/"
34+
},
35+
"files": ["_register.php"]
36+
},
37+
"autoload-dev": {
38+
"psr-4": {
39+
"OpenTelemetry\\Tests\\Instrumentation\\AwsSdk\\": "tests/"
40+
}
41+
},
42+
"config": {
43+
"allow-plugins": {
44+
"php-http/discovery": false,
45+
"tbachert/spi": true
46+
}
47+
}
48+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
includes:
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
4+
parameters:
5+
tmpDir: var/cache/phpstan
6+
level: 5
7+
paths:
8+
- src
9+
- tests
10+
excludePaths:
11+
analyseAndScan:
12+
- tests/Unit

0 commit comments

Comments
 (0)