forked from getndazn/dazn-lambda-powertools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (41 loc) · 948 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const DEBUG_LOG_ENABLED = 'debug-log-enabled'
class CorrelationIds {
constructor (context = {}) {
this.context = context
}
clearAll () {
this.context = {}
}
replaceAllWith (ctx) {
this.context = ctx
}
set (key, value) {
if (!key.startsWith('x-correlation-')) {
key = 'x-correlation-' + key
}
this.context[key] = value
}
get () {
return this.context
}
get debugEnabled () {
return this.context[DEBUG_LOG_ENABLED] === 'true'
}
static clearAll () {
globalCorrelationIds.clearAll()
}
static replaceAllWith (...args) {
globalCorrelationIds.replaceAllWith(...args)
}
static set (...args) {
globalCorrelationIds.set(...args)
}
static get () {
return globalCorrelationIds.get()
}
};
if (!global.CORRELATION_IDS) {
global.CORRELATION_IDS = new CorrelationIds()
}
const globalCorrelationIds = global.CORRELATION_IDS
module.exports = CorrelationIds