browserTracingIntegration.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var {
  2. _optionalChain
  3. } = require('@sentry/utils');
  4. Object.defineProperty(exports, '__esModule', { value: true });
  5. const react = require('@sentry/react');
  6. const nextRoutingInstrumentation = require('./routing/nextRoutingInstrumentation.js');
  7. /**
  8. * A custom BrowserTracing integration for Next.js.
  9. *
  10. * @deprecated Use `browserTracingIntegration` instead.
  11. */
  12. // eslint-disable-next-line deprecation/deprecation
  13. class BrowserTracing extends react.BrowserTracing {
  14. // eslint-disable-next-line deprecation/deprecation
  15. constructor(options) {
  16. super({
  17. // eslint-disable-next-line deprecation/deprecation
  18. tracingOrigins:
  19. process.env.NODE_ENV === 'development'
  20. ? [
  21. // Will match any URL that contains "localhost" but not "webpack.hot-update.json" - The webpack dev-server
  22. // has cors and it doesn't like extra headers when it's accessed from a different URL.
  23. // TODO(v8): Ideally we rework our tracePropagationTargets logic so this hack won't be necessary anymore (see issue #9764)
  24. /^(?=.*localhost)(?!.*webpack\.hot-update\.json).*/,
  25. /^\/(?!\/)/,
  26. ]
  27. : // eslint-disable-next-line deprecation/deprecation
  28. [...react.defaultRequestInstrumentationOptions.tracingOrigins, /^(api\/)/],
  29. // eslint-disable-next-line deprecation/deprecation
  30. routingInstrumentation: nextRoutingInstrumentation.nextRouterInstrumentation,
  31. ...options,
  32. });
  33. }
  34. }
  35. /**
  36. * A custom BrowserTracing integration for Next.js.
  37. */
  38. function browserTracingIntegration(
  39. options,
  40. ) {
  41. const browserTracingIntegrationInstance = react.browserTracingIntegration({
  42. // eslint-disable-next-line deprecation/deprecation
  43. tracingOrigins:
  44. process.env.NODE_ENV === 'development'
  45. ? [
  46. // Will match any URL that contains "localhost" but not "webpack.hot-update.json" - The webpack dev-server
  47. // has cors and it doesn't like extra headers when it's accessed from a different URL.
  48. // TODO(v8): Ideally we rework our tracePropagationTargets logic so this hack won't be necessary anymore (see issue #9764)
  49. /^(?=.*localhost)(?!.*webpack\.hot-update\.json).*/,
  50. /^\/(?!\/)/,
  51. ]
  52. : // eslint-disable-next-line deprecation/deprecation
  53. [...react.defaultRequestInstrumentationOptions.tracingOrigins, /^(api\/)/],
  54. ...options,
  55. instrumentNavigation: false,
  56. instrumentPageLoad: false,
  57. });
  58. return {
  59. ...browserTracingIntegrationInstance,
  60. afterAllSetup(client) {
  61. const startPageloadCallback = (startSpanOptions) => {
  62. react.startBrowserTracingPageLoadSpan(client, startSpanOptions);
  63. };
  64. const startNavigationCallback = (startSpanOptions) => {
  65. react.startBrowserTracingNavigationSpan(client, startSpanOptions);
  66. };
  67. // We need to run the navigation span instrumentation before the `afterAllSetup` hook on the normal browser
  68. // tracing integration because we need to ensure the order of execution is as follows:
  69. // Instrumentation to start span on RSC fetch request runs -> Instrumentation to put tracing headers from active span on fetch runs
  70. // If it were the other way around, the RSC fetch request would not receive the tracing headers from the navigation transaction.
  71. // eslint-disable-next-line deprecation/deprecation
  72. nextRoutingInstrumentation.nextRouterInstrumentation(
  73. () => undefined,
  74. false,
  75. _optionalChain([options, 'optionalAccess', _ => _.instrumentNavigation]),
  76. startPageloadCallback,
  77. startNavigationCallback,
  78. );
  79. browserTracingIntegrationInstance.afterAllSetup(client);
  80. // eslint-disable-next-line deprecation/deprecation
  81. nextRoutingInstrumentation.nextRouterInstrumentation(
  82. () => undefined,
  83. _optionalChain([options, 'optionalAccess', _2 => _2.instrumentPageLoad]),
  84. false,
  85. startPageloadCallback,
  86. startNavigationCallback,
  87. );
  88. },
  89. };
  90. }
  91. exports.BrowserTracing = BrowserTracing;
  92. exports.browserTracingIntegration = browserTracingIntegration;
  93. //# sourceMappingURL=browserTracingIntegration.js.map