Skip to content

Commit 00d720e

Browse files
committed
capture request info in pre-request hook
1 parent ea44c4d commit 00d720e

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55

66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77

8+
## [Unreleased]
9+
10+
* AWS SDK Instrumentation - capture request info in pre-request hook
11+
812
## [0.5.5] - 2024-03-28
913

1014
* Fix: don't swallow lambda errors

meta.wrapper.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,7 +3586,7 @@
35863586
"format": "cjs"
35873587
},
35883588
"src/lambda-wrapper.ts": {
3589-
"bytes": 753,
3589+
"bytes": 1357,
35903590
"imports": [
35913591
{
35923592
"path": "node_modules/@opentelemetry/instrumentation-aws-sdk/build/src/index.js",
@@ -4654,10 +4654,10 @@
46544654
"bytesInOutput": 262747
46554655
},
46564656
"src/lambda-wrapper.ts": {
4657-
"bytesInOutput": 430
4657+
"bytesInOutput": 823
46584658
}
46594659
},
4660-
"bytes": 487187
4660+
"bytes": 487580
46614661
}
46624662
}
46634663
}

src/lambda-wrapper.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@ import { flatten } from "flat";
44

55
import { BaselimeSDK, BetterHttpInstrumentation } from "@baselime/node-opentelemetry";
66

7+
const blockedRequestOperations = [
8+
{ service: 'S3', operation: 'PutObject' },
9+
{ service: 'Kinesis', operation: 'PutRecord' }
10+
]
11+
12+
const blockedResponseOperations = [
13+
{ service: 'S3', operation: 'GetObject' },
14+
]
15+
716
const instrumentations = [
817
new AwsInstrumentation({
918
suppressInternalInstrumentation: process.env.AWS_SDK_INTERNALS === 'true' ? false : true,
10-
responseHook: (span, { response }) => {
11-
if (response) {
12-
const awsApiReqData = {
13-
request: response.request,
19+
responseHook(span, { response }) {
20+
if (response && !blockedResponseOperations.some(({ service, operation }) => response.request.serviceName === service && response.request.commandName === operation)) {
21+
span.setAttributes(flatten({
1422
response: response.data,
15-
};
16-
span.setAttributes(flatten(awsApiReqData));
23+
}))
24+
}
25+
},
26+
preRequestHook(span, request) {
27+
if (!blockedRequestOperations.some(({ service, operation }) => request.request.serviceName === service && request.request.commandName === operation)) {
28+
span.setAttributes(flatten({
29+
request: request.request,
30+
}))
1731
}
1832
}
1933
}),
@@ -23,4 +37,4 @@ const instrumentations = [
2337
})
2438
]
2539

26-
new BaselimeSDK({ instrumentations }).start();
40+
new BaselimeSDK({ instrumentations, service: process.env.AWS_LAMBDA_FUNCTION_NAME }).start();

0 commit comments

Comments
 (0)