-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(nextjs): Stop sending transactions for requests that 404 #4095
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
lobsterkatie
merged 6 commits into
master
from
kmclb-nextjs-stop-sending-404-transactions
Nov 5, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4a94eb2
add filter for 404 transactions
lobsterkatie a7b492d
add server test
lobsterkatie fd704f8
add client test
lobsterkatie b2872a8
assert on more things in tests
lobsterkatie fa74fae
Merge branch 'master' into kmclb-nextjs-stop-sending-404-transactions
lobsterkatie 25c8260
Merge branch 'master' into kmclb-nextjs-stop-sending-404-transactions
lobsterkatie 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| import { BaseClient } from '@sentry/core'; | ||
| import { getCurrentHub } from '@sentry/hub'; | ||
| import * as SentryReact from '@sentry/react'; | ||
| import { Integrations as TracingIntegrations } from '@sentry/tracing'; | ||
| import { Integration } from '@sentry/types'; | ||
| import { getGlobalObject } from '@sentry/utils'; | ||
| import { getGlobalObject, logger, SentryError } from '@sentry/utils'; | ||
|
|
||
| import { init, Integrations, nextRouterInstrumentation } from '../src/index.client'; | ||
| import { NextjsOptions } from '../src/utils/nextjsOptions'; | ||
|
|
@@ -12,10 +13,12 @@ const { BrowserTracing } = TracingIntegrations; | |
| const global = getGlobalObject(); | ||
|
|
||
| const reactInit = jest.spyOn(SentryReact, 'init'); | ||
| const captureEvent = jest.spyOn(BaseClient.prototype, 'captureEvent'); | ||
| const logError = jest.spyOn(logger, 'error'); | ||
|
|
||
| describe('Client init()', () => { | ||
| afterEach(() => { | ||
| reactInit.mockClear(); | ||
| jest.clearAllMocks(); | ||
| global.__SENTRY__.hub = undefined; | ||
| }); | ||
|
|
||
|
|
@@ -50,6 +53,22 @@ describe('Client init()', () => { | |
| expect(currentScope._tags).toEqual({ runtime: 'browser' }); | ||
| }); | ||
|
|
||
| it('adds 404 transaction filter', () => { | ||
| init({ | ||
| dsn: 'https://[email protected]/12312012', | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
| const hub = getCurrentHub(); | ||
| const sendEvent = jest.spyOn(hub.getClient()!.getTransport!(), 'sendEvent'); | ||
|
|
||
| const transaction = hub.startTransaction({ name: '/404' }); | ||
| transaction.finish(); | ||
|
|
||
| expect(sendEvent).not.toHaveBeenCalled(); | ||
| expect(captureEvent.mock.results[0].value).toBeUndefined(); | ||
| expect(logError).toHaveBeenCalledWith(new SentryError('An event processor returned null, will not send event.')); | ||
| }); | ||
|
|
||
| describe('integrations', () => { | ||
| it('does not add BrowserTracing integration by default if tracesSampleRate is not set', () => { | ||
| init({}); | ||
|
|
||
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 |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| import { BaseClient } from '@sentry/core'; | ||
| import { RewriteFrames } from '@sentry/integrations'; | ||
| import * as SentryNode from '@sentry/node'; | ||
| import { getCurrentHub, NodeClient } from '@sentry/node'; | ||
| import { Integration } from '@sentry/types'; | ||
| import { getGlobalObject } from '@sentry/utils'; | ||
| import { getGlobalObject, logger, SentryError } from '@sentry/utils'; | ||
| import * as domain from 'domain'; | ||
|
|
||
| import { init } from '../src/index.server'; | ||
|
|
@@ -16,10 +17,12 @@ const global = getGlobalObject(); | |
| (global as typeof global & { __rewriteFramesDistDir__: string }).__rewriteFramesDistDir__ = '.next'; | ||
|
|
||
| const nodeInit = jest.spyOn(SentryNode, 'init'); | ||
| const captureEvent = jest.spyOn(BaseClient.prototype, 'captureEvent'); | ||
| const logError = jest.spyOn(logger, 'error'); | ||
|
|
||
| describe('Server init()', () => { | ||
| afterEach(() => { | ||
| nodeInit.mockClear(); | ||
| jest.clearAllMocks(); | ||
| global.__SENTRY__.hub = undefined; | ||
| }); | ||
|
|
||
|
|
@@ -87,6 +90,22 @@ describe('Server init()', () => { | |
| expect(currentScope._tags.vercel).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('adds 404 transaction filter', () => { | ||
| init({ | ||
| dsn: 'https://[email protected]/12312012', | ||
| tracesSampleRate: 1.0, | ||
| }); | ||
| const hub = getCurrentHub(); | ||
| const sendEvent = jest.spyOn(hub.getClient()!.getTransport!(), 'sendEvent'); | ||
|
|
||
| const transaction = hub.startTransaction({ name: '/404' }); | ||
| transaction.finish(); | ||
|
|
||
| expect(sendEvent).not.toHaveBeenCalled(); | ||
| expect(captureEvent.mock.results[0].value).toBeUndefined(); | ||
| expect(logError).toHaveBeenCalledWith(new SentryError('An event processor returned null, will not send event.')); | ||
lobsterkatie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| it("initializes both global hub and domain hub when there's an active domain", () => { | ||
| const globalHub = getCurrentHub(); | ||
| const local = domain.create(); | ||
|
|
||
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.