index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const core = require('@sentry/core');
  3. const node = require('@sentry/node');
  4. const utils = require('@sentry/utils');
  5. const debugBuild = require('../common/debug-build.js');
  6. const devErrorSymbolicationEventProcessor = require('../common/devErrorSymbolicationEventProcessor.js');
  7. const getVercelEnv = require('../common/getVercelEnv.js');
  8. const isBuild = require('../common/utils/isBuild.js');
  9. const httpIntegration = require('./httpIntegration.js');
  10. const onUncaughtExceptionIntegration = require('./onUncaughtExceptionIntegration.js');
  11. const rewriteFramesIntegration = require('./rewriteFramesIntegration.js');
  12. const react = require('@sentry/react');
  13. const _error = require('../common/_error.js');
  14. const wrapGetStaticPropsWithSentry = require('../common/wrapGetStaticPropsWithSentry.js');
  15. const wrapGetInitialPropsWithSentry = require('../common/wrapGetInitialPropsWithSentry.js');
  16. const wrapAppGetInitialPropsWithSentry = require('../common/wrapAppGetInitialPropsWithSentry.js');
  17. const wrapDocumentGetInitialPropsWithSentry = require('../common/wrapDocumentGetInitialPropsWithSentry.js');
  18. const wrapErrorGetInitialPropsWithSentry = require('../common/wrapErrorGetInitialPropsWithSentry.js');
  19. const wrapGetServerSidePropsWithSentry = require('../common/wrapGetServerSidePropsWithSentry.js');
  20. const wrapServerComponentWithSentry = require('../common/wrapServerComponentWithSentry.js');
  21. const wrapRouteHandlerWithSentry = require('../common/wrapRouteHandlerWithSentry.js');
  22. const wrapApiHandlerWithSentryVercelCrons = require('../common/wrapApiHandlerWithSentryVercelCrons.js');
  23. const wrapMiddlewareWithSentry = require('../common/wrapMiddlewareWithSentry.js');
  24. const wrapPageComponentWithSentry = require('../common/wrapPageComponentWithSentry.js');
  25. const wrapGenerationFunctionWithSentry = require('../common/wrapGenerationFunctionWithSentry.js');
  26. const withServerActionInstrumentation = require('../common/withServerActionInstrumentation.js');
  27. const wrapApiHandlerWithSentry = require('../common/wrapApiHandlerWithSentry.js');
  28. const Integrations = {
  29. ...node.Integrations,
  30. Http: httpIntegration.Http,
  31. OnUncaughtException: onUncaughtExceptionIntegration.OnUncaughtException,
  32. };
  33. /**
  34. * A passthrough error boundary for the server that doesn't depend on any react. Error boundaries don't catch SSR errors
  35. * so they should simply be a passthrough.
  36. */
  37. const ErrorBoundary = (props) => {
  38. if (!props.children) {
  39. return null;
  40. }
  41. if (typeof props.children === 'function') {
  42. return (props.children )();
  43. }
  44. // since Next.js >= 10 requires React ^16.6.0 we are allowed to return children like this here
  45. return props.children ;
  46. };
  47. /**
  48. * A passthrough error boundary wrapper for the server that doesn't depend on any react. Error boundaries don't catch
  49. * SSR errors so they should simply be a passthrough.
  50. */
  51. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  52. function withErrorBoundary(
  53. WrappedComponent,
  54. ) {
  55. return WrappedComponent ;
  56. }
  57. /**
  58. * Just a passthrough since we're on the server and showing the report dialog on the server doesn't make any sense.
  59. */
  60. function showReportDialog() {
  61. return;
  62. }
  63. // TODO (v8): Remove this
  64. /**
  65. * @deprecated This constant will be removed in the next major update.
  66. */
  67. const IS_BUILD = isBuild.isBuild();
  68. const IS_VERCEL = !!process.env.VERCEL;
  69. /** Inits the Sentry NextJS SDK on node. */
  70. function init(options) {
  71. core.addTracingExtensions();
  72. if (isBuild.isBuild()) {
  73. return;
  74. }
  75. const customDefaultIntegrations = [
  76. ...node.getDefaultIntegrations(options).filter(
  77. integration => !['Http', 'OnUncaughtException'].includes(integration.name),
  78. ),
  79. rewriteFramesIntegration.rewriteFramesIntegration(),
  80. new httpIntegration.Http(),
  81. new onUncaughtExceptionIntegration.OnUncaughtException(),
  82. ];
  83. const opts = {
  84. environment: process.env.SENTRY_ENVIRONMENT || getVercelEnv.getVercelEnv(false) || process.env.NODE_ENV,
  85. defaultIntegrations: customDefaultIntegrations,
  86. ...options,
  87. // Right now we only capture frontend sessions for Next.js
  88. autoSessionTracking: false,
  89. };
  90. if (debugBuild.DEBUG_BUILD && opts.debug) {
  91. utils.logger.enable();
  92. }
  93. debugBuild.DEBUG_BUILD && utils.logger.log('Initializing SDK...');
  94. if (sdkAlreadyInitialized()) {
  95. debugBuild.DEBUG_BUILD && utils.logger.log('SDK already initialized');
  96. return;
  97. }
  98. core.applySdkMetadata(opts, 'nextjs', ['nextjs', 'node']);
  99. node.init(opts);
  100. const filterTransactions = event => {
  101. return event.type === 'transaction' && event.transaction === '/404' ? null : event;
  102. };
  103. filterTransactions.id = 'NextServer404TransactionFilter';
  104. const scope = node.getCurrentScope();
  105. scope.setTag('runtime', 'node');
  106. if (IS_VERCEL) {
  107. scope.setTag('vercel', true);
  108. }
  109. scope.addEventProcessor(filterTransactions);
  110. if (process.env.NODE_ENV === 'development') {
  111. scope.addEventProcessor(devErrorSymbolicationEventProcessor.devErrorSymbolicationEventProcessor);
  112. }
  113. debugBuild.DEBUG_BUILD && utils.logger.log('SDK successfully initialized');
  114. }
  115. function sdkAlreadyInitialized() {
  116. return !!core.getClient();
  117. }
  118. // TODO (v8): Remove this
  119. /**
  120. * @deprecated This constant will be removed in the next major update.
  121. */
  122. const deprecatedIsBuild = () => isBuild.isBuild();
  123. exports.rewriteFramesIntegration = rewriteFramesIntegration.rewriteFramesIntegration;
  124. exports.createReduxEnhancer = react.createReduxEnhancer;
  125. exports.captureUnderscoreErrorException = _error.captureUnderscoreErrorException;
  126. exports.withSentryGetStaticProps = wrapGetStaticPropsWithSentry.withSentryGetStaticProps;
  127. exports.wrapGetStaticPropsWithSentry = wrapGetStaticPropsWithSentry.wrapGetStaticPropsWithSentry;
  128. exports.withSentryServerSideGetInitialProps = wrapGetInitialPropsWithSentry.withSentryServerSideGetInitialProps;
  129. exports.wrapGetInitialPropsWithSentry = wrapGetInitialPropsWithSentry.wrapGetInitialPropsWithSentry;
  130. exports.withSentryServerSideAppGetInitialProps = wrapAppGetInitialPropsWithSentry.withSentryServerSideAppGetInitialProps;
  131. exports.wrapAppGetInitialPropsWithSentry = wrapAppGetInitialPropsWithSentry.wrapAppGetInitialPropsWithSentry;
  132. exports.withSentryServerSideDocumentGetInitialProps = wrapDocumentGetInitialPropsWithSentry.withSentryServerSideDocumentGetInitialProps;
  133. exports.wrapDocumentGetInitialPropsWithSentry = wrapDocumentGetInitialPropsWithSentry.wrapDocumentGetInitialPropsWithSentry;
  134. exports.withSentryServerSideErrorGetInitialProps = wrapErrorGetInitialPropsWithSentry.withSentryServerSideErrorGetInitialProps;
  135. exports.wrapErrorGetInitialPropsWithSentry = wrapErrorGetInitialPropsWithSentry.wrapErrorGetInitialPropsWithSentry;
  136. exports.withSentryGetServerSideProps = wrapGetServerSidePropsWithSentry.withSentryGetServerSideProps;
  137. exports.wrapGetServerSidePropsWithSentry = wrapGetServerSidePropsWithSentry.wrapGetServerSidePropsWithSentry;
  138. exports.wrapServerComponentWithSentry = wrapServerComponentWithSentry.wrapServerComponentWithSentry;
  139. exports.wrapRouteHandlerWithSentry = wrapRouteHandlerWithSentry.wrapRouteHandlerWithSentry;
  140. exports.wrapApiHandlerWithSentryVercelCrons = wrapApiHandlerWithSentryVercelCrons.wrapApiHandlerWithSentryVercelCrons;
  141. exports.wrapMiddlewareWithSentry = wrapMiddlewareWithSentry.wrapMiddlewareWithSentry;
  142. exports.wrapPageComponentWithSentry = wrapPageComponentWithSentry.wrapPageComponentWithSentry;
  143. exports.wrapGenerationFunctionWithSentry = wrapGenerationFunctionWithSentry.wrapGenerationFunctionWithSentry;
  144. exports.withServerActionInstrumentation = withServerActionInstrumentation.withServerActionInstrumentation;
  145. exports.withSentry = wrapApiHandlerWithSentry.withSentry;
  146. exports.withSentryAPI = wrapApiHandlerWithSentry.withSentryAPI;
  147. exports.wrapApiHandlerWithSentry = wrapApiHandlerWithSentry.wrapApiHandlerWithSentry;
  148. exports.ErrorBoundary = ErrorBoundary;
  149. exports.IS_BUILD = IS_BUILD;
  150. exports.Integrations = Integrations;
  151. exports.init = init;
  152. exports.isBuild = deprecatedIsBuild;
  153. exports.showReportDialog = showReportDialog;
  154. exports.withErrorBoundary = withErrorBoundary;
  155. for (const k in node) {
  156. if (k !== 'default' && !exports.hasOwnProperty(k)) exports[k] = node[k];
  157. }
  158. //# sourceMappingURL=index.js.map