sdk.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const utils = require('@sentry/utils');
  3. const debugBuild = require('./debug-build.js');
  4. const exports$1 = require('./exports.js');
  5. const hub = require('./hub.js');
  6. /** A class object that can instantiate Client objects. */
  7. /**
  8. * Internal function to create a new SDK client instance. The client is
  9. * installed and then bound to the current scope.
  10. *
  11. * @param clientClass The client class to instantiate.
  12. * @param options Options to pass to the client.
  13. */
  14. function initAndBind(
  15. clientClass,
  16. options,
  17. ) {
  18. if (options.debug === true) {
  19. if (debugBuild.DEBUG_BUILD) {
  20. utils.logger.enable();
  21. } else {
  22. // use `console.warn` rather than `logger.warn` since by non-debug bundles have all `logger.x` statements stripped
  23. utils.consoleSandbox(() => {
  24. // eslint-disable-next-line no-console
  25. console.warn('[Sentry] Cannot initialize SDK with `debug` option using a non-debug bundle.');
  26. });
  27. }
  28. }
  29. const scope = exports$1.getCurrentScope();
  30. scope.update(options.initialScope);
  31. const client = new clientClass(options);
  32. setCurrentClient(client);
  33. initializeClient(client);
  34. }
  35. /**
  36. * Make the given client the current client.
  37. */
  38. function setCurrentClient(client) {
  39. // eslint-disable-next-line deprecation/deprecation
  40. const hub$1 = hub.getCurrentHub();
  41. // eslint-disable-next-line deprecation/deprecation
  42. const top = hub$1.getStackTop();
  43. top.client = client;
  44. top.scope.setClient(client);
  45. }
  46. /**
  47. * Initialize the client for the current scope.
  48. * Make sure to call this after `setCurrentClient()`.
  49. */
  50. function initializeClient(client) {
  51. if (client.init) {
  52. client.init();
  53. // TODO v8: Remove this fallback
  54. // eslint-disable-next-line deprecation/deprecation
  55. } else if (client.setupIntegrations) {
  56. // eslint-disable-next-line deprecation/deprecation
  57. client.setupIntegrations();
  58. }
  59. }
  60. exports.initAndBind = initAndBind;
  61. exports.setCurrentClient = setCurrentClient;
  62. //# sourceMappingURL=sdk.js.map