sdk.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const core = require('@sentry/core');
  3. const utils = require('@sentry/utils');
  4. const async = require('./async.js');
  5. const client = require('./client.js');
  6. const wintercgFetch = require('./integrations/wintercg-fetch.js');
  7. const index = require('./transports/index.js');
  8. const vercel = require('./utils/vercel.js');
  9. const nodeStackParser = utils.createStackParser(utils.nodeStackLineParser());
  10. /** @deprecated Use `getDefaultIntegrations(options)` instead. */
  11. const defaultIntegrations = [
  12. core.inboundFiltersIntegration(),
  13. core.functionToStringIntegration(),
  14. core.linkedErrorsIntegration(),
  15. wintercgFetch.winterCGFetchIntegration(),
  16. ];
  17. /** Get the default integrations for the browser SDK. */
  18. function getDefaultIntegrations(options) {
  19. return [
  20. // eslint-disable-next-line deprecation/deprecation
  21. ...defaultIntegrations,
  22. ...(options.sendDefaultPii ? [core.requestDataIntegration()] : []),
  23. ];
  24. }
  25. /** Inits the Sentry NextJS SDK on the Edge Runtime. */
  26. function init(options = {}) {
  27. async.setAsyncLocalStorageAsyncContextStrategy();
  28. if (options.defaultIntegrations === undefined) {
  29. options.defaultIntegrations = getDefaultIntegrations(options);
  30. }
  31. if (options.dsn === undefined && process.env.SENTRY_DSN) {
  32. options.dsn = process.env.SENTRY_DSN;
  33. }
  34. if (options.tracesSampleRate === undefined && process.env.SENTRY_TRACES_SAMPLE_RATE) {
  35. const tracesSampleRate = parseFloat(process.env.SENTRY_TRACES_SAMPLE_RATE);
  36. if (isFinite(tracesSampleRate)) {
  37. options.tracesSampleRate = tracesSampleRate;
  38. }
  39. }
  40. if (options.release === undefined) {
  41. const detectedRelease = getSentryRelease();
  42. if (detectedRelease !== undefined) {
  43. options.release = detectedRelease;
  44. } else {
  45. // If release is not provided, then we should disable autoSessionTracking
  46. options.autoSessionTracking = false;
  47. }
  48. }
  49. options.environment =
  50. options.environment || process.env.SENTRY_ENVIRONMENT || vercel.getVercelEnv(false) || process.env.NODE_ENV;
  51. if (options.autoSessionTracking === undefined && options.dsn !== undefined) {
  52. options.autoSessionTracking = true;
  53. }
  54. if (options.instrumenter === undefined) {
  55. options.instrumenter = 'sentry';
  56. }
  57. const clientOptions = {
  58. ...options,
  59. stackParser: utils.stackParserFromStackParserOptions(options.stackParser || nodeStackParser),
  60. integrations: core.getIntegrationsToSetup(options),
  61. transport: options.transport || index.makeEdgeTransport,
  62. };
  63. core.initAndBind(client.VercelEdgeClient, clientOptions);
  64. }
  65. /**
  66. * Returns a release dynamically from environment variables.
  67. */
  68. function getSentryRelease(fallback) {
  69. // Always read first as Sentry takes this as precedence
  70. if (process.env.SENTRY_RELEASE) {
  71. return process.env.SENTRY_RELEASE;
  72. }
  73. // This supports the variable that sentry-webpack-plugin injects
  74. if (utils.GLOBAL_OBJ.SENTRY_RELEASE && utils.GLOBAL_OBJ.SENTRY_RELEASE.id) {
  75. return utils.GLOBAL_OBJ.SENTRY_RELEASE.id;
  76. }
  77. return (
  78. // GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
  79. process.env.GITHUB_SHA ||
  80. // Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
  81. process.env.VERCEL_GIT_COMMIT_SHA ||
  82. process.env.VERCEL_GITHUB_COMMIT_SHA ||
  83. process.env.VERCEL_GITLAB_COMMIT_SHA ||
  84. process.env.VERCEL_BITBUCKET_COMMIT_SHA ||
  85. // Zeit (now known as Vercel)
  86. process.env.ZEIT_GITHUB_COMMIT_SHA ||
  87. process.env.ZEIT_GITLAB_COMMIT_SHA ||
  88. process.env.ZEIT_BITBUCKET_COMMIT_SHA ||
  89. fallback
  90. );
  91. }
  92. exports.defaultIntegrations = defaultIntegrations;
  93. exports.getDefaultIntegrations = getDefaultIntegrations;
  94. exports.getSentryRelease = getSentryRelease;
  95. exports.init = init;
  96. //# sourceMappingURL=sdk.js.map