@ogcio/o11y-sdk-react
Version:
Opentelemetry standard instrumentation SDK for React based project
33 lines (32 loc) • 954 B
JavaScript
import { _cleanStringPII } from "./pii-detection.js";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function _cleanObjectPII(data, type) {
if (!data) {
return;
}
if (Array.isArray(data)) {
data.forEach((item, index) => {
if (typeof item === "string") {
data[index] = _cleanStringPII(data[index], type);
return;
}
if (typeof item === "object") {
_cleanObjectPII(item, type);
}
});
}
if (typeof data === "object") {
for (const key in data) {
if (typeof data[key] === "string") {
data[key] = _cleanStringPII(data[key], type);
}
if (typeof data[key] === "object") {
_cleanObjectPII(data[key], type);
}
}
}
}
export function _beforeSend(item) {
_cleanObjectPII(item, item.type);
return item;
}