-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (26 loc) · 1.21 KB
/
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
const { trace, context, propagation } = require('@opentelemetry/api');
function customBaggage(req, res, next) {
let headers = req.headers;
let chapterId = headers['x-chapter-id'];
let sessionId = headers['x-session-id'];
let userId = headers['x-user-id'];
let triggerRoute = headers['x-triggerroute'];
let requestData = headers['x-requestdata'];
let currentSpan = trace.getSpan(context.active());
currentSpan.setAttribute('frontendChapter', chapterId);
currentSpan.setAttribute('frontendSession', sessionId);
currentSpan.setAttribute('frontendUser', userId);
currentSpan.setAttribute('triggerRoute', triggerRoute);
currentSpan.setAttribute('requestData', requestData);
const baggage =
propagation.getBaggage(context.active()) || propagation.createBaggage();
const updatedBaggage = baggage
.setEntry('frontendChapter', { value: chapterId })
.setEntry('frontendSession', { value: sessionId })
.setEntry('frontendUser', { value: userId })
.setEntry('triggerRoute', { value: triggerRoute })
.setEntry('requestData', { value: requestData });
const newContext = propagation.setBaggage(context.active(), updatedBaggage);
context.with(newContext, next);
}
module.exports = customBaggage;