@@ -9,7 +9,7 @@ import type {
99 ScopeContext ,
1010} from '@sentry/types' ;
1111import { GLOBAL_OBJ , createStackParser } from '@sentry/utils' ;
12- import { setGlobalScope } from '../../src' ;
12+ import { getCurrentHub , getIsolationScope , setGlobalScope } from '../../src' ;
1313
1414import { Scope , getGlobalScope } from '../../src/scope' ;
1515import {
@@ -192,6 +192,7 @@ describe('parseEventHintOrCaptureContext', () => {
192192describe ( 'prepareEvent' , ( ) => {
193193 beforeEach ( ( ) => {
194194 setGlobalScope ( undefined ) ;
195+ getCurrentHub ( ) . getIsolationScope ( ) . clear ( ) ;
195196 } ) ;
196197
197198 it ( 'works without any scope data' , async ( ) => {
@@ -240,12 +241,15 @@ describe('prepareEvent', () => {
240241 const breadcrumb1 = { message : '1' , timestamp : 111 } as Breadcrumb ;
241242 const breadcrumb2 = { message : '2' , timestamp : 222 } as Breadcrumb ;
242243 const breadcrumb3 = { message : '3' , timestamp : 123 } as Breadcrumb ;
244+ const breadcrumb4 = { message : '4' , timestamp : 123 } as Breadcrumb ;
243245
244246 const eventProcessor1 = jest . fn ( ( a : unknown ) => a ) as EventProcessor ;
245247 const eventProcessor2 = jest . fn ( ( b : unknown ) => b ) as EventProcessor ;
248+ const eventProcessor3 = jest . fn ( ( b : unknown ) => b ) as EventProcessor ;
246249
247250 const attachment1 = { filename : '1' } as Attachment ;
248251 const attachment2 = { filename : '2' } as Attachment ;
252+ const attachment3 = { filename : '3' } as Attachment ;
249253
250254 const scope = new Scope ( ) ;
251255 scope . update ( {
@@ -261,13 +265,19 @@ describe('prepareEvent', () => {
261265 scope . addAttachment ( attachment1 ) ;
262266
263267 const globalScope = getGlobalScope ( ) ;
268+ const isolationScope = getIsolationScope ( ) ;
264269
265270 globalScope . addBreadcrumb ( breadcrumb2 ) ;
266271 globalScope . addEventProcessor ( eventProcessor2 ) ;
267272 globalScope . setSDKProcessingMetadata ( { aa : 'aa' } ) ;
268273 globalScope . addAttachment ( attachment2 ) ;
269274
270- const event = { message : 'foo' , breadcrumbs : [ breadcrumb3 ] , fingerprint : [ 'dd' ] } ;
275+ isolationScope . addBreadcrumb ( breadcrumb3 ) ;
276+ isolationScope . addEventProcessor ( eventProcessor3 ) ;
277+ isolationScope . setSDKProcessingMetadata ( { bb : 'bb' } ) ;
278+ isolationScope . addAttachment ( attachment3 ) ;
279+
280+ const event = { message : 'foo' , breadcrumbs : [ breadcrumb4 ] , fingerprint : [ 'dd' ] } ;
271281
272282 const options = { } as ClientOptions ;
273283 const processedEvent = await prepareEvent (
@@ -277,15 +287,18 @@ describe('prepareEvent', () => {
277287 integrations : [ ] ,
278288 } ,
279289 scope ,
290+ undefined ,
291+ isolationScope ,
280292 ) ;
281293
282294 expect ( eventProcessor1 ) . toHaveBeenCalledTimes ( 1 ) ;
283295 expect ( eventProcessor2 ) . toHaveBeenCalledTimes ( 1 ) ;
296+ expect ( eventProcessor3 ) . toHaveBeenCalledTimes ( 1 ) ;
284297
285298 // Test that attachments are correctly merged
286299 expect ( eventProcessor1 ) . toHaveBeenCalledWith ( processedEvent , {
287300 integrations : [ ] ,
288- attachments : [ attachment2 , attachment1 ] ,
301+ attachments : [ attachment2 , attachment3 , attachment1 ] ,
289302 } ) ;
290303
291304 expect ( processedEvent ) . toEqual ( {
@@ -298,9 +311,10 @@ describe('prepareEvent', () => {
298311 extra : { extra1 : 'aa' , extra2 : 'aa' } ,
299312 contexts : { os : { name : 'os1' } , culture : { display_name : 'name1' } } ,
300313 fingerprint : [ 'dd' , 'aa' ] ,
301- breadcrumbs : [ breadcrumb3 , breadcrumb2 , breadcrumb1 ] ,
314+ breadcrumbs : [ breadcrumb4 , breadcrumb2 , breadcrumb3 , breadcrumb1 ] ,
302315 sdkProcessingMetadata : {
303316 aa : 'aa' ,
317+ bb : 'bb' ,
304318 propagationContext : {
305319 spanId : '1' ,
306320 traceId : '1' ,
@@ -312,33 +326,50 @@ describe('prepareEvent', () => {
312326 it ( 'works without a scope' , async ( ) => {
313327 const breadcrumb1 = { message : '1' , timestamp : 111 } as Breadcrumb ;
314328 const breadcrumb2 = { message : '2' , timestamp : 222 } as Breadcrumb ;
329+ const breadcrumb3 = { message : '3' , timestamp : 333 } as Breadcrumb ;
315330
316331 const eventProcessor1 = jest . fn ( ( a : unknown ) => a ) as EventProcessor ;
332+ const eventProcessor2 = jest . fn ( ( a : unknown ) => a ) as EventProcessor ;
317333
318- const attachment1 = { filename : '1' } as Attachment ;
319- const attachment2 = { filename : '2' } as Attachment ;
334+ const attachmentGlobal = { filename : 'global scope attachment' } as Attachment ;
335+ const attachmentIsolation = { filename : 'isolation scope attachment' } as Attachment ;
336+ const attachmentHint = { filename : 'hint attachment' } as Attachment ;
320337
321338 const globalScope = getGlobalScope ( ) ;
339+ const isolationScope = getIsolationScope ( ) ;
322340
323341 globalScope . addBreadcrumb ( breadcrumb1 ) ;
324342 globalScope . addEventProcessor ( eventProcessor1 ) ;
325343 globalScope . setSDKProcessingMetadata ( { aa : 'aa' } ) ;
326- globalScope . addAttachment ( attachment1 ) ;
344+ globalScope . addAttachment ( attachmentGlobal ) ;
327345
328- const event = { message : 'foo' , breadcrumbs : [ breadcrumb2 ] , fingerprint : [ 'dd' ] } ;
346+ isolationScope . addBreadcrumb ( breadcrumb2 ) ;
347+ isolationScope . addEventProcessor ( eventProcessor2 ) ;
348+ isolationScope . setSDKProcessingMetadata ( { bb : 'bb' } ) ;
349+ isolationScope . addAttachment ( attachmentIsolation ) ;
350+
351+ const event = { message : 'foo' , breadcrumbs : [ breadcrumb3 ] , fingerprint : [ 'dd' ] } ;
329352
330353 const options = { } as ClientOptions ;
331- const processedEvent = await prepareEvent ( options , event , {
332- integrations : [ ] ,
333- attachments : [ attachment2 ] ,
334- } ) ;
354+ const processedEvent = await prepareEvent (
355+ options ,
356+ event ,
357+ {
358+ integrations : [ ] ,
359+ attachments : [ attachmentHint ] ,
360+ } ,
361+ undefined ,
362+ undefined ,
363+ isolationScope ,
364+ ) ;
335365
336366 expect ( eventProcessor1 ) . toHaveBeenCalledTimes ( 1 ) ;
367+ expect ( eventProcessor2 ) . toHaveBeenCalledTimes ( 1 ) ;
337368
338369 // Test that attachments are correctly merged
339370 expect ( eventProcessor1 ) . toHaveBeenCalledWith ( processedEvent , {
340371 integrations : [ ] ,
341- attachments : [ attachment2 , attachment1 ] ,
372+ attachments : [ attachmentHint , attachmentGlobal , attachmentIsolation ] ,
342373 } ) ;
343374
344375 expect ( processedEvent ) . toEqual ( {
@@ -347,10 +378,11 @@ describe('prepareEvent', () => {
347378 environment : 'production' ,
348379 message : 'foo' ,
349380 fingerprint : [ 'dd' ] ,
350- breadcrumbs : [ breadcrumb2 , breadcrumb1 ] ,
381+ breadcrumbs : [ breadcrumb3 , breadcrumb1 , breadcrumb2 ] ,
351382 sdkProcessingMetadata : {
352383 aa : 'aa' ,
353- propagationContext : globalScope . getPropagationContext ( ) ,
384+ bb : 'bb' ,
385+ propagationContext : isolationScope . getPropagationContext ( ) ,
354386 } ,
355387 } ) ;
356388 } ) ;
0 commit comments