index.js 5.5 KB

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