extensions.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const core = require('@sentry/core');
  3. const utils = require('@sentry/utils');
  4. /**
  5. * @private
  6. */
  7. function _autoloadDatabaseIntegrations() {
  8. const carrier = core.getMainCarrier();
  9. if (!carrier.__SENTRY__) {
  10. return;
  11. }
  12. const packageToIntegrationMapping = {
  13. mongodb() {
  14. const integration = utils.dynamicRequire(module, './node/integrations/mongo')
  15. ;
  16. return new integration.Mongo();
  17. },
  18. mongoose() {
  19. const integration = utils.dynamicRequire(module, './node/integrations/mongo')
  20. ;
  21. return new integration.Mongo();
  22. },
  23. mysql() {
  24. const integration = utils.dynamicRequire(module, './node/integrations/mysql')
  25. ;
  26. return new integration.Mysql();
  27. },
  28. pg() {
  29. const integration = utils.dynamicRequire(module, './node/integrations/postgres')
  30. ;
  31. return new integration.Postgres();
  32. },
  33. };
  34. const mappedPackages = Object.keys(packageToIntegrationMapping)
  35. .filter(moduleName => !!utils.loadModule(moduleName))
  36. .map(pkg => {
  37. try {
  38. return packageToIntegrationMapping[pkg]();
  39. } catch (e) {
  40. return undefined;
  41. }
  42. })
  43. .filter(p => p) ;
  44. if (mappedPackages.length > 0) {
  45. carrier.__SENTRY__.integrations = [...(carrier.__SENTRY__.integrations || []), ...mappedPackages];
  46. }
  47. }
  48. /**
  49. * This patches the global object and injects the Tracing extensions methods
  50. */
  51. function addExtensionMethods() {
  52. core.addTracingExtensions();
  53. // Detect and automatically load specified integrations.
  54. if (utils.isNodeEnv()) {
  55. _autoloadDatabaseIntegrations();
  56. }
  57. }
  58. exports.addExtensionMethods = addExtensionMethods;
  59. //# sourceMappingURL=extensions.js.map