-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_extractor.js
More file actions
24 lines (23 loc) · 884 Bytes
/
Copy pathcustom_extractor.js
File metadata and controls
24 lines (23 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// This function is used to extract the traceId, parentId, and sampleMode from the incoming event.
// An example json payload is:
// {
// "request":{
// "headers":{
// "traceparent":"00-0000000000000000abcdef1234567890-12341e2abcdefabc-02",
// "x-datadog-parent-id": "1234567123456789000",
// "x-datadog-trace-id": "9876543217654321000",
// "x-datadog-sampling-priority": 1,
// "x-datadog-origin": "rum"
// }}
// }
exports.nestedJsonExtractor = (event, _) => {
const nestedJson = event.request.headers; // the payload is nested inside the "request" key
const result = {
traceId: nestedJson["x-datadog-trace-id"],
parentId: nestedJson["x-datadog-parent-id"],
sampleMode: 1, //parseInt(nestedJson["x-datadog-sampling-priority"], 10);
source: "event",
};
console.log(JSON.stringify(result));
return result;
};