@@ -12,7 +12,7 @@ export class Scope {
1212 protected scopeListeners : Array < ( scope : Scope ) => void > = [ ] ;
1313
1414 /** Callback list that will be called after {@link applyToEvent}. */
15- protected eventProcessors : Array < ( scope : SentryEvent ) => void > = [ ] ;
15+ protected eventProcessors : Array < ( scope : SentryEvent ) => Promise < void > > = [ ] ;
1616
1717 /** Array of breadcrumbs. */
1818 protected breadcrumbs : Breadcrumb [ ] = [ ] ;
@@ -35,7 +35,9 @@ export class Scope {
3535 }
3636
3737 /** Add new event processor that will be called after {@link applyToEvent}. */
38- public addEventProcessor ( callback : ( scope : SentryEvent ) => void ) : void {
38+ public addEventProcessor (
39+ callback : ( scope : SentryEvent ) => Promise < void > ,
40+ ) : void {
3941 this . eventProcessors . push ( callback ) ;
4042 }
4143
@@ -57,10 +59,11 @@ export class Scope {
5759 /**
5860 * This will be called after {@link applyToEvent} is finished.
5961 */
60- protected notifyEventProcessors ( event : SentryEvent ) : void {
61- this . eventProcessors . forEach ( callback => {
62- callback ( event ) ;
63- } ) ;
62+ protected async notifyEventProcessors ( event : SentryEvent ) : Promise < void > {
63+ return this . eventProcessors . reduce ( async ( prev , callback ) => {
64+ await prev ;
65+ return callback ( event ) ;
66+ } , Promise . resolve ( ) ) ;
6467 }
6568
6669 /**
@@ -164,7 +167,10 @@ export class Scope {
164167 * @param event SentryEvent
165168 * @param maxBreadcrumbs number of max breadcrumbs to merged into event.
166169 */
167- public applyToEvent ( event : SentryEvent , maxBreadcrumbs ?: number ) : void {
170+ public async applyToEvent (
171+ event : SentryEvent ,
172+ maxBreadcrumbs ?: number ,
173+ ) : Promise < void > {
168174 if ( this . extra && Object . keys ( this . extra ) . length ) {
169175 event . extra = { ...this . extra , ...event . extra } ;
170176 }
@@ -189,6 +195,6 @@ export class Scope {
189195 : this . breadcrumbs ;
190196 }
191197
192- this . notifyEventProcessors ( event ) ;
198+ await this . notifyEventProcessors ( event ) ;
193199 }
194200}
0 commit comments