eventProcessors.js 1.8 KB

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