File tree Expand file tree Collapse file tree 4 files changed +20
-21
lines changed
Expand file tree Collapse file tree 4 files changed +20
-21
lines changed Original file line number Diff line number Diff line change @@ -242,10 +242,6 @@ export abstract class BaseClient<B extends Backend, O extends Options>
242242 prepared . release = release ;
243243 }
244244
245- if ( scope ) {
246- scope . applyToEvent ( prepared , Math . min ( maxBreadcrumbs , MAX_BREADCRUMBS ) ) ;
247- }
248-
249245 if ( prepared . message ) {
250246 prepared . message = truncate ( prepared . message , MAX_URL_LENGTH ) ;
251247 }
@@ -265,6 +261,12 @@ export abstract class BaseClient<B extends Backend, O extends Options>
265261
266262 prepared . event_id = uuid4 ( ) ;
267263
264+ // This should be the last thing called, since we want that
265+ // {@link Hub.addEventProcessor } gets the finished prepared event.
266+ if ( scope ) {
267+ scope . applyToEvent ( prepared , Math . min ( maxBreadcrumbs , MAX_BREADCRUMBS ) ) ;
268+ }
269+
268270 return prepared ;
269271 }
270272
Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ export function initAndBind<F extends Client, O extends Options>(
2727 const client = new clientClass ( options ) ;
2828 client . install ( ) ;
2929
30+ // This should happen here if any integration uses {@link Hub.addEventProcessor }
31+ // there needs to be a client on the hub already.
32+ getDefaultHub ( ) . bindClient ( client ) ;
33+
3034 let integrations = [ ...defaultIntegrations ] ;
3135 if ( Array . isArray ( options . integrations ) ) {
3236 integrations = [ ...integrations , ...options . integrations ] ;
@@ -40,6 +44,4 @@ export function initAndBind<F extends Client, O extends Options>(
4044 integration . install ( ) ;
4145 } ) ;
4246 }
43-
44- getDefaultHub ( ) . bindClient ( client ) ;
4547}
Original file line number Diff line number Diff line change @@ -8,9 +8,6 @@ export class Scope {
88 /** Flag if notifiying is happening. */
99 protected notifyingListeners : boolean = false ;
1010
11- /** Flag if notifiying is happening. */
12- protected notifyingProcessors : boolean = false ;
13-
1411 /** Callback for client to receive scope changes. */
1512 protected scopeListeners : Array < ( scope : Scope ) => void > = [ ] ;
1613
@@ -61,15 +58,9 @@ export class Scope {
6158 * This will be called after {@link applyToEvent} is finished.
6259 */
6360 protected notifyEventProcessors ( event : SentryEvent ) : void {
64- if ( ! this . notifyingProcessors ) {
65- this . notifyingProcessors = true ;
66- setTimeout ( ( ) => {
67- this . eventProcessors . forEach ( callback => {
68- callback ( event ) ;
69- } ) ;
70- this . notifyingProcessors = false ;
71- } , 0 ) ;
72- }
61+ this . eventProcessors . forEach ( callback => {
62+ callback ( event ) ;
63+ } ) ;
7364 }
7465
7566 /**
Original file line number Diff line number Diff line change @@ -227,8 +227,7 @@ describe('Hub', () => {
227227 } ) ;
228228
229229 test ( 'addEventProcessor' , done => {
230- jest . useFakeTimers ( ) ;
231- expect . assertions ( 1 ) ;
230+ expect . assertions ( 2 ) ;
232231 const event : SentryEvent = {
233232 extra : { b : 3 } ,
234233 } ;
@@ -237,9 +236,14 @@ describe('Hub', () => {
237236 const hub = new Hub ( { a : 'b' } , localScope ) ;
238237 hub . addEventProcessor ( ( ) => ( processedEvent : SentryEvent ) => {
239238 expect ( processedEvent . extra ) . toEqual ( { a : 'b' , b : 3 } ) ;
239+ } ) ;
240+ hub . addEventProcessor ( ( ) => ( processedEvent : SentryEvent ) => {
241+ processedEvent . dist = '1' ;
242+ } ) ;
243+ hub . addEventProcessor ( ( ) => ( processedEvent : SentryEvent ) => {
244+ expect ( processedEvent . dist ) . toEqual ( '1' ) ;
240245 done ( ) ;
241246 } ) ;
242247 localScope . applyToEvent ( event ) ;
243- jest . runAllTimers ( ) ;
244248 } ) ;
245249} ) ;
You can’t perform that action at this time.
0 commit comments