eventProcessors.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { SyncPromise, logger, isThenable, getGlobalSingleton } from '@sentry/utils';
  2. import { DEBUG_BUILD } from './debug-build.js';
  3. /**
  4. * Returns the global event processors.
  5. * @deprecated Global event processors will be removed in v8.
  6. */
  7. function getGlobalEventProcessors() {
  8. return getGlobalSingleton('globalEventProcessors', () => []);
  9. }
  10. /**
  11. * Add a EventProcessor to be kept globally.
  12. * @deprecated Use `addEventProcessor` instead. Global event processors will be removed in v8.
  13. */
  14. function addGlobalEventProcessor(callback) {
  15. // eslint-disable-next-line deprecation/deprecation
  16. getGlobalEventProcessors().push(callback);
  17. }
  18. /**
  19. * Process an array of event processors, returning the processed event (or `null` if the event was dropped).
  20. */
  21. function notifyEventProcessors(
  22. processors,
  23. event,
  24. hint,
  25. index = 0,
  26. ) {
  27. return new SyncPromise((resolve, reject) => {
  28. const processor = processors[index];
  29. if (event === null || typeof processor !== 'function') {
  30. resolve(event);
  31. } else {
  32. const result = processor({ ...event }, hint) ;
  33. DEBUG_BUILD && processor.id && result === null && logger.log(`Event processor "${processor.id}" dropped event`);
  34. if (isThenable(result)) {
  35. void result
  36. .then(final => notifyEventProcessors(processors, final, hint, index + 1).then(resolve))
  37. .then(null, reject);
  38. } else {
  39. void notifyEventProcessors(processors, result, hint, index + 1)
  40. .then(resolve)
  41. .then(null, reject);
  42. }
  43. }
  44. });
  45. }
  46. export { addGlobalEventProcessor, getGlobalEventProcessors, notifyEventProcessors };
  47. //# sourceMappingURL=eventProcessors.js.map