Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 8899079

Browse files
author
Amir Blum
authored
feat(aws-sdk): support for aws-sdk v3 (#91)
BREAKING CHANGE: remove `component` attribute from aws-sdk spans BREAKING CHANGE: change hooks function signature in aws-sdk
1 parent 36f480f commit 8899079

File tree

19 files changed

+775
-188
lines changed

19 files changed

+775
-188
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "root",
33
"private": true,
44
"scripts": {
5+
"watch": "lerna run watch --parallel",
56
"test": "lerna run test",
67
"test:ci": "lerna run test:ci --since origin/master",
78
"build": "lerna run build",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'aws-sdk':
2+
# there are so many version to test, it can take forever.
3+
# we will just sample few of them
4+
versions: ">=2.880.0 || 2.706.0 || 2.608.0 || 2.518.0 || 2.422.0 || 2.315.0 || 2.224.1 || 2.122.0 || 2.59.0"
5+
commands:
6+
- yarn test
7+
8+
'@aws-sdk/client-s3':
9+
versions: ">=3.0.0"
10+
commands:
11+
- yarn test
12+
13+
'@aws-sdk/client-sqs':
14+
versions: ">=3.0.0"
15+
commands:
16+
- yarn test

packages/instrumentation-aws-sdk/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# OpenTelemetry aws-sdk Instrumentation for Node.js
22
[![NPM version](https://img.shields.io/npm/v/opentelemetry-instrumentation-aws-sdk.svg)](https://www.npmjs.com/package/opentelemetry-instrumentation-aws-sdk)
33

4-
This module provides automatic instrumentation for [`aws-sdk`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/).
4+
This module provides automatic instrumentation for [`aws-sdk` v2](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/) and [`@aws-sdk` v3](https://github.com/aws/aws-sdk-js-v3)
55

66
## Installation
77

@@ -49,32 +49,36 @@ aws-sdk instrumentation has few options available to choose from. You can set th
4949

5050

5151
## Span Attributes
52-
This instrumentation patch the internal `Request` object, which means that each sdk operation will create a single span with attributes from 3 sources:
52+
Both V2 and V3 instrumentations are collecting the following attributes:
53+
| Attribute Name | Type | Description | Example |
54+
| -------------- | ---- | ----------- | ------- |
55+
| `rpc.system` | string | Always equals "aws-api" |
56+
| `rpc.method` | string | The name of the operation corresponding to the request, normalized to camelCase | `putObject` |
57+
| `rpc.service` | string | The name of the service to which a request is made, as returned by the AWS SDK, normalized to lower case | `s3` |
58+
| `aws.region` | string | Region name for the request | "eu-west-1" |
5359

54-
### Default attributes
55-
Each span will have the following attributes:
60+
### V2 attributes
61+
In addition to the above attributes, the instrumentation also collect the following for V2 ONLY:
5662
| Attribute Name | Type | Description | Example |
5763
| -------------- | ---- | ----------- | ------- |
58-
| `component` | string | Always equals "aws-sdk" | "aws-sdk" |
5964
| `aws.operation` | string | The method name for the request. | for `SQS.sendMessage(...)` the operation is "sendMessage" |
6065
| `aws.signature.version` | string | AWS version of authentication signature on the request. | "v4" |
61-
| `aws.region` | string | Region name for the request | "eu-west-1" |
6266
| `aws.service.api` | string | The sdk class name for the service | "SQS" |
6367
| `aws.service.identifier` | string | Identifier for the service in the sdk | "sqs" |
6468
| `aws.service.name` | string | Abbreviation name for the service | "Amazon SQS" |
6569
| `aws.request.id` | uuid | Request unique id, as returned from aws on response | "01234567-89ab-cdef-0123-456789abcdef" |
6670
| `aws.error` | string | information about a service or networking error, as returned from AWS | "UriParameterError: Expected uri parameter to have length >= 1, but found "" for params.Bucket" |
6771

6872
### Custom User Attributes
69-
The instrumentation user can configure a `preRequestHook` function which will be called before each request, with the request object and the corresponding span.
73+
The instrumentation user can configure a `preRequestHook` function which will be called before each request, with a normalized request object (across v2 and v3) and the corresponding span.
7074
This hook can be used to add custom attributes to the span with any logic.
7175
For example, user can add interesting attributes from the `request.params`, and write custom logic based on the service and operation.
7276
Usage example:
7377
```js
7478
awsInstrumentationConfig = {
7579
preRequestHook: (span, request) => {
76-
if (span.attributes["aws.service.api"] === 's3') {
77-
span.setAttribute("s3.bucket.name", request.params["Bucket"]);
80+
if (span.serviceName === 's3') {
81+
span.setAttribute("s3.bucket.name", request.commandInput["Bucket"]);
7882
}
7983
}
8084
};
@@ -85,6 +89,7 @@ AWS contains dozens of services accessible with the JS SDK. For many services, t
8589

8690
Specific service logic currently implemented for:
8791
* [SQS](./docs/sqs.md)
92+
* DynamoDb
8893

8994
---
9095

packages/instrumentation-aws-sdk/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
"build": "tsc",
2525
"prepare": "yarn run build",
2626
"test": "mocha",
27-
"test:ci": "yarn test",
27+
"test:ci": "yarn test-all-versions",
2828
"watch": "tsc -w",
2929
"version:update": "node ../../scripts/version-update.js",
30-
"version": "yarn run version:update"
30+
"version": "yarn run version:update",
31+
"test-all-versions": "tav"
3132
},
3233
"bugs": {
3334
"url": "https://github.com/aspecto-io/opentelemetry-ext-js/issues"
@@ -39,13 +40,18 @@
3940
"opentelemetry-propagation-utils": "^0.5.0"
4041
},
4142
"devDependencies": {
43+
"@aws-sdk/client-s3": "^3.8.1",
44+
"@aws-sdk/client-sqs": "^3.8.1",
45+
"@aws-sdk/types": "^3.6.1",
4246
"@opentelemetry/api": "^0.18.0",
4347
"@opentelemetry/node": "^0.18.0",
4448
"@opentelemetry/tracing": "^0.18.0",
4549
"@types/mocha": "^8.2.0",
4650
"aws-sdk": "^2.780.0",
4751
"expect": "^26.6.2",
4852
"mocha": "^8.3.0",
53+
"nock": "^13.0.11",
54+
"test-all-versions": "^5.0.1",
4955
"ts-node": "^9.1.1",
5056
"typescript": "^4.0.5"
5157
},

0 commit comments

Comments
 (0)