Merged in feat/sw-3560-sanitize2 (pull request #3001)

feat(SW-3560): send parameters to sentry logs

* feat(SW-3560): send parameters to sentry logs

* Use flatten instead of sanitize when logging


Approved-by: Joakim Jäderberg
This commit is contained in:
Linus Flood
2025-10-23 11:30:15 +00:00
parent a00cf8d327
commit 6374085a36
3 changed files with 70 additions and 157 deletions

View File

@@ -42,18 +42,6 @@ describe("sanitize", () => {
expect(sanitize(input)).toEqual(expected)
})
test("should stringify non-valid attributes", () => {
const input = {
key1: new Date("2024-08-08T12:00:00Z"),
key2: { nested: "object" },
}
const expected = {
key1: '"2024-08-08T12:00:00.000Z"',
"key2.nested": "object",
}
expect(sanitize(input)).toEqual(expected)
})
test("should handle nested valid attributes", () => {
const input = {
key1: "Example",
@@ -82,54 +70,42 @@ describe("sanitize", () => {
nestedKey1: "Value",
nestedKey2: {
nestedKey2Key1: true,
nestedKey2Key2: new Date("2024-08-08T12:00:00Z"),
},
nestedKey3: {
reallyNested: "hello",
},
},
nonPrimitive: new Date("2024-08-08T13:00:00Z"),
}
const expected = {
key1: "Example",
key2: 10,
"nested.nestedKey1": "Value",
"nested.nestedKey2.nestedKey2Key1": true,
"nested.nestedKey2.nestedKey2Key2": '"2024-08-08T12:00:00.000Z"',
"nested.nestedKey3.reallyNested": "hello",
nonPrimitive: '"2024-08-08T13:00:00.000Z"',
}
expect(sanitize(input)).toEqual(expected)
})
test("should throw an error when a function is passed", () => {
const key1 = () => {}
const input = {
key1: () => {},
key1,
}
const expected = {
key1,
}
expect(() => sanitize(input)).toThrowError("Cannot sanitize function")
})
test("should throw an error when input not an object", () => {
// @ts-expect-error: array not allowed. We do this here to make sure the
// function not only relies on TS but actively blocks arrays as input.
expect(() => sanitize(null)).toThrowError()
// @ts-expect-error: array not allowed. We do this here to make sure the
// function not only relies on TS but actively blocks arrays as input.
expect(() => sanitize(undefined)).toThrowError()
// @ts-expect-error: array not allowed. We do this here to make sure the
// function not only relies on TS but actively blocks arrays as input.
expect(() => sanitize("")).toThrowError()
// @ts-expect-error: array not allowed. We do this here to make sure the
// function not only relies on TS but actively blocks arrays as input.
expect(() => sanitize([1, 2, 3])).toThrowError()
})
test("should handle empty input", () => {
const input = {}
const expected = {}
expect(sanitize(input)).toEqual(expected)
})
test("should handle when input is not an object", () => {
expect(sanitize(null)).toEqual({})
expect(sanitize(undefined)).toEqual({})
expect(sanitize("")).toEqual({})
expect(sanitize([1, 2, 3])).toEqual({ "0": 1, "1": 2, "2": 3 })
expect(sanitize("Test string")).toEqual({ value: "Test string" })
})
})