From 9a06381afc6a7a27bc49af4ef796a547eafbf6ff Mon Sep 17 00:00:00 2001 From: Jonathan Lee <107072447+jj22ee@users.noreply.github.com> Date: Mon, 22 Jul 2024 23:39:07 -0700 Subject: [PATCH] fix(aws-sdk): add http status code attribute to aws sdk span if aws sdk v3 client exception occurs (#2344) * add http.status.code attribute value to span after aws sdk client exception * npm run lint:fix --------- Co-authored-by: Amir Blum --- .../opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts | 9 +++++++++ .../test/aws-sdk-v3.test.ts | 1 + 2 files changed, 10 insertions(+) diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts index cca362e293..1427ae0386 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts @@ -538,6 +538,15 @@ export class AwsInstrumentation extends InstrumentationBase { if (requestId) { span.setAttribute(AttributeNames.AWS_REQUEST_ID, requestId); } + + const httpStatusCode = err?.$metadata?.httpStatusCode; + if (httpStatusCode) { + span.setAttribute( + SEMATTRS_HTTP_STATUS_CODE, + httpStatusCode + ); + } + const extendedRequestId = err?.extendedRequestId; if (extendedRequestId) { span.setAttribute( diff --git a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts index 8dee305175..0e3a752c1b 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts @@ -167,6 +167,7 @@ describe('instrumentation-aws-sdk-v3', () => { expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api'); expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual('PutObject'); expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('S3'); + expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(403); expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region); expect(span.attributes[AttributeNames.AWS_REQUEST_ID]).toEqual( 'MS95GTS7KXQ34X2S'