Skip to content

Commit afc1a75

Browse files
authored
[SVLS-3853] handle the null case first before handling max depth (#465)
* handle the null case first before max depth
1 parent 73f4af2 commit afc1a75

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/utils/tag-object.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ describe("tagObject", () => {
7171
level2_list: [null, true, "nice", { l3: "v3" }],
7272
level2_bool: true,
7373
level2_int: 2,
74+
level2_null: null,
75+
level2_empty_obj: {},
7476
},
7577
vals: [{ thingOne: 1 }, { thingTwo: 2 }],
7678
},
@@ -83,6 +85,8 @@ describe("tagObject", () => {
8385
["function.request.level1.level2_list", '[null,true,"nice",{"l3":"v3"}]'],
8486
["function.request.level1.level2_bool", "true"],
8587
["function.request.level1.level2_int", "2"],
88+
["function.request.level1.level2_null", null],
89+
["function.request.level1.level2_empty_obj", "{}"],
8690
["function.request.vals.0", '{"thingOne":1}'],
8791
["function.request.vals.1", '{"thingTwo":2}'],
8892
]);

src/utils/tag-object.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const redactableKeys = ["authorization", "x-authorization", "password", "token"];
22

33
export function tagObject(currentSpan: any, key: string, obj: any, depth = 0, maxDepth = 10): any {
4-
if (depth >= maxDepth) {
5-
return currentSpan.setTag(key, redactVal(key, JSON.stringify(obj).substring(0, 5000)));
6-
}
74
if (obj === null) {
85
return currentSpan.setTag(key, obj);
96
}
7+
if (depth >= maxDepth) {
8+
return currentSpan.setTag(key, redactVal(key, JSON.stringify(obj).substring(0, 5000)));
9+
}
1010
depth += 1;
1111
if (typeof obj === "string") {
1212
let parsed: string;

0 commit comments

Comments
 (0)