UNPKG

@ogcio/o11y-sdk-react

Version:

Opentelemetry standard instrumentation SDK for React based project

46 lines (39 loc) 1.01 kB
import { APIEvent, TransportItem, TransportItemType, } from "@grafana/faro-web-sdk"; import { _cleanStringPII } from "./pii-detection.js"; // eslint-disable-next-line @typescript-eslint/no-explicit-any function _cleanObjectPII(data: any, type: TransportItemType) { 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: TransportItem<APIEvent>, ): TransportItem<APIEvent> | null { _cleanObjectPII(item, item.type); return item; }