Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
6.9 KiB
Plaintext
1 line
6.9 KiB
Plaintext
{"version":3,"file":"tunnel.js","sources":["../../../../src/config/withSentryConfig/tunnel.ts"],"sourcesContent":["import { _INTERNAL_safeMathRandom } from '@sentry/core';\nimport type { NextConfigObject } from '../types';\n\n/**\n * Generates a random tunnel route path that's less likely to be blocked by ad-blockers\n */\nfunction generateRandomTunnelRoute(): string {\n // Generate a random 8-character alphanumeric string\n const randomString = _INTERNAL_safeMathRandom().toString(36).substring(2, 10);\n return `/${randomString}`;\n}\n\n/**\n * Resolves the tunnel route based on the user's configuration and the environment.\n * @param tunnelRoute - The user-provided tunnel route option\n */\nexport function resolveTunnelRoute(tunnelRoute: string | true): string {\n if (process.env.__SENTRY_TUNNEL_ROUTE__) {\n // Reuse cached value from previous build (server/client)\n return process.env.__SENTRY_TUNNEL_ROUTE__;\n }\n\n const resolvedTunnelRoute = typeof tunnelRoute === 'string' ? tunnelRoute : generateRandomTunnelRoute();\n\n // Cache for subsequent builds (only during build time)\n // Turbopack runs the config twice, so we need a shared context to avoid generating a new tunnel route for each build.\n // env works well here\n // https://linear.app/getsentry/issue/JS-549/adblock-plus-blocking-requests-to-sentry-and-monitoring-tunnel\n if (resolvedTunnelRoute) {\n process.env.__SENTRY_TUNNEL_ROUTE__ = resolvedTunnelRoute;\n }\n\n return resolvedTunnelRoute;\n}\n\n/**\n * Injects rewrite rules into the Next.js config provided by the user to tunnel\n * requests from the `tunnelPath` to Sentry.\n *\n * See https://nextjs.org/docs/api-reference/next.config.js/rewrites.\n */\nexport function setUpTunnelRewriteRules(userNextConfig: NextConfigObject, tunnelPath: string): void {\n const originalRewrites = userNextConfig.rewrites;\n // Allow overriding the tunnel destination for E2E tests via environment variable\n const destinationOverride = process.env._SENTRY_TUNNEL_DESTINATION_OVERRIDE;\n\n // Make sure destinations are statically defined at build time\n const destination = destinationOverride || 'https://o:orgid.ingest.sentry.io/api/:projectid/envelope/?hsts=0';\n const destinationWithRegion =\n destinationOverride || 'https://o:orgid.ingest.:region.sentry.io/api/:projectid/envelope/?hsts=0';\n\n // This function doesn't take any arguments at the time of writing but we future-proof\n // here in case Next.js ever decides to pass some\n userNextConfig.rewrites = async (...args: unknown[]) => {\n const tunnelRouteRewrite = {\n // Matched rewrite routes will look like the following: `[tunnelPath]?o=[orgid]&p=[projectid]`\n // Nextjs will automatically convert `source` into a regex for us\n source: `${tunnelPath}(/?)`,\n has: [\n {\n type: 'query',\n key: 'o', // short for orgId - we keep it short so matching is harder for ad-blockers\n value: '(?<orgid>\\\\d*)',\n },\n {\n type: 'query',\n key: 'p', // short for projectId - we keep it short so matching is harder for ad-blockers\n value: '(?<projectid>\\\\d*)',\n },\n ],\n destination,\n };\n\n const tunnelRouteRewriteWithRegion = {\n // Matched rewrite routes will look like the following: `[tunnelPath]?o=[orgid]&p=[projectid]?r=[region]`\n // Nextjs will automatically convert `source` into a regex for us\n source: `${tunnelPath}(/?)`,\n has: [\n {\n type: 'query',\n key: 'o', // short for orgId - we keep it short so matching is harder for ad-blockers\n value: '(?<orgid>\\\\d*)',\n },\n {\n type: 'query',\n key: 'p', // short for projectId - we keep it short so matching is harder for ad-blockers\n value: '(?<projectid>\\\\d*)',\n },\n {\n type: 'query',\n key: 'r', // short for region - we keep it short so matching is harder for ad-blockers\n value: '(?<region>[a-z]{2})',\n },\n ],\n destination: destinationWithRegion,\n };\n\n // Order of these is important, they get applied first to last.\n const newRewrites = [tunnelRouteRewriteWithRegion, tunnelRouteRewrite];\n\n if (typeof originalRewrites !== 'function') {\n return newRewrites;\n }\n\n // @ts-expect-error Expected 0 arguments but got 1 - this is from the future-proofing mentioned above, so we don't care about it\n const originalRewritesResult = await originalRewrites(...args);\n\n if (Array.isArray(originalRewritesResult)) {\n return [...newRewrites, ...originalRewritesResult];\n } else {\n return {\n ...originalRewritesResult,\n beforeFiles: [...newRewrites, ...(originalRewritesResult.beforeFiles || [])],\n };\n }\n };\n}\n"],"names":[],"mappings":";;AAGA;AACA;AACA;AACA,SAAS,yBAAyB,GAAW;AAC7C;AACA,EAAE,MAAM,YAAA,GAAe,wBAAwB,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC;AAC/E,EAAE,OAAO,CAAC,CAAC,EAAE,YAAY,CAAC,CAAA;AACA;;AAEA;AACA;AACA;AACA;AACA,SAAA,kBAAA,CAAA,WAAA,EAAA;AACA,EAAA,IAAA,OAAA,CAAA,GAAA,CAAA,uBAAA,EAAA;AACA;AACA,IAAA,OAAA,OAAA,CAAA,GAAA,CAAA,uBAAA;AACA,EAAA;;AAEA,EAAA,MAAA,mBAAA,GAAA,OAAA,WAAA,KAAA,QAAA,GAAA,WAAA,GAAA,yBAAA,EAAA;;AAEA;AACA;AACA;AACA;AACA,EAAA,IAAA,mBAAA,EAAA;AACA,IAAA,OAAA,CAAA,GAAA,CAAA,uBAAA,GAAA,mBAAA;AACA,EAAA;;AAEA,EAAA,OAAA,mBAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,uBAAA,CAAA,cAAA,EAAA,UAAA,EAAA;AACA,EAAA,MAAA,gBAAA,GAAA,cAAA,CAAA,QAAA;AACA;AACA,EAAA,MAAA,mBAAA,GAAA,OAAA,CAAA,GAAA,CAAA,mCAAA;;AAEA;AACA,EAAA,MAAA,WAAA,GAAA,mBAAA,IAAA,kEAAA;AACA,EAAA,MAAA,qBAAA;AACA,IAAA,mBAAA,IAAA,0EAAA;;AAEA;AACA;AACA,EAAA,cAAA,CAAA,QAAA,GAAA,OAAA,GAAA,IAAA,KAAA;AACA,IAA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