-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlambda-wrapper.ts
40 lines (34 loc) · 1.32 KB
/
lambda-wrapper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { AwsInstrumentation } from "@opentelemetry/instrumentation-aws-sdk";
import { flatten } from "flat";
import { BaselimeSDK, BetterHttpInstrumentation } from "@baselime/node-opentelemetry";
const blockedRequestOperations = [
{ service: 'S3', operation: 'PutObject' },
{ service: 'Kinesis', operation: 'PutRecord' }
]
const blockedResponseOperations = [
{ service: 'S3', operation: 'GetObject' },
]
const instrumentations = [
new AwsInstrumentation({
suppressInternalInstrumentation: process.env.AWS_SDK_INTERNALS === 'true' ? false : true,
responseHook(span, { response }) {
if (response && !blockedResponseOperations.some(({ service, operation }) => response.request.serviceName === service && response.request.commandName === operation)) {
span.setAttributes(flatten({
response: response.data,
}))
}
},
preRequestHook(span, request) {
if (!blockedRequestOperations.some(({ service, operation }) => request.request.serviceName === service && request.request.commandName === operation)) {
span.setAttributes(flatten({
request: request.request,
}))
}
}
}),
new BetterHttpInstrumentation({
captureBody: process.env.BASELIME_REQUEST_CAPTURE === 'true' ? true : false,
captureHeaders: true,
})
]
new BaselimeSDK({ instrumentations, service: process.env.AWS_LAMBDA_FUNCTION_NAME }).start();