@sentry/nextjs
Version:
Official Sentry SDK for Next.js
40 lines (37 loc) • 1.63 kB
JavaScript
import { GLOBAL_OBJ, dsnFromString, debug } from '@sentry/core';
import { DEBUG_BUILD } from '../common/debug-build.js';
const globalWithInjectedValues = GLOBAL_OBJ;
function applyTunnelRouteOption(options) {
const tunnelRouteOption = process.env._sentryRewritesTunnelPath || globalWithInjectedValues._sentryRewritesTunnelPath;
if (tunnelRouteOption && options.dsn) {
const dsnComponents = dsnFromString(options.dsn);
if (!dsnComponents) {
return;
}
const tunnelRouteMode = process.env._sentryTunnelRouteMode || globalWithInjectedValues._sentryTunnelRouteMode;
if (tunnelRouteMode === "handler") {
options.tunnel = tunnelRouteOption;
DEBUG_BUILD && debug.log(`Tunneling events to "${tunnelRouteOption}"`);
return;
}
const sentrySaasDsnMatch = dsnComponents.host.match(/^o(\d+)\.ingest(?:\.([a-z]{2}))?\.sentry\.io$/);
if (sentrySaasDsnMatch) {
const orgId = sentrySaasDsnMatch[1];
const regionCode = sentrySaasDsnMatch[2];
let tunnelPath = `${tunnelRouteOption}?o=${orgId}&p=${dsnComponents.projectId}`;
if (regionCode) {
tunnelPath += `&r=${regionCode}`;
}
options.tunnel = tunnelPath;
options.transportOptions = {
...options.transportOptions,
fetchOptions: { credentials: "omit", ...options.transportOptions?.fetchOptions }
};
DEBUG_BUILD && debug.log(`Tunneling events to "${tunnelPath}"`);
} else {
DEBUG_BUILD && debug.warn("Provided DSN is not a Sentry SaaS DSN. Will not tunnel events.");
}
}
}
export { applyTunnelRouteOption };
//# sourceMappingURL=tunnelRoute.js.map