metadata.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { forEachEnvelopeItem } from '@sentry/utils';
  2. import { convertIntegrationFnToClass, defineIntegration } from '../integration.js';
  3. import { stripMetadataFromStackFrames, addMetadataToStackFrames } from '../metadata.js';
  4. const INTEGRATION_NAME = 'ModuleMetadata';
  5. const _moduleMetadataIntegration = (() => {
  6. return {
  7. name: INTEGRATION_NAME,
  8. // TODO v8: Remove this
  9. setupOnce() {}, // eslint-disable-line @typescript-eslint/no-empty-function
  10. setup(client) {
  11. if (typeof client.on !== 'function') {
  12. return;
  13. }
  14. // We need to strip metadata from stack frames before sending them to Sentry since these are client side only.
  15. client.on('beforeEnvelope', envelope => {
  16. forEachEnvelopeItem(envelope, (item, type) => {
  17. if (type === 'event') {
  18. const event = Array.isArray(item) ? (item )[1] : undefined;
  19. if (event) {
  20. stripMetadataFromStackFrames(event);
  21. item[1] = event;
  22. }
  23. }
  24. });
  25. });
  26. },
  27. processEvent(event, _hint, client) {
  28. const stackParser = client.getOptions().stackParser;
  29. addMetadataToStackFrames(stackParser, event);
  30. return event;
  31. },
  32. };
  33. }) ;
  34. const moduleMetadataIntegration = defineIntegration(_moduleMetadataIntegration);
  35. /**
  36. * Adds module metadata to stack frames.
  37. *
  38. * Metadata can be injected by the Sentry bundler plugins using the `_experiments.moduleMetadata` config option.
  39. *
  40. * When this integration is added, the metadata passed to the bundler plugin is added to the stack frames of all events
  41. * under the `module_metadata` property. This can be used to help in tagging or routing of events from different teams
  42. * our sources
  43. *
  44. * @deprecated Use `moduleMetadataIntegration()` instead.
  45. */
  46. // eslint-disable-next-line deprecation/deprecation
  47. const ModuleMetadata = convertIntegrationFnToClass(
  48. INTEGRATION_NAME,
  49. moduleMetadataIntegration,
  50. )
  51. ;
  52. export { ModuleMetadata, moduleMetadataIntegration };
  53. //# sourceMappingURL=metadata.js.map