-
Notifications
You must be signed in to change notification settings - Fork 156
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
Redesign AWS SDK V3 instrumentation to use middleware #416
Conversation
@trivikr @AllanZhengYP please review |
packages/core/lib/patchers/aws3_p.ts
Outdated
region: string, | ||
res: any, | ||
): Promise<[ServiceSegment, HttpResponse]> => { | ||
const { extendedRequestId, requestId, httpStatusCode: statusCode, attempts } = res.output?.$metadata || res.$metadata; |
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.
const { extendedRequestId, requestId, httpStatusCode: statusCode, attempts } = res.output?.$metadata || res.$metadata; | |
const { extendedRequestId, requestId, httpStatusCode: statusCode, attempts } = res.output?.$metadata; |
The $metadata is always stored in output, so res.$metadata
can be removed.
Example deserialize function of listTables command which populates $metadata https://github.com/aws/aws-sdk-js-v3/blob/e6080b303b0934ecec36c9284e0530d4129bb79e/clients/client-dynamodb/protocols/Aws_json1_0.ts#L3379-L3394
This parsed data from response is stored in the output in deseiralizerMiddleware https://github.com/aws/aws-sdk-js-v3/blob/e6080b303b0934ecec36c9284e0530d4129bb79e/packages/middleware-serde/src/deserializerMiddleware.ts#L20-L24
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.
Actually that parameter can be either a response
object or an error
object, and the error
object has $metadata
populated on it directly. However, I agree that this is a bit of an anti-pattern design so I'll make separate parameters for them.
|
||
const errObj = { message: err.message, name: err.name, stack: err.stack || new Error().stack }; | ||
subsegment.close(errObj, true); | ||
throw err; |
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.
Is throwing an Object instead of Error expected in Xray SDK?
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.
What do you mean? We construct the errObj
to record it in the X-Ray subsegment, so it conforms to our data model. But after recording it we just throw the original caught error.
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.
My bad, I mistakenly read as errObj being thrown. There's no issue here.
Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Codecov Report
@@ Coverage Diff @@
## aws-v3-support #416 +/- ##
=================================================
Coverage ? 54.33%
=================================================
Files ? 36
Lines ? 2650
Branches ? 0
=================================================
Hits ? 1440
Misses ? 1210
Partials ? 0 Continue to review full report at Codecov.
|
* Revert "Revert PR #386 (#412)" This reverts commit 9e20d2e. * Add proper TypeScript build logic (#417) * build core files to dist directory * fixed unit tests * updated workflows and readme * try to fix windows * fix ls * slashes * no more ls * zstd decompress * see what bin has * removed rsync * fixes * added sh * try xargs instead * cleanups * fixed publishing logic * Redesign AWS SDK V3 instrumentation to use middleware (#416) * updated deps and type file * removed type keyword added deps * remove changes to js * updated versions * finished redesign of aws sdk v3 instrumentation * refactored buildAttributes signature * add compile back to workflow * bumped tsd version instead Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> * removed dependencies and added docs * add back most changes, update types * removed aws-v3 branch from CI * fixed codecov to use dist directory * added blog post link Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Issue #, if available:
#411
Description of changes:
This change redesigns the AWS SDK V3 client instrumentation to use the AWS SDK's
Pluggable
interface, which makes all the instrumentation middleware-based instead of a hybrid solution of middleware and monkey-patching. There was an original plan to vend solely a plugin, which customers could use like:However, I decided to stick with the original user experience of:
This is for 3 reasons:
middlewareStack
)I was still unable to get the latter API to work perfectly with TypeScript, because I would still get the error described in aws/aws-sdk-js-v3#1803. But a workaround was to just cast the client to
any
while instrumenting, which is not ideal, but worked once I did it.Also, tests will not pass because I've removed the transpiled JS from source control, I will add the necessary lifecycle hooks to get tests & publishing working later. Just wanted eyes on the code ASAP.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.