@@ -116,6 +116,8 @@ describe('ScopeSync', () => {
116116 let setExtrasScopeSpy : jest . SpyInstance ;
117117 let addBreadcrumbScopeSpy : jest . SpyInstance ;
118118 let setContextScopeSpy : jest . SpyInstance ;
119+ let setAttributeScopeSpy : jest . SpyInstance ;
120+ let setAttributesScopeSpy : jest . SpyInstance ;
119121
120122 beforeAll ( ( ) => {
121123 const testScope = SentryCore . getIsolationScope ( ) ;
@@ -126,6 +128,8 @@ describe('ScopeSync', () => {
126128 setExtrasScopeSpy = jest . spyOn ( testScope , 'setExtras' ) ;
127129 addBreadcrumbScopeSpy = jest . spyOn ( testScope , 'addBreadcrumb' ) ;
128130 setContextScopeSpy = jest . spyOn ( testScope , 'setContext' ) ;
131+ setAttributeScopeSpy = jest . spyOn ( testScope , 'setAttribute' ) ;
132+ setAttributesScopeSpy = jest . spyOn ( testScope , 'setAttributes' ) ;
129133 } ) ;
130134
131135 beforeEach ( ( ) => {
@@ -214,5 +218,70 @@ describe('ScopeSync', () => {
214218 expect ( NATIVE . setContext ) . toHaveBeenCalledExactlyOnceWith ( 'key' , { key : 'value' } ) ;
215219 expect ( setContextScopeSpy ) . toHaveBeenCalledExactlyOnceWith ( 'key' , { key : 'value' } ) ;
216220 } ) ;
221+
222+ it ( 'setAttribute' , ( ) => {
223+ expect ( SentryCore . getIsolationScope ( ) . setAttribute ) . not . toBe ( setAttributeScopeSpy ) ;
224+
225+ SentryCore . getIsolationScope ( ) . setAttribute ( 'session_id' , 'abc123' ) ;
226+ expect ( NATIVE . setAttribute ) . toHaveBeenCalledExactlyOnceWith ( 'session_id' , 'abc123' ) ;
227+ expect ( setAttributeScopeSpy ) . toHaveBeenCalledExactlyOnceWith ( 'session_id' , 'abc123' ) ;
228+ } ) ;
229+
230+ it ( 'setAttribute with number' , ( ) => {
231+ SentryCore . getIsolationScope ( ) . setAttribute ( 'request_count' , 42 ) ;
232+ expect ( NATIVE . setAttribute ) . toHaveBeenCalledExactlyOnceWith ( 'request_count' , 42 ) ;
233+ } ) ;
234+
235+ it ( 'setAttribute with boolean' , ( ) => {
236+ SentryCore . getIsolationScope ( ) . setAttribute ( 'is_admin' , true ) ;
237+ expect ( NATIVE . setAttribute ) . toHaveBeenCalledExactlyOnceWith ( 'is_admin' , true ) ;
238+ } ) ;
239+
240+ it ( 'setAttribute with non-primitive does not sync to native' , ( ) => {
241+ SentryCore . getIsolationScope ( ) . setAttribute ( 'complex' , { nested : 'object' } ) ;
242+ expect ( NATIVE . setAttribute ) . not . toHaveBeenCalled ( ) ;
243+ } ) ;
244+
245+ it ( 'setAttributes' , ( ) => {
246+ expect ( SentryCore . getIsolationScope ( ) . setAttributes ) . not . toBe ( setAttributesScopeSpy ) ;
247+
248+ SentryCore . getIsolationScope ( ) . setAttributes ( {
249+ session_type : 'test' ,
250+ request_count : 42 ,
251+ is_admin : true ,
252+ } ) ;
253+ expect ( NATIVE . setAttributes ) . toHaveBeenCalledExactlyOnceWith ( {
254+ session_type : 'test' ,
255+ request_count : 42 ,
256+ is_admin : true ,
257+ } ) ;
258+ expect ( setAttributesScopeSpy ) . toHaveBeenCalledExactlyOnceWith ( {
259+ session_type : 'test' ,
260+ request_count : 42 ,
261+ is_admin : true ,
262+ } ) ;
263+ } ) ;
264+
265+ it ( 'setAttributes filters non-primitive values' , ( ) => {
266+ SentryCore . getIsolationScope ( ) . setAttributes ( {
267+ session_type : 'test' ,
268+ request_count : 42 ,
269+ complex : { nested : 'object' } ,
270+ is_admin : true ,
271+ } ) ;
272+ expect ( NATIVE . setAttributes ) . toHaveBeenCalledExactlyOnceWith ( {
273+ session_type : 'test' ,
274+ request_count : 42 ,
275+ is_admin : true ,
276+ } ) ;
277+ } ) ;
278+
279+ it ( 'setAttributes does not sync to native if all values are non-primitive' , ( ) => {
280+ SentryCore . getIsolationScope ( ) . setAttributes ( {
281+ complex1 : { nested : 'object' } ,
282+ complex2 : [ 'array' ] ,
283+ } ) ;
284+ expect ( NATIVE . setAttributes ) . not . toHaveBeenCalled ( ) ;
285+ } ) ;
217286 } ) ;
218287} ) ;
0 commit comments