index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { applySdkMetadata, hasTracingEnabled } from '@sentry/core';
  2. import { Integrations as Integrations$1, init as init$1, getCurrentScope, getDefaultIntegrations as getDefaultIntegrations$1 } from '@sentry/react';
  3. export * from '@sentry/react';
  4. import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor.js';
  5. import { getVercelEnv } from '../common/getVercelEnv.js';
  6. import { BrowserTracing, browserTracingIntegration } from './browserTracingIntegration.js';
  7. export { BrowserTracing, browserTracingIntegration } from './browserTracingIntegration.js';
  8. import { rewriteFramesIntegration } from './rewriteFramesIntegration.js';
  9. export { rewriteFramesIntegration } from './rewriteFramesIntegration.js';
  10. import { applyTunnelRouteOption } from './tunnelRoute.js';
  11. export { nextRouterInstrumentation } from './routing/nextRoutingInstrumentation.js';
  12. export { captureUnderscoreErrorException } from '../common/_error.js';
  13. export { withSentryGetStaticProps, wrapGetStaticPropsWithSentry } from '../common/wrapGetStaticPropsWithSentry.js';
  14. export { withSentryServerSideGetInitialProps, wrapGetInitialPropsWithSentry } from '../common/wrapGetInitialPropsWithSentry.js';
  15. export { withSentryServerSideAppGetInitialProps, wrapAppGetInitialPropsWithSentry } from '../common/wrapAppGetInitialPropsWithSentry.js';
  16. export { withSentryServerSideDocumentGetInitialProps, wrapDocumentGetInitialPropsWithSentry } from '../common/wrapDocumentGetInitialPropsWithSentry.js';
  17. export { withSentryServerSideErrorGetInitialProps, wrapErrorGetInitialPropsWithSentry } from '../common/wrapErrorGetInitialPropsWithSentry.js';
  18. export { withSentryGetServerSideProps, wrapGetServerSidePropsWithSentry } from '../common/wrapGetServerSidePropsWithSentry.js';
  19. export { wrapServerComponentWithSentry } from '../common/wrapServerComponentWithSentry.js';
  20. export { wrapRouteHandlerWithSentry } from '../common/wrapRouteHandlerWithSentry.js';
  21. export { wrapApiHandlerWithSentryVercelCrons } from '../common/wrapApiHandlerWithSentryVercelCrons.js';
  22. export { wrapMiddlewareWithSentry } from '../common/wrapMiddlewareWithSentry.js';
  23. export { wrapPageComponentWithSentry } from '../common/wrapPageComponentWithSentry.js';
  24. export { wrapGenerationFunctionWithSentry } from '../common/wrapGenerationFunctionWithSentry.js';
  25. export { withServerActionInstrumentation } from '../common/withServerActionInstrumentation.js';
  26. /** @deprecated Import the integration function directly, e.g. `inboundFiltersIntegration()` instead of `new Integrations.InboundFilter(). */
  27. const Integrations = {
  28. // eslint-disable-next-line deprecation/deprecation
  29. ...Integrations$1,
  30. BrowserTracing,
  31. };
  32. // Treeshakable guard to remove all code related to tracing
  33. /** Inits the Sentry NextJS SDK on the browser with the React SDK. */
  34. function init(options) {
  35. const opts = {
  36. environment: getVercelEnv(true) || process.env.NODE_ENV,
  37. defaultIntegrations: getDefaultIntegrations(options),
  38. ...options,
  39. };
  40. fixBrowserTracingIntegration(opts);
  41. applyTunnelRouteOption(opts);
  42. applySdkMetadata(opts, 'nextjs', ['nextjs', 'react']);
  43. init$1(opts);
  44. const scope = getCurrentScope();
  45. scope.setTag('runtime', 'browser');
  46. const filterTransactions = event =>
  47. event.type === 'transaction' && event.transaction === '/404' ? null : event;
  48. filterTransactions.id = 'NextClient404Filter';
  49. scope.addEventProcessor(filterTransactions);
  50. if (process.env.NODE_ENV === 'development') {
  51. scope.addEventProcessor(devErrorSymbolicationEventProcessor);
  52. }
  53. }
  54. // TODO v8: Remove this again
  55. // We need to handle BrowserTracing passed to `integrations` that comes from `@sentry/tracing`, not `@sentry/nextjs` :(
  56. function fixBrowserTracingIntegration(options) {
  57. const { integrations } = options;
  58. if (!integrations) {
  59. return;
  60. }
  61. if (Array.isArray(integrations)) {
  62. options.integrations = maybeUpdateBrowserTracingIntegration(integrations);
  63. } else {
  64. options.integrations = defaultIntegrations => {
  65. const userFinalIntegrations = integrations(defaultIntegrations);
  66. return maybeUpdateBrowserTracingIntegration(userFinalIntegrations);
  67. };
  68. }
  69. }
  70. function isNewBrowserTracingIntegration(
  71. integration,
  72. ) {
  73. // eslint-disable-next-line deprecation/deprecation
  74. return !!integration.afterAllSetup && !!(integration ).options;
  75. }
  76. function maybeUpdateBrowserTracingIntegration(integrations) {
  77. const browserTracing = integrations.find(integration => integration.name === 'BrowserTracing');
  78. if (!browserTracing) {
  79. return integrations;
  80. }
  81. // If `browserTracingIntegration()` was added, we need to force-convert it to our custom one
  82. if (isNewBrowserTracingIntegration(browserTracing)) {
  83. const { options } = browserTracing;
  84. // eslint-disable-next-line deprecation/deprecation
  85. integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options);
  86. }
  87. // If BrowserTracing was added, but it is not our forked version,
  88. // replace it with our forked version with the same options
  89. // eslint-disable-next-line deprecation/deprecation
  90. if (!(browserTracing instanceof BrowserTracing)) {
  91. // eslint-disable-next-line deprecation/deprecation
  92. const options = (browserTracing ).options;
  93. // This option is overwritten by the custom integration
  94. delete options.routingInstrumentation;
  95. // eslint-disable-next-line deprecation/deprecation
  96. delete options.tracingOrigins;
  97. // eslint-disable-next-line deprecation/deprecation
  98. integrations[integrations.indexOf(browserTracing)] = new BrowserTracing(options);
  99. }
  100. return integrations;
  101. }
  102. function getDefaultIntegrations(options) {
  103. const customDefaultIntegrations = [...getDefaultIntegrations$1(options), rewriteFramesIntegration()];
  104. // This evaluates to true unless __SENTRY_TRACING__ is text-replaced with "false", in which case everything inside
  105. // will get treeshaken away
  106. if (typeof __SENTRY_TRACING__ === 'undefined' || __SENTRY_TRACING__) {
  107. if (hasTracingEnabled(options)) {
  108. customDefaultIntegrations.push(browserTracingIntegration());
  109. }
  110. }
  111. return customDefaultIntegrations;
  112. }
  113. /**
  114. * Just a passthrough in case this is imported from the client.
  115. */
  116. function withSentryConfig(exportedUserNextConfig) {
  117. return exportedUserNextConfig;
  118. }
  119. export { Integrations, init, withSentryConfig };
  120. //# sourceMappingURL=index.js.map