Skip to content

Commit

Permalink
fix(aws-sdk): add http status code attribute to aws sdk span if aws s…
Browse files Browse the repository at this point in the history
…dk 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 <amirgiraffe@gmail.com>
  • Loading branch information
jj22ee and blumamir committed Jul 23, 2024
1 parent 4bb28c9 commit 9a06381
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 9a06381

Please sign in to comment.