Skip to content

Commit 5b6d39b

Browse files
committed
ref: use safeNormalize on any data we store on Scope
1 parent dece6ee commit 5b6d39b

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- [node] Port memory-leak tests from raven-node
66
- [core] feat: ExtraErrorData integration
7+
- [hub] ref: use safeNormalize on any data we store on Scope
8+
- [utils] feat: Introduce safeNormalize util method to unify stored data
79

810
## 4.4.1
911

packages/hub/src/scope.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Breadcrumb, SentryEvent, SentryEventHint, Severity, User } from '@sentry/types';
22
import { getGlobalObject } from '@sentry/utils/misc';
3-
import { assign } from '@sentry/utils/object';
3+
import { assign, safeNormalize } from '@sentry/utils/object';
44

55
export type EventProcessor = (event: SentryEvent, hint?: SentryEventHint) => Promise<SentryEvent | null>;
66

@@ -85,7 +85,7 @@ export class Scope {
8585
* @param user User context object to merge into current context.
8686
*/
8787
public setUser(user: User): Scope {
88-
this.user = user;
88+
this.user = safeNormalize(user);
8989
this.notifyScopeListeners();
9090
return this;
9191
}
@@ -95,7 +95,7 @@ export class Scope {
9595
* @param tags Tags context object to merge into current context.
9696
*/
9797
public setTag(key: string, value: string): Scope {
98-
this.tags = { ...this.tags, [key]: value };
98+
this.tags = { ...this.tags, [key]: safeNormalize(value) };
9999
this.notifyScopeListeners();
100100
return this;
101101
}
@@ -105,7 +105,7 @@ export class Scope {
105105
* @param extra context object to merge into current context.
106106
*/
107107
public setExtra(key: string, extra: any): Scope {
108-
this.extra = { ...this.extra, [key]: extra };
108+
this.extra = { ...this.extra, [key]: safeNormalize(extra) };
109109
this.notifyScopeListeners();
110110
return this;
111111
}
@@ -115,7 +115,7 @@ export class Scope {
115115
* @param fingerprint string[] to group events in Sentry.
116116
*/
117117
public setFingerprint(fingerprint: string[]): Scope {
118-
this.fingerprint = fingerprint;
118+
this.fingerprint = safeNormalize(fingerprint);
119119
this.notifyScopeListeners();
120120
return this;
121121
}
@@ -125,7 +125,7 @@ export class Scope {
125125
* @param level string {@link Severity}
126126
*/
127127
public setLevel(level: Severity): Scope {
128-
this.level = level;
128+
this.level = safeNormalize(level);
129129
this.notifyScopeListeners();
130130
return this;
131131
}
@@ -167,8 +167,8 @@ export class Scope {
167167
public addBreadcrumb(breadcrumb: Breadcrumb, maxBreadcrumbs?: number): void {
168168
this.breadcrumbs =
169169
maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
170-
? [...this.breadcrumbs, breadcrumb].slice(-maxBreadcrumbs)
171-
: [...this.breadcrumbs, breadcrumb];
170+
? [...this.breadcrumbs, safeNormalize(breadcrumb)].slice(-maxBreadcrumbs)
171+
: [...this.breadcrumbs, safeNormalize(breadcrumb)];
172172
this.notifyScopeListeners();
173173
}
174174

0 commit comments

Comments
 (0)