1
import * as uuid from 'uuid'
2

3 0
export const requestIdHeader = 'Request-Id'
4

5
// tslint:disable-next-line: no-unnecessary-class
6
export class RequestId {
7 0
  static ids: string[] = []
8

9
  static track(...ids: string[]) {
10 0
    const tracked = RequestId.ids
11 0
    ids = ids.filter(id => !(tracked.includes(id)))
12 0
    RequestId.ids = [...ids, ...tracked]
13 0
    return RequestId.ids
14
  }
15

16
  static create(): string[] {
17 0
    const tracked = RequestId.ids
18 0
    const generatedId = RequestId._generate()
19 0
    RequestId.ids = [generatedId, ...tracked]
20 0
    return RequestId.ids
21
  }
22

23
  static empty(): void {
24 0
    RequestId.ids = []
25
  }
26

27
  static get headerValue() {
28 0
    return RequestId.ids.join(',')
29
  }
30

31
  static _generate() {
32 0
    return uuid.v4()
33
  }
34
}

Read our documentation on viewing source code .

Loading