Skip to content

[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 18 commits into from
Jun 10, 2025

Conversation

AsakerMohd
Copy link
Contributor

Description:
There currently only exists a manual instrumentation library for the AWS SDK. It would be very helpful to also have an auto instrumentation library where customers only need to add one line in composer.json like "open-telemetry/opentelemetry-auto-aws-sdk": "*", to instrument their AWS SDK calls.

  1. This is an initial version of the auto instrumentation agent where it sets attributes such as rpc.system, rpc.method, rpc.service, aws.region and aws.requestId.. In the future, it should also support aws specific attributes for specific services such as bedrock, sns, sqs, etc. that have attributes such as gen_ai.agent.id, gen_ai.system, etc

  2. Another thing that needs to be supported is propagation which I'm having difficulty figuring out where to add. I see it's being added to libraries such as Slim here:

    // Propagate traceresponse header to response, if TraceResponsePropagator is present
    We have this X-Ray propagator which is important since it has functions to inject the traceid header for outgoing request and extract parent context from incoming requests. Any tips here would be appreciated.

  3. Enabling http instrumentation like slim produces duplicate spans. Lets say we make a call to S3. In this case, we have an aws-sdk span with rpc.service = S3 and an outgoing http span with "url.full": "https://s3.amazonaws.com/". Is there a way to suppress the http instrumentation for this specific scenario? I know this is doable in other languages such as Java/DotNet.

For testing:
I have this sample app: https://github.com/AsakerMohd/phpSample
I added the instrumentation path to that repo in the composer.json file:

"repositories": [
    {
      "type": "path",
      "url": "./AwsSdk",
      "options": {
        "symlink": true
      }
    }
  ],
  "require": {
     ...,
     "open-telemetry/opentelemetry-auto-aws-sdk": "*",
     ...,
  }

Then running the app through docker and making an API call, this is an example trace where only the aws-sdk instrumentation is enabled (notice the parent_id is empty. This is because this is the only instrumentation enabled. When something like slim is also enabled, the id is populated correctly):

[
my_php_app      |     {
my_php_app      |         "name": "s3.ListBuckets",
my_php_app      |         "context": {
my_php_app      |             "trace_id": "381643ab3693053e6ba9f3ee19d3b2b7",
my_php_app      |             "span_id": "a8806c84389623ff",
my_php_app      |             "trace_state": "",
my_php_app      |             "trace_flags": 1
my_php_app      |         },
my_php_app      |         "resource": {
my_php_app      |             "host.name": "160a5c84428f",
my_php_app      |             "host.arch": "aarch64",
my_php_app      |             "os.type": "linux",
my_php_app      |             "os.description": "6.10.14-linuxkit",
my_php_app      |             "os.name": "Linux",
my_php_app      |             "os.version": "#1 SMP Thu Mar 20 16:32:56 UTC 2025",
my_php_app      |             "process.pid": 7,
my_php_app      |             "process.executable.path": "\/usr\/local\/bin\/php",
my_php_app      |             "process.owner": "root",
my_php_app      |             "process.runtime.name": "cli-server",
my_php_app      |             "process.runtime.version": "8.2.28",
my_php_app      |             "telemetry.sdk.name": "opentelemetry",
my_php_app      |             "telemetry.sdk.language": "php",
my_php_app      |             "telemetry.sdk.version": "dev-main",
my_php_app      |             "telemetry.distro.name": "opentelemetry-php-instrumentation",
my_php_app      |             "telemetry.distro.version": "1.1.2",
my_php_app      |             "service.name": "php-sample-ec2",
my_php_app      |             "service.version": "dev-main"
my_php_app      |         },
my_php_app      |         "parent_span_id": "",
my_php_app      |         "kind": "KIND_CLIENT",
my_php_app      |         "start": 1745386257527632330,
my_php_app      |         "end": 1745386257846341288,
my_php_app      |         "attributes": {
my_php_app      |             "rpc.system": "aws-api",
my_php_app      |             "rpc.method": "ListBuckets",
my_php_app      |             "rpc.service": "s3",
my_php_app      |             "aws.region": "us-east-1",
my_php_app      |             "code.function": "execute",
my_php_app      |             "code.namespace": "Aws\\AwsClient",
my_php_app      |             "code.filepath": "\/app\/vendor\/aws\/aws-sdk-php\/src\/AwsClientTrait.php",
my_php_app      |             "code.line_number": 56,
my_php_app      |             "http.status_code": 200,
my_php_app      |             "aws.requestId": "60PQSDPPNH5CSPMD"
my_php_app      |         },
my_php_app      |         "status": {
my_php_app      |             "code": "Unset",
my_php_app      |             "description": ""
my_php_app      |         },
my_php_app      |         "events": [],
my_php_app      |         "links": [],
my_php_app      |         "schema_url": "https:\/\/opentelemetry.io\/schemas\/1.30.0"
my_php_app      |     }
my_php_app      | ]

For the integration test: Running vendor/bin/phpunit tests/Integration/AwsSdkInstrumentationTest.php runs the test there that asserts for the attributes and span and it passes as expected.

@AsakerMohd AsakerMohd requested a review from a team as a code owner April 24, 2025 19:40
Copy link

welcome bot commented Apr 24, 2025

Thanks for opening your first pull request! If you haven't yet signed our Contributor License Agreement (CLA), then please do so that we can accept your contribution. A link should appear shortly in this PR if you have not already signed one.

Copy link

codecov bot commented Apr 30, 2025

Codecov Report

Attention: Patch coverage is 81.13208% with 10 lines in your changes missing coverage. Please review.

Project coverage is 82.13%. Comparing base (39f190a) to head (75e5033).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...strumentation/AwsSdk/src/AwsSdkInstrumentation.php 81.13% 10 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #361      +/-   ##
============================================
- Coverage     82.14%   82.13%   -0.01%     
- Complexity     1801     1808       +7     
============================================
  Files           137      138       +1     
  Lines          7594     7647      +53     
============================================
+ Hits           6238     6281      +43     
- Misses         1356     1366      +10     
Flag Coverage Δ
Aws 92.59% <ø> (ø)
Context/Swoole 0.00% <ø> (ø)
Instrumentation/AwsSdk 81.13% <81.13%> (?)
Instrumentation/CakePHP 20.40% <ø> (ø)
Instrumentation/CodeIgniter 73.55% <ø> (ø)
Instrumentation/Doctrine 92.72% <ø> (ø)
Instrumentation/ExtAmqp 88.48% <ø> (ø)
Instrumentation/ExtRdKafka 86.11% <ø> (ø)
Instrumentation/Guzzle 69.13% <ø> (ø)
Instrumentation/HttpAsyncClient 78.04% <ø> (ø)
Instrumentation/IO 70.68% <ø> (ø)
Instrumentation/Laravel 63.91% <ø> (ø)
Instrumentation/MongoDB 74.28% <ø> (ø)
Instrumentation/MySqli 95.81% <ø> (ø)
Instrumentation/OpenAIPHP 87.21% <ø> (ø)
Instrumentation/PDO 94.21% <ø> (ø)
Instrumentation/Psr14 76.47% <ø> (ø)
Instrumentation/Psr15 89.15% <ø> (ø)
Instrumentation/Psr16 97.50% <ø> (ø)
Instrumentation/Psr18 77.46% <ø> (ø)
Instrumentation/Psr3 67.01% <ø> (ø)
Instrumentation/Psr6 97.61% <ø> (ø)
Instrumentation/ReactPHP 99.28% <ø> (ø)
Instrumentation/Slim 86.11% <ø> (ø)
Instrumentation/Symfony 84.74% <ø> (ø)
Instrumentation/Yii 77.50% <ø> (ø)
Logs/Monolog 100.00% <ø> (ø)
Propagation/Instana 98.11% <ø> (ø)
Propagation/ServerTiming 100.00% <ø> (ø)
Propagation/TraceResponse 100.00% <ø> (ø)
ResourceDetectors/Azure 91.66% <ø> (ø)
ResourceDetectors/Container 93.02% <ø> (ø)
Sampler/RuleBased 33.51% <ø> (ø)
Shims/OpenTracing 92.45% <ø> (ø)
Symfony 87.81% <ø> (ø)
Utils/Test 87.53% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...strumentation/AwsSdk/src/AwsSdkInstrumentation.php 81.13% <81.13%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39f190a...75e5033. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@ChrisLightfootWild ChrisLightfootWild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you also copy one of the .gitattributes across from another contrib package and tweak appropriately, if required?

@AsakerMohd
Copy link
Contributor Author

Please can you also copy one of the .gitattributes across from another contrib package and tweak appropriately, if required?

Done!

@@ -60,6 +60,8 @@ splits:
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-yii.git"
- prefix: "src/Instrumentation/Doctrine"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-doctrine.git"
- prefix: "src/Instrumentation/AwsSdk"
target: "https://${GH_TOKEN}@github.com/opentelemetry-php/contrib-auto-aws-sdk.git"
Copy link
Contributor

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.

@brettmc
Copy link
Contributor

brettmc commented May 14, 2025

The tests aren't running for this one yet, @AsakerMohd can you add it to the top-level .github/workflows/php.yml please

@AsakerMohd
Copy link
Contributor Author

.github/workflows/php.yml

Added!

@brettmc
Copy link
Contributor

brettmc commented May 20, 2025

@AsakerMohd now that checks+tests are running, you can address those failures. It will be fastest if you get them all passing locally (make all locally, per our docs here: https://github.com/open-telemetry/opentelemetry-php/blob/main/CONTRIBUTING.md )

@AsakerMohd
Copy link
Contributor Author

@AsakerMohd now that checks+tests are running, you can address those failures. It will be fastest if you get them all passing locally (make all locally, per our docs here: https://github.com/open-telemetry/opentelemetry-php/blob/main/CONTRIBUTING.md )

Fixed the style issue and the build issue for php 8.1 workflow. The other failures are for instrumentation packages that aren't related to this change.

@brettmc brettmc merged commit fe1f358 into open-telemetry:main Jun 10, 2025
140 of 144 checks passed
@brettmc
Copy link
Contributor

brettmc commented Jun 10, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants