-
Notifications
You must be signed in to change notification settings - Fork 223
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
feat: add instrumentation for aws-sdk S3 client #3287
Conversation
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.
This is a great start.
Eventually, another thing to add to the v3 instrumentation is span.setHttpContext(...)
as is done in the v2 instrumentation for S3, which adds this to the span:
{
"span": {
// ...
"context": {
"http": {
"status_code": 200,
"response": {
"encoded_body_size": 11500
}
}
},
}
}
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.
Interesting, I got this error when running this with my current AWS config:
$ node ./test/instrumentation/modules/@aws-sdk/fixtures/use-s3-v3.js | ecslog
...
[2023-04-26T21:35:04.728Z] INFO (elastic-apm-node): createBucket
event.module: "app"
bucketName: "elasticapmtest-bucket-20230426213504"
data: null
error: {
"type": "S3ServiceException",
"message":
The async () => {
if (typeof region === "string") {
return (0, getRealRegion_1.getRealRegion)(region);
}
const providedRegion = await region();
return (0, getRealRegion_1.getRealRegion)(providedRegion);
} location constraint is incompatible for the region specific endpoint this request was sent to.,
"stack_trace":
IllegalLocationConstraintException: The async () => {
if (typeof region === "string") {
return (0, getRealRegion_1.getRealRegion)(region);
}
const providedRegion = await region();
return (0, getRealRegion_1.getRealRegion)(providedRegion);
} location constraint is incompatible for the region specific endpoint this request was sent to.
at throwDefaultError (/Users/trentm/el/apm-agent-nodejs11/node_modules/@aws-sdk/smithy-client/dist-cjs/default-error-handler.js:8:22)
at /Users/trentm/el/apm-agent-nodejs11/node_modules/@aws-sdk/smithy-client/dist-cjs/default-error-handler.js:18:39
at de_CreateBucketCommandError (/Users/trentm/el/apm-agent-nodejs11/node_modules/@aws-sdk/client-s3/dist-cjs/protocols/Aws_restXml.js:3162:20)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
}
I get this even when the APM agent isn't involved:
ELASTIC_APM_ACTIVE=false node ./test/instrumentation/modules/@aws-sdk/fixtures/use-s3-v3.js | ecslog
Do you know what might be causing this?
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.
Not yet. I'm going to run my own tests too and post results here
For the |
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.
This is great.
Another couple things:
- You should add a
@aws-sdk/client-s3
line to the supported modules table here: https://www.elastic.co/guide/en/apm/agent/nodejs/current/supported-technologies.html#compatibility-tracing-and-instrumentation (that is in "docs/supported-technologies.asciidoc"). - You should also add a note to the CHANGELOG.asciidoc.
This will avoid the failures in CI tests with node less than v14 (the min supported node version for diff --git a/test/instrumentation/modules/@aws-sdk/s3-v3.test.js b/test/instrumentation/modules/@aws-sdk/s3-v3.test.js
index ecfe0dc3..453502f2 100644
--- a/test/instrumentation/modules/@aws-sdk/s3-v3.test.js
+++ b/test/instrumentation/modules/@aws-sdk/s3-v3.test.js
@@ -6,10 +6,15 @@
'use strict'
+const semver = require('semver')
if (process.env.GITHUB_ACTIONS === 'true' && process.platform === 'win32') {
console.log('# SKIP: GH Actions do not support docker services on Windows')
process.exit(0)
}
+if (semver.lt(process.version, '14.0.0')) {
+ console.log(`# SKIP @aws-sdk min supported node is v14 (node ${process.version})`)
+ process.exit()
+}
// Test S3 instrumentation of the '@aws-sdk/client-s3' module.
// |
Co-authored-by: Trent Mick <trent.mick@elastic.co>
Co-authored-by: Trent Mick <trent.mick@elastic.co>
Co-authored-by: Trent Mick <trent.mick@elastic.co>
Co-authored-by: Trent Mick <trent.mick@elastic.co>
Co-authored-by: Trent Mick <trent.mick@elastic.co>
package-lock.json
Outdated
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.
This PR shouldn't have most (any?) of these package-lock diffs. I think some of these will be resolved by merging from recent "main" changes.
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.
The PR is adding @aws-sdk/client-s3
as a dev dependency and this is its entry in the lock file
"node_modules/@aws-sdk/client-s3": {
"version": "3.325.0",
"resolved": "https://registry.npmjs.org/@aws-sdk/client-s3/-/client-s3-3.325.0.tgz",
"integrity": "sha512-S88q84bJ1Wba3jnpIrWxMD4AbDsG7l45Ey4ZDdyriEceEgIWvBCA90ZOgSdaObhFNa5pNFZG9C6UbiaCz3F3bA==",
"dev": true,
"dependencies": {
"@aws-crypto/sha1-browser": "3.0.0",
"@aws-crypto/sha256-browser": "3.0.0",
"@aws-crypto/sha256-js": "3.0.0",
"@aws-sdk/client-sts": "3.325.0",
"@aws-sdk/config-resolver": "3.310.0",
"@aws-sdk/credential-provider-node": "3.325.0",
"@aws-sdk/eventstream-serde-browser": "3.310.0",
"@aws-sdk/eventstream-serde-config-resolver": "3.310.0",
"@aws-sdk/eventstream-serde-node": "3.310.0",
"@aws-sdk/fetch-http-handler": "3.310.0",
"@aws-sdk/hash-blob-browser": "3.310.0",
"@aws-sdk/hash-node": "3.310.0",
"@aws-sdk/hash-stream-node": "3.310.0",
"@aws-sdk/invalid-dependency": "3.310.0",
"@aws-sdk/md5-js": "3.310.0",
"@aws-sdk/middleware-bucket-endpoint": "3.310.0",
"@aws-sdk/middleware-content-length": "3.325.0",
"@aws-sdk/middleware-endpoint": "3.325.0",
"@aws-sdk/middleware-expect-continue": "3.325.0",
"@aws-sdk/middleware-flexible-checksums": "3.325.0",
"@aws-sdk/middleware-host-header": "3.325.0",
"@aws-sdk/middleware-location-constraint": "3.325.0",
"@aws-sdk/middleware-logger": "3.325.0",
"@aws-sdk/middleware-recursion-detection": "3.325.0",
"@aws-sdk/middleware-retry": "3.325.0",
"@aws-sdk/middleware-sdk-s3": "3.325.0",
"@aws-sdk/middleware-serde": "3.325.0",
"@aws-sdk/middleware-signing": "3.325.0",
"@aws-sdk/middleware-ssec": "3.325.0",
"@aws-sdk/middleware-stack": "3.325.0",
"@aws-sdk/middleware-user-agent": "3.325.0",
"@aws-sdk/node-config-provider": "3.310.0",
"@aws-sdk/node-http-handler": "3.321.1",
"@aws-sdk/protocol-http": "3.310.0",
"@aws-sdk/signature-v4-multi-region": "3.310.0",
"@aws-sdk/smithy-client": "3.325.0",
"@aws-sdk/types": "3.310.0",
"@aws-sdk/url-parser": "3.310.0",
"@aws-sdk/util-base64": "3.310.0",
"@aws-sdk/util-body-length-browser": "3.310.0",
"@aws-sdk/util-body-length-node": "3.310.0",
"@aws-sdk/util-defaults-mode-browser": "3.325.0",
"@aws-sdk/util-defaults-mode-node": "3.325.0",
"@aws-sdk/util-endpoints": "3.319.0",
"@aws-sdk/util-retry": "3.310.0",
"@aws-sdk/util-stream-browser": "3.310.0",
"@aws-sdk/util-stream-node": "3.321.1",
"@aws-sdk/util-user-agent-browser": "3.310.0",
"@aws-sdk/util-user-agent-node": "3.310.0",
"@aws-sdk/util-utf8": "3.310.0",
"@aws-sdk/util-waiter": "3.310.0",
"@aws-sdk/xml-builder": "3.310.0",
"fast-xml-parser": "4.1.2",
"tslib": "^2.5.0"
},
"engines": {
"node": ">=14.0.0"
}
},
There's a lot of dependencies and these packages also have their dependencies as well. I guess for SNS, SQS & DynamoDB it will be less impact on the lock file.
…tic/apm-agent-nodejs into luna/2955-instrumentation-aws-s3-v3
…re/support-specific-modules * 'main' of github.com:elastic/apm-agent-nodejs: (54 commits) chore: fix dev-utils/ci-tav-slow-jobs.sh (elastic#3319) test: reduce TAV test matrix for slowest jobs (elastic#3321) chore: sync package-lock so 'npm ci' can work (elastic#3318) docs: document `useElasticTraceparentHeader` config var (elastic#3316) chore, test: test driver improvements (elastic#3293) test: drop node 14 from RC tests now that it is EOL (elastic#3315) test: fix running fastify.test.js with node v8 (elastic#3317) feat: add @apollo/server@4 support (elastic#3203) chore: update nvm (elastic#3309) tests: stop testing 'express-graphql' instrumentation (elastic#3304) chore: fix bitrot.js dev util for recent changes (elastic#3308) test: restore testing of Azure Functions on node >=18.x (elastic#3307) fix: support Lambda instrumentation for `contextManager: 'patch'`; refactor Lambda tests (elastic#3305) test: fix fastify TAV test failures (elastic#3314) test: fix @aws-sdk/client-s3 TAV test failures (elastic#3312) feat: add instrumentation for aws-sdk S3 client (elastic#3287) feat(fastify): add captureBody support (elastic#2681) feat: mysql2@3 support (elastic#3301) chore(deps): bump @opentelemetry/exporter-prometheus from 0.37.0 to 0.38.0 in /test/opentelemetry-metrics/fixtures (elastic#3295) chore(deps-dev): bump fastify from 4.16.3 to 4.17.0 (elastic#3296) ...
* feat: add instrumentation for aws-sdk S3 client --------- Co-authored-by: Trent Mick <trent.mick@elastic.co>
Description
This change-set add instrumentation for
@aws-sdk/client-s3
which is available in v3. The approach is not to instrument theS3Client
directly but the baseClient
class so we can add specific middleware functions based on each client without having to instrument them.Fixes: #2955
Checklist