Skip to content
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(aws-sdk): add s3 and kinesis service extensions for aws-sdk instrumentation #2361

Merged
merged 12 commits into from
Nov 1, 2024
108 changes: 98 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@
},
"devDependencies": {
"@aws-sdk/client-dynamodb": "3.85.0",
"@aws-sdk/client-kinesis": "3.85.0",
blumamir marked this conversation as resolved.
Show resolved Hide resolved
"@aws-sdk/client-lambda": "3.85.0",
"@aws-sdk/client-s3": "3.85.0",
"@aws-sdk/client-sns": "3.85.0",
"@aws-sdk/client-sqs": "3.85.0",
"@aws-sdk/types": "3.78.0",
"@smithy/node-http-handler": "2.4.0",
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/contrib-test-utils": "^0.42.0",
"@opentelemetry/sdk-trace-base": "^1.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ export enum AttributeNames {
AWS_REQUEST_ID = 'aws.request.id',
AWS_REQUEST_EXTENDED_ID = 'aws.request.extended_id',
AWS_SIGNATURE_VERSION = 'aws.signature.version',

// TODO: Add these semantic attributes to:
// - https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-semantic-conventions/src/trace/SemanticAttributes.ts
// For S3, see specification: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/object-stores/s3.md
AWS_S3_BUCKET = 'aws.s3.bucket',
AWS_KINESIS_STREAM_NAME = 'aws.kinesis.stream.name',
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
import { DynamodbServiceExtension } from './dynamodb';
import { SnsServiceExtension } from './sns';
import { LambdaServiceExtension } from './lambda';
import { S3ServiceExtension } from './s3';
import { KinesisServiceExtension } from './kinesis';

export class ServicesExtensions implements ServiceExtension {
services: Map<string, ServiceExtension> = new Map();
Expand All @@ -33,6 +35,8 @@ export class ServicesExtensions implements ServiceExtension {
this.services.set('SNS', new SnsServiceExtension());
this.services.set('DynamoDB', new DynamodbServiceExtension());
this.services.set('Lambda', new LambdaServiceExtension());
this.services.set('S3', new S3ServiceExtension());
this.services.set('Kinesis', new KinesisServiceExtension());
}

requestPreSpanHook(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Attributes, SpanKind } from '@opentelemetry/api';
import { AttributeNames } from '../enums';
import { AwsSdkInstrumentationConfig, NormalizedRequest } from '../types';
import { RequestMetadata, ServiceExtension } from './ServiceExtension';

export class KinesisServiceExtension implements ServiceExtension {
requestPreSpanHook(
request: NormalizedRequest,
_config: AwsSdkInstrumentationConfig
): RequestMetadata {
const streamName = request.commandInput?.StreamName;
const spanKind: SpanKind = SpanKind.CLIENT;
const spanAttributes: Attributes = {};

if (streamName) {
spanAttributes[AttributeNames.AWS_KINESIS_STREAM_NAME] = streamName;
}

const isIncoming = false;

return {
isIncoming,
spanAttributes,
spanKind,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Attributes, SpanKind } from '@opentelemetry/api';
import { AttributeNames } from '../enums';
import { AwsSdkInstrumentationConfig, NormalizedRequest } from '../types';
import { RequestMetadata, ServiceExtension } from './ServiceExtension';

export class S3ServiceExtension implements ServiceExtension {
requestPreSpanHook(
request: NormalizedRequest,
_config: AwsSdkInstrumentationConfig
): RequestMetadata {
const bucketName = request.commandInput?.Bucket;
const spanKind: SpanKind = SpanKind.CLIENT;
blumamir marked this conversation as resolved.
Show resolved Hide resolved
const spanAttributes: Attributes = {};

if (bucketName) {
spanAttributes[AttributeNames.AWS_S3_BUCKET] = bucketName;
}

const isIncoming = false;

return {
isIncoming,
spanAttributes,
spanKind,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NormalizedRequest } from './types';
import { Attributes, Context, context } from '@opentelemetry/api';
import {
SEMATTRS_RPC_METHOD,
SEMATTRS_RPC_SERVICE,
SEMATTRS_RPC_SYSTEM,
} from '@opentelemetry/semantic-conventions';
import { AttributeNames } from './enums';
import { NormalizedRequest } from './types';

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