-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Add option to automatically tunnel events #6425
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
56a1391
ref(nextjs): Use generic loader to inject global values
7c9b129
feat(nextjs): Add option to automatically tunnel events
655be47
Rename option
bece2cc
Apply review feedback
f381240
"Simplify" with query instead of multi-segment route
b499fef
Simplify isomorphic loader logic
4e8f3aa
Improve comment wording
be36164
Use quotes around key
9b548da
Remove redundant test
a75807c
Add comment explaining objectContaining({})
42a1e0a
Merge branch 'lforst-generalize-prefix-loader' into lforst-next-auto-…
cd281f6
Update log message
5f59f68
Add tests for setting `tunnel` option
b1aae28
Merge remote-tracking branch 'origin/master' into lforst-next-auto-tu…
f371849
Apply suggestions from code review
9f8e1f7
Add comment
5c62c05
Merge remote-tracking branch 'origin/master' into lforst-next-auto-tu…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { dsnFromString, logger } from '@sentry/utils'; | ||
|
||
import { NextjsOptions } from './nextjsOptions'; | ||
|
||
const globalWithInjectedValues = global as typeof global & { | ||
__sentryRewritesTunnelPath__?: string; | ||
}; | ||
|
||
/** | ||
* Applies the `tunnel` option to the Next.js SDK options based on `withSentryConfig`'s `tunnelRoute` option. | ||
*/ | ||
export function applyTunnelRouteOption(options: NextjsOptions): void { | ||
const tunnelRouteOption = globalWithInjectedValues.__sentryRewritesTunnelPath__; | ||
if (tunnelRouteOption && options.dsn) { | ||
const dsnComponents = dsnFromString(options.dsn); | ||
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.'); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { NextjsOptions } from '../../src/utils/nextjsOptions'; | ||
import { applyTunnelRouteOption } from '../../src/utils/tunnelRoute'; | ||
|
||
const globalWithInjectedValues = global as typeof global & { | ||
__sentryRewritesTunnelPath__?: string; | ||
}; | ||
|
||
beforeEach(() => { | ||
globalWithInjectedValues.__sentryRewritesTunnelPath__ = undefined; | ||
}); | ||
|
||
describe('applyTunnelRouteOption()', () => { | ||
it('should correctly apply `tunnelRoute` option when conditions are met', () => { | ||
globalWithInjectedValues.__sentryRewritesTunnelPath__ = '/my-error-monitoring-route'; | ||
const options: any = { | ||
dsn: 'https://[email protected]/3333333', | ||
} as NextjsOptions; | ||
|
||
applyTunnelRouteOption(options); | ||
|
||
expect(options.tunnel).toBe('/my-error-monitoring-route?o=2222222&p=3333333'); | ||
}); | ||
|
||
it('should not apply `tunnelRoute` when DSN is missing', () => { | ||
globalWithInjectedValues.__sentryRewritesTunnelPath__ = '/my-error-monitoring-route'; | ||
const options: any = { | ||
// no dsn | ||
} as NextjsOptions; | ||
|
||
applyTunnelRouteOption(options); | ||
|
||
expect(options.tunnel).toBeUndefined(); | ||
}); | ||
|
||
it("should not apply `tunnelRoute` option when `tunnelRoute` option wasn't injected", () => { | ||
const options: any = { | ||
dsn: 'https://[email protected]/3333333', | ||
} as NextjsOptions; | ||
|
||
applyTunnelRouteOption(options); | ||
|
||
expect(options.tunnel).toBeUndefined(); | ||
}); | ||
|
||
it('should not apply `tunnelRoute` option when DSN is not a SaaS DSN', () => { | ||
globalWithInjectedValues.__sentryRewritesTunnelPath__ = '/my-error-monitoring-route'; | ||
const options: any = { | ||
dsn: 'https://[email protected]/3333333', | ||
} as NextjsOptions; | ||
|
||
applyTunnelRouteOption(options); | ||
|
||
expect(options.tunnel).toBeUndefined(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.