-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Add option for auto-generated random tunnel route #16626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,15 @@ export function withSentryConfig<C>(nextConfig?: C, sentryBuildOptions: SentryBu | |
} | ||
} | ||
|
||
/** | ||
* Generates a random tunnel route path that's less likely to be blocked by ad-blockers | ||
*/ | ||
function generateRandomTunnelRoute(): string { | ||
// Generate a random 8-character alphanumeric string | ||
const randomString = Math.random().toString(36).substring(2, 10); | ||
return `/${randomString}`; | ||
} | ||
|
||
// Modify the materialized object form of the user's next config by deleting the `sentry` property and wrapping the | ||
// `webpack` property | ||
function getFinalConfigObject( | ||
|
@@ -93,7 +102,14 @@ function getFinalConfigObject( | |
); | ||
} | ||
} else { | ||
setUpTunnelRewriteRules(incomingUserNextConfigObject, userSentryOptions.tunnelRoute); | ||
const resolvedTunnelRoute = | ||
typeof userSentryOptions.tunnelRoute === 'boolean' | ||
? generateRandomTunnelRoute() | ||
: userSentryOptions.tunnelRoute; | ||
|
||
// Update the global options object to use the resolved value everywhere | ||
userSentryOptions.tunnelRoute = resolvedTunnelRoute; | ||
Comment on lines
+110
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, is this the only way to pass the route around? Not a big fan of overwriting the passed in option but maybe this is bike-shedding. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seemed to be the most KISS variant I could think of here, because we can prevent the case that we have two different values floating around for the route There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I guess fair enough. |
||
setUpTunnelRewriteRules(incomingUserNextConfigObject, resolvedTunnelRoute); | ||
} | ||
} | ||
|
||
|
@@ -363,8 +379,11 @@ function setUpBuildTimeVariables( | |
): void { | ||
const assetPrefix = userNextConfig.assetPrefix || userNextConfig.basePath || ''; | ||
const basePath = userNextConfig.basePath ?? ''; | ||
|
||
const rewritesTunnelPath = | ||
userSentryOptions.tunnelRoute !== undefined && userNextConfig.output !== 'export' | ||
userSentryOptions.tunnelRoute !== undefined && | ||
userNextConfig.output !== 'export' && | ||
typeof userSentryOptions.tunnelRoute === 'string' | ||
? `${basePath}${userSentryOptions.tunnelRoute}` | ||
: undefined; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Purely out of interestet, because I don't have context on how the SDK works in this case - how do we make sure these routes don't show up as endpoints in the data? Is this done by
setUpTunnelRewriteRules
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have an event processor in place that will filter these out. That being said I still need to figure out some details regarding value injection and test this manually