Skip to content

Commit a5b5614

Browse files
jj22eeblumamir
andauthored
feat(aws-sdk): add s3 and kinesis service extensions for aws-sdk instrumentation (#2361)
Co-authored-by: Amir Blum <[email protected]>
1 parent ad8c581 commit a5b5614

File tree

11 files changed

+352
-11
lines changed

11 files changed

+352
-11
lines changed

package-lock.json

+98-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/node/opentelemetry-instrumentation-aws-sdk/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@
5252
},
5353
"devDependencies": {
5454
"@aws-sdk/client-dynamodb": "3.85.0",
55+
"@aws-sdk/client-kinesis": "3.85.0",
5556
"@aws-sdk/client-lambda": "3.85.0",
5657
"@aws-sdk/client-s3": "3.85.0",
5758
"@aws-sdk/client-sns": "3.85.0",
5859
"@aws-sdk/client-sqs": "3.85.0",
5960
"@aws-sdk/types": "3.78.0",
61+
"@smithy/node-http-handler": "2.4.0",
6062
"@opentelemetry/api": "^1.3.0",
6163
"@opentelemetry/contrib-test-utils": "^0.42.0",
6264
"@opentelemetry/sdk-trace-base": "^1.8.0",

plugins/node/opentelemetry-instrumentation-aws-sdk/src/enums.ts

+6
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@ export enum AttributeNames {
2222
AWS_REQUEST_ID = 'aws.request.id',
2323
AWS_REQUEST_EXTENDED_ID = 'aws.request.extended_id',
2424
AWS_SIGNATURE_VERSION = 'aws.signature.version',
25+
26+
// TODO: Add these semantic attributes to:
27+
// - https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts
28+
// For S3, see specification: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/object-stores/s3.md
29+
AWS_S3_BUCKET = 'aws.s3.bucket',
30+
AWS_KINESIS_STREAM_NAME = 'aws.kinesis.stream.name',
2531
}

plugins/node/opentelemetry-instrumentation-aws-sdk/src/services/ServicesExtensions.ts

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
import { DynamodbServiceExtension } from './dynamodb';
2525
import { SnsServiceExtension } from './sns';
2626
import { LambdaServiceExtension } from './lambda';
27+
import { S3ServiceExtension } from './s3';
28+
import { KinesisServiceExtension } from './kinesis';
2729

2830
export class ServicesExtensions implements ServiceExtension {
2931
services: Map<string, ServiceExtension> = new Map();
@@ -33,6 +35,8 @@ export class ServicesExtensions implements ServiceExtension {
3335
this.services.set('SNS', new SnsServiceExtension());
3436
this.services.set('DynamoDB', new DynamodbServiceExtension());
3537
this.services.set('Lambda', new LambdaServiceExtension());
38+
this.services.set('S3', new S3ServiceExtension());
39+
this.services.set('Kinesis', new KinesisServiceExtension());
3640
}
3741

3842
requestPreSpanHook(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import { Attributes, SpanKind } from '@opentelemetry/api';
17+
import { AttributeNames } from '../enums';
18+
import { AwsSdkInstrumentationConfig, NormalizedRequest } from '../types';
19+
import { RequestMetadata, ServiceExtension } from './ServiceExtension';
20+
21+
export class KinesisServiceExtension implements ServiceExtension {
22+
requestPreSpanHook(
23+
request: NormalizedRequest,
24+
_config: AwsSdkInstrumentationConfig
25+
): RequestMetadata {
26+
const streamName = request.commandInput?.StreamName;
27+
const spanKind: SpanKind = SpanKind.CLIENT;
28+
const spanAttributes: Attributes = {};
29+
30+
if (streamName) {
31+
spanAttributes[AttributeNames.AWS_KINESIS_STREAM_NAME] = streamName;
32+
}
33+
34+
const isIncoming = false;
35+
36+
return {
37+
isIncoming,
38+
spanAttributes,
39+
spanKind,
40+
};
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import { Attributes, SpanKind } from '@opentelemetry/api';
17+
import { AttributeNames } from '../enums';
18+
import { AwsSdkInstrumentationConfig, NormalizedRequest } from '../types';
19+
import { RequestMetadata, ServiceExtension } from './ServiceExtension';
20+
21+
export class S3ServiceExtension implements ServiceExtension {
22+
requestPreSpanHook(
23+
request: NormalizedRequest,
24+
_config: AwsSdkInstrumentationConfig
25+
): RequestMetadata {
26+
const bucketName = request.commandInput?.Bucket;
27+
const spanKind: SpanKind = SpanKind.CLIENT;
28+
const spanAttributes: Attributes = {};
29+
30+
if (bucketName) {
31+
spanAttributes[AttributeNames.AWS_S3_BUCKET] = bucketName;
32+
}
33+
34+
const isIncoming = false;
35+
36+
return {
37+
isIncoming,
38+
spanAttributes,
39+
spanKind,
40+
};
41+
}
42+
}

plugins/node/opentelemetry-instrumentation-aws-sdk/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { NormalizedRequest } from './types';
1716
import { Attributes, Context, context } from '@opentelemetry/api';
1817
import {
1918
SEMATTRS_RPC_METHOD,
2019
SEMATTRS_RPC_SERVICE,
2120
SEMATTRS_RPC_SYSTEM,
2221
} from '@opentelemetry/semantic-conventions';
2322
import { AttributeNames } from './enums';
23+
import { NormalizedRequest } from './types';
2424

2525
const toPascalCase = (str: string): string =>
2626
typeof str === 'string' ? str.charAt(0).toUpperCase() + str.slice(1) : str;

0 commit comments

Comments
 (0)