-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.js
59 lines (51 loc) · 1.34 KB
/
helper.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
56
57
58
59
"use strict";
const tagPrimitive = (span, key, value) => {
span.setTag(key, value);
};
const tagObject = (span, obj) => {
for (let key in obj) {
if (!obj[key]) continue;
if (isArray(obj[key])) {
tagArray(span, obj, key);
continue;
}
if (isPrimitive(obj[key])) {
tagPrimitive(span, key, obj[key]);
continue;
}
tagObject(span, obj[key]);
}
};
const tagArray = (span, arr, key) => {
for (let index = 0; index < arr.length; index++) {
const item = arr[index];
if (isPrimitive(item)) {
tagPrimitive(span, `${key}${index}`, item);
continue;
}
tagObject(span, item);
}
};
const isPrimitive = input => {
return input !== Object(input);
};
const isArray = input => {
return Array.isArray(input);
};
const isExcludedPath = (method,requestPath, options) => {
const { excludedPath = [] } = options;
if (requestPath.includes("health") || requestPath.includes("public")) return true;
for (let index = 0; index < excludedPath.length; index++) {
const path = excludedPath[index];
if(requestPath.includes(path.url) && path.method.toLowerCase()===method.toLowerCase()) return true;
}
return false;
};
const isEmptyObject = (input)=>{
return Object.keys(input).length === 0 && input.constructor === Object
}
module.exports = {
tagObject,
isExcludedPath,
isEmptyObject
};