Skip to content

Commit 9a06381

Browse files
jj22eeblumamir
andauthored
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 <[email protected]>
1 parent 4bb28c9 commit 9a06381

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,15 @@ export class AwsInstrumentation extends InstrumentationBase {
538538
if (requestId) {
539539
span.setAttribute(AttributeNames.AWS_REQUEST_ID, requestId);
540540
}
541+
542+
const httpStatusCode = err?.$metadata?.httpStatusCode;
543+
if (httpStatusCode) {
544+
span.setAttribute(
545+
SEMATTRS_HTTP_STATUS_CODE,
546+
httpStatusCode
547+
);
548+
}
549+
541550
const extendedRequestId = err?.extendedRequestId;
542551
if (extendedRequestId) {
543552
span.setAttribute(

plugins/node/opentelemetry-instrumentation-aws-sdk/test/aws-sdk-v3.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ describe('instrumentation-aws-sdk-v3', () => {
167167
expect(span.attributes[SEMATTRS_RPC_SYSTEM]).toEqual('aws-api');
168168
expect(span.attributes[SEMATTRS_RPC_METHOD]).toEqual('PutObject');
169169
expect(span.attributes[SEMATTRS_RPC_SERVICE]).toEqual('S3');
170+
expect(span.attributes[SEMATTRS_HTTP_STATUS_CODE]).toEqual(403);
170171
expect(span.attributes[AttributeNames.AWS_REGION]).toEqual(region);
171172
expect(span.attributes[AttributeNames.AWS_REQUEST_ID]).toEqual(
172173
'MS95GTS7KXQ34X2S'

0 commit comments

Comments
 (0)