tunnelRoute.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import { dsnFromString, logger } from '@sentry/utils';
  2. import { DEBUG_BUILD } from '../common/debug-build.js';
  3. const globalWithInjectedValues = global
  4. ;
  5. /**
  6. * Applies the `tunnel` option to the Next.js SDK options based on `withSentryConfig`'s `tunnelRoute` option.
  7. */
  8. function applyTunnelRouteOption(options) {
  9. const tunnelRouteOption = globalWithInjectedValues.__sentryRewritesTunnelPath__;
  10. if (tunnelRouteOption && options.dsn) {
  11. const dsnComponents = dsnFromString(options.dsn);
  12. if (!dsnComponents) {
  13. return;
  14. }
  15. const sentrySaasDsnMatch = dsnComponents.host.match(/^o(\d+)\.ingest\.sentry\.io$/);
  16. if (sentrySaasDsnMatch) {
  17. const orgId = sentrySaasDsnMatch[1];
  18. const tunnelPath = `${tunnelRouteOption}?o=${orgId}&p=${dsnComponents.projectId}`;
  19. options.tunnel = tunnelPath;
  20. DEBUG_BUILD && logger.info(`Tunneling events to "${tunnelPath}"`);
  21. } else {
  22. DEBUG_BUILD && logger.warn('Provided DSN is not a Sentry SaaS DSN. Will not tunnel events.');
  23. }
  24. }
  25. }
  26. export { applyTunnelRouteOption };
  27. //# sourceMappingURL=tunnelRoute.js.map