-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Introduce
processEvent
hook on Integration
- Loading branch information
Showing
7 changed files
with
125 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { Event, EventHint, EventProcessor } from '@sentry/types'; | ||
import { getGlobalSingleton, isThenable, logger, SyncPromise } from '@sentry/utils'; | ||
|
||
/** | ||
* Returns the global event processors. | ||
*/ | ||
export function getGlobalEventProcessors(): EventProcessor[] { | ||
return getGlobalSingleton<EventProcessor[]>('globalEventProcessors', () => []); | ||
} | ||
|
||
/** | ||
* Add a EventProcessor to be kept globally. | ||
* @param callback EventProcessor to add | ||
*/ | ||
export function addGlobalEventProcessor(callback: EventProcessor): void { | ||
getGlobalEventProcessors().push(callback); | ||
} | ||
|
||
/** | ||
* Process an array of event processors, returning the processed event (or `null` if the event was dropped). | ||
*/ | ||
export function notifyEventProcessors( | ||
processors: EventProcessor[], | ||
event: Event | null, | ||
hint: EventHint, | ||
index: number = 0, | ||
): PromiseLike<Event | null> { | ||
return new SyncPromise<Event | null>((resolve, reject) => { | ||
const processor = processors[index]; | ||
if (event === null || typeof processor !== 'function') { | ||
resolve(event); | ||
} else { | ||
const result = processor({ ...event }, hint) as Event | null; | ||
|
||
__DEBUG_BUILD__ && | ||
processor.id && | ||
result === null && | ||
logger.log(`Event processor "${processor.id}" dropped event`); | ||
|
||
if (isThenable(result)) { | ||
void result | ||
.then(final => notifyEventProcessors(processors, final, hint, index + 1).then(resolve)) | ||
.then(null, reject); | ||
} else { | ||
void notifyEventProcessors(processors, result, hint, index + 1) | ||
.then(resolve) | ||
.then(null, reject); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters