* Applies `normalize` function on necessary `Event` attributes to make them safe for serialization. * Normalized keys: * - `breadcrumbs.data` * - `user` * - `contexts` * - `extra` * @param event Event * @returns Normalized event
(event: Event | null, depth: number, maxBreadth: number)
| 230 | * @returns Normalized event |
| 231 | */ |
| 232 | function normalizeEvent(event: Event | null, depth: number, maxBreadth: number): Event | null { |
| 233 | if (!event) { |
| 234 | return null; |
| 235 | } |
| 236 | |
| 237 | const normalized: Event = { |
| 238 | ...event, |
| 239 | ...(event.breadcrumbs && { |
| 240 | breadcrumbs: event.breadcrumbs.map(b => ({ |
| 241 | ...b, |
| 242 | ...(b.data && { |
| 243 | data: normalize(b.data, depth, maxBreadth), |
| 244 | }), |
| 245 | })), |
| 246 | }), |
| 247 | ...(event.user && { |
| 248 | user: normalize(event.user, depth, maxBreadth), |
| 249 | }), |
| 250 | ...(event.contexts && { |
| 251 | contexts: normalize(event.contexts, depth, maxBreadth), |
| 252 | }), |
| 253 | ...(event.extra && { |
| 254 | extra: normalize(event.extra, depth, maxBreadth), |
| 255 | }), |
| 256 | }; |
| 257 | |
| 258 | // event.contexts.trace stores information about a Transaction. Similarly, |
| 259 | // event.spans[] stores information about child Spans. Given that a |
| 260 | // Transaction is conceptually a Span, normalization should apply to both |
| 261 | // Transactions and Spans consistently. |
| 262 | // For now the decision is to skip normalization of Transactions and Spans, |
| 263 | // so this block overwrites the normalized event to add back the original |
| 264 | // Transaction information prior to normalization. |
| 265 | if (event.contexts?.trace && normalized.contexts) { |
| 266 | normalized.contexts.trace = event.contexts.trace; |
| 267 | |
| 268 | // event.contexts.trace.data may contain circular/dangerous data so we need to normalize it |
| 269 | if (event.contexts.trace.data) { |
| 270 | normalized.contexts.trace.data = normalize(event.contexts.trace.data, depth, maxBreadth); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | // event.spans[].data may contain circular/dangerous data so we need to normalize it |
| 275 | if (event.spans) { |
| 276 | normalized.spans = event.spans.map(span => { |
| 277 | return { |
| 278 | ...span, |
| 279 | ...(span.data && { |
| 280 | data: normalize(span.data, depth, maxBreadth), |
| 281 | }), |
| 282 | }; |
| 283 | }); |
| 284 | } |
| 285 | |
| 286 | // event.contexts.flags (FeatureFlagContext) stores context for our feature |
| 287 | // flag integrations. It has a greater nesting depth than our other typed |
| 288 | // Contexts, so we re-normalize with a fixed depth of 3 here. We do not want |
| 289 | // to skip this in case of conflicting, user-provided context. |
no test coverage detected