@sentry/nextjs
Version:
Official Sentry SDK for Next.js
32 lines (27 loc) • 1.1 kB
JavaScript
import { dsnFromString, logger } from '@sentry/utils';
import { DEBUG_BUILD } from '../common/debug-build.js';
const globalWithInjectedValues = global
;
/**
* Applies the `tunnel` option to the Next.js SDK options based on `withSentryConfig`'s `tunnelRoute` option.
*/
function applyTunnelRouteOption(options) {
const tunnelRouteOption = globalWithInjectedValues.__sentryRewritesTunnelPath__;
if (tunnelRouteOption && options.dsn) {
const dsnComponents = dsnFromString(options.dsn);
if (!dsnComponents) {
return;
}
const sentrySaasDsnMatch = dsnComponents.host.match(/^o(\d+)\.ingest\.sentry\.io$/);
if (sentrySaasDsnMatch) {
const orgId = sentrySaasDsnMatch[1];
const tunnelPath = `${tunnelRouteOption}?o=${orgId}&p=${dsnComponents.projectId}`;
options.tunnel = tunnelPath;
DEBUG_BUILD && logger.info(`Tunneling events to "${tunnelPath}"`);
} else {
DEBUG_BUILD && logger.warn('Provided DSN is not a Sentry SaaS DSN. Will not tunnel events.');
}
}
}
export { applyTunnelRouteOption };
//# sourceMappingURL=tunnelRoute.js.map