(eventName: string, data: Record<string, any>)
| 86 | } |
| 87 | |
| 88 | function sanitizeProperties(eventName: string, data: Record<string, any>) { |
| 89 | let customProperties: Record<string, string> = {}; |
| 90 | Object.getOwnPropertyNames(data).forEach((prop) => { |
| 91 | if (data[prop] === undefined || data[prop] === null) { |
| 92 | return; |
| 93 | } |
| 94 | try { |
| 95 | // If there are any errors in serializing one property, ignore that and move on. |
| 96 | // Else nothing will be sent. |
| 97 | customProperties[prop] = |
| 98 | typeof data[prop] === 'string' |
| 99 | ? data[prop] |
| 100 | : typeof data[prop] === 'object' |
| 101 | ? 'object' |
| 102 | : data[prop].toString(); |
| 103 | } catch (ex) { |
| 104 | logger.error(`Failed to serialize ${prop} for ${eventName}`, ex); |
| 105 | } |
| 106 | }); |
| 107 | return customProperties; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Send this & subsequent telemetry only after this promise has been resolved. |
no test coverage detected