forked from getndazn/dazn-lambda-powertools
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
31 lines (27 loc) · 931 Bytes
/
index.js
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
const CorrelationIds = require('@dazn/lambda-powertools-correlation-ids')
const generic = require('./event-sources/generic')
const eventSources = [
require('./event-sources/api-gateway'),
require('./event-sources/sns'),
require('./event-sources/sqs'),
require('./event-sources/kinesis'),
require('./event-sources/dynamodb'),
require('./event-sources/firehose'),
require('./event-sources/eventbridge'),
require('./event-sources/direct-invoke')
]
module.exports = ({ sampleDebugLogRate }) => {
return {
before: (handler, next) => {
CorrelationIds.clearAll()
const { event, context } = handler
const eventSource = eventSources.find(evtSrc => evtSrc.isMatch(event))
if (eventSource) {
eventSource.captureCorrelationIds(event, context, sampleDebugLogRate)
} else {
generic.captureCorrelationIds(event, context, sampleDebugLogRate)
}
next()
}
}
}