debug.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { defineIntegration, convertIntegrationFnToClass } from '@sentry/core';
  2. import { consoleSandbox } from '@sentry/utils';
  3. const INTEGRATION_NAME = 'Debug';
  4. const _debugIntegration = ((options = {}) => {
  5. const _options = {
  6. debugger: false,
  7. stringify: false,
  8. ...options,
  9. };
  10. return {
  11. name: INTEGRATION_NAME,
  12. // TODO v8: Remove this
  13. setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
  14. setup(client) {
  15. if (!client.on) {
  16. return;
  17. }
  18. client.on('beforeSendEvent', (event, hint) => {
  19. if (_options.debugger) {
  20. // eslint-disable-next-line no-debugger
  21. debugger;
  22. }
  23. /* eslint-disable no-console */
  24. consoleSandbox(() => {
  25. if (_options.stringify) {
  26. console.log(JSON.stringify(event, null, 2));
  27. if (hint && Object.keys(hint).length) {
  28. console.log(JSON.stringify(hint, null, 2));
  29. }
  30. } else {
  31. console.log(event);
  32. if (hint && Object.keys(hint).length) {
  33. console.log(hint);
  34. }
  35. }
  36. });
  37. /* eslint-enable no-console */
  38. });
  39. },
  40. };
  41. }) ;
  42. const debugIntegration = defineIntegration(_debugIntegration);
  43. /**
  44. * Integration to debug sent Sentry events.
  45. * This integration should not be used in production.
  46. *
  47. * @deprecated Use `debugIntegration()` instead.
  48. */
  49. // eslint-disable-next-line deprecation/deprecation
  50. const Debug = convertIntegrationFnToClass(INTEGRATION_NAME, debugIntegration)
  51. ;
  52. export { Debug, debugIntegration };
  53. //# sourceMappingURL=debug.js.map