@@ -10,6 +10,10 @@ import {
1010} from '@sentry/types' ;
1111import { getGlobalObject , isThenable , normalize , SyncPromise , timestampWithMs } from '@sentry/utils' ;
1212
13+ import { getCurrentHub } from './hub' ;
14+
15+ const DEFAULT_NORMALIZE_DEPTH = 3 ;
16+
1317/**
1418 * Holds additional event information. {@link Scope.applyToEvent} will be
1519 * called by the client before an event will be sent.
@@ -115,7 +119,9 @@ export class Scope implements ScopeInterface {
115119 * @inheritDoc
116120 */
117121 public setUser ( user : User | null ) : this {
118- this . _user = normalize ( user ) ;
122+ const client = getCurrentHub ( ) . getClient ( ) ;
123+ const normalizeDepth = ( client && client . getOptions ( ) . normalizeDepth ) || DEFAULT_NORMALIZE_DEPTH ;
124+ this . _user = normalize ( user , normalizeDepth ) ;
119125 this . _notifyScopeListeners ( ) ;
120126 return this ;
121127 }
@@ -126,7 +132,7 @@ export class Scope implements ScopeInterface {
126132 public setTags ( tags : { [ key : string ] : string } ) : this {
127133 this . _tags = {
128134 ...this . _tags ,
129- ...normalize ( tags ) ,
135+ ...tags ,
130136 } ;
131137 this . _notifyScopeListeners ( ) ;
132138 return this ;
@@ -136,19 +142,22 @@ export class Scope implements ScopeInterface {
136142 * @inheritDoc
137143 */
138144 public setTag ( key : string , value : string ) : this {
139- this . _tags = { ...this . _tags , [ key ] : normalize ( value ) } ;
145+ this . _tags = { ...this . _tags , [ key ] : value } ;
140146 this . _notifyScopeListeners ( ) ;
141147 return this ;
142148 }
143149
144150 /**
145151 * @inheritDoc
146152 */
147- public setExtras ( extra : { [ key : string ] : any } ) : this {
148- this . _extra = {
149- ...this . _extra ,
150- ...normalize ( extra ) ,
151- } ;
153+ public setExtras ( extras : { [ key : string ] : any } ) : this {
154+ const client = getCurrentHub ( ) . getClient ( ) ;
155+ const normalizeDepth = ( client && client . getOptions ( ) . normalizeDepth ) || DEFAULT_NORMALIZE_DEPTH ;
156+ for ( const key in extras ) {
157+ if ( Object . prototype . hasOwnProperty . call ( extras , key ) ) {
158+ this . _extra [ key ] = normalize ( extras [ key ] , normalizeDepth ) ;
159+ }
160+ }
152161 this . _notifyScopeListeners ( ) ;
153162 return this ;
154163 }
@@ -157,7 +166,9 @@ export class Scope implements ScopeInterface {
157166 * @inheritDoc
158167 */
159168 public setExtra ( key : string , extra : any ) : this {
160- this . _extra = { ...this . _extra , [ key ] : normalize ( extra ) } ;
169+ const client = getCurrentHub ( ) . getClient ( ) ;
170+ const normalizeDepth = ( client && client . getOptions ( ) . normalizeDepth ) || DEFAULT_NORMALIZE_DEPTH ;
171+ this . _extra = { ...this . _extra , [ key ] : normalize ( extra , normalizeDepth ) } ;
161172 this . _notifyScopeListeners ( ) ;
162173 return this ;
163174 }
@@ -166,7 +177,7 @@ export class Scope implements ScopeInterface {
166177 * @inheritDoc
167178 */
168179 public setFingerprint ( fingerprint : string [ ] ) : this {
169- this . _fingerprint = normalize ( fingerprint ) ;
180+ this . _fingerprint = fingerprint ;
170181 this . _notifyScopeListeners ( ) ;
171182 return this ;
172183 }
@@ -175,7 +186,7 @@ export class Scope implements ScopeInterface {
175186 * @inheritDoc
176187 */
177188 public setLevel ( level : Severity ) : this {
178- this . _level = normalize ( level ) ;
189+ this . _level = level ;
179190 this . _notifyScopeListeners ( ) ;
180191 return this ;
181192 }
@@ -196,7 +207,9 @@ export class Scope implements ScopeInterface {
196207 * @inheritDoc
197208 */
198209 public setContext ( name : string , context : { [ key : string ] : any } | null ) : this {
199- this . _context [ name ] = context ? normalize ( context ) : undefined ;
210+ const client = getCurrentHub ( ) . getClient ( ) ;
211+ const normalizeDepth = ( client && client . getOptions ( ) . normalizeDepth ) || DEFAULT_NORMALIZE_DEPTH ;
212+ this . _context [ name ] = context ? normalize ( context , normalizeDepth ) : undefined ;
200213 this . _notifyScopeListeners ( ) ;
201214 return this ;
202215 }
@@ -260,13 +273,20 @@ export class Scope implements ScopeInterface {
260273 * @inheritDoc
261274 */
262275 public addBreadcrumb ( breadcrumb : Breadcrumb , maxBreadcrumbs ?: number ) : this {
263- const timestamp = timestampWithMs ( ) ;
264- const mergedBreadcrumb = { timestamp, ...breadcrumb } ;
276+ const client = getCurrentHub ( ) . getClient ( ) ;
277+ const normalizeDepth = ( client && client . getOptions ( ) . normalizeDepth ) || DEFAULT_NORMALIZE_DEPTH ;
278+ const normalizedBreadcrumb = normalize (
279+ {
280+ timestamp : timestampWithMs ( ) ,
281+ ...breadcrumb ,
282+ } ,
283+ normalizeDepth ,
284+ ) ;
265285
266286 this . _breadcrumbs =
267287 maxBreadcrumbs !== undefined && maxBreadcrumbs >= 0
268- ? [ ...this . _breadcrumbs , normalize ( mergedBreadcrumb ) ] . slice ( - maxBreadcrumbs )
269- : [ ...this . _breadcrumbs , normalize ( mergedBreadcrumb ) ] ;
288+ ? [ ...this . _breadcrumbs , normalizedBreadcrumb ] . slice ( - maxBreadcrumbs )
289+ : [ ...this . _breadcrumbs , normalizedBreadcrumb ] ;
270290 this . _notifyScopeListeners ( ) ;
271291 return this ;
272292 }
0 commit comments