Skip to content

Commit cd896a4

Browse files
author
Luca Forstner
committed
Normalize free form data in spans
1 parent ceab6b9 commit cd896a4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

packages/core/src/baseclient.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
477477
return null;
478478
}
479479

480-
const normalized = {
480+
const normalized: Event = {
481481
...event,
482482
...(event.breadcrumbs && {
483483
breadcrumbs: event.breadcrumbs.map(b => ({
@@ -497,6 +497,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
497497
extra: normalize(event.extra, depth, maxBreadth),
498498
}),
499499
};
500+
500501
// event.contexts.trace stores information about a Transaction. Similarly,
501502
// event.spans[] stores information about child Spans. Given that a
502503
// Transaction is conceptually a Span, normalization should apply to both
@@ -505,16 +506,24 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
505506
// so this block overwrites the normalized event to add back the original
506507
// Transaction information prior to normalization.
507508
if (event.contexts && event.contexts.trace) {
508-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
509+
normalized.contexts = {};
509510
normalized.contexts.trace = event.contexts.trace;
510511

511512
// event.contexts.trace.data may contain circular/dangerous data so we need to normalize it
512513
if (event.contexts.trace.data) {
513-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
514514
normalized.contexts.trace.data = normalize(event.contexts.trace.data, depth, maxBreadth);
515515
}
516516
}
517517

518+
// event.spans[].data may contain circular/dangerous data so we need to normalize it
519+
if (event.spans) {
520+
normalized.spans = event.spans.map(span => {
521+
// We cannot use the spread operator on span here because that overwrites the `toJSON` method
522+
span.data = normalize(span.data, depth, maxBreadth);
523+
return span;
524+
});
525+
}
526+
518527
normalized.sdkProcessingMetadata = { ...normalized.sdkProcessingMetadata, baseClientNormalized: true };
519528

520529
return normalized;

0 commit comments

Comments
 (0)