@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
54 lines (47 loc) • 1.53 kB
JavaScript
import { getGlobalSingleton, SyncPromise, logger, isThenable } from '@sentry/utils';
/**
* Returns the global event processors.
*/
function getGlobalEventProcessors() {
return getGlobalSingleton('globalEventProcessors', () => []);
}
/**
* Add a EventProcessor to be kept globally.
* @param callback EventProcessor to add
*/
function addGlobalEventProcessor(callback) {
getGlobalEventProcessors().push(callback);
}
/**
* Process an array of event processors, returning the processed event (or `null` if the event was dropped).
*/
function notifyEventProcessors(
processors,
event,
hint,
index = 0,
) {
return new SyncPromise((resolve, reject) => {
const processor = processors[index];
if (event === null || typeof processor !== 'function') {
resolve(event);
} else {
const result = processor({ ...event }, hint) ;
(typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) &&
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);
}
}
});
}
export { addGlobalEventProcessor, getGlobalEventProcessors, notifyEventProcessors };
//# sourceMappingURL=eventProcessors.js.map