-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Add browser SDK to app
directory browser bundle
#6812
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
5 commits
Select commit
Hold shift + click to select a range
4c3e556
feat(nextjs): Add browser SDK to `app` directory bundle
lforst be1e9f3
Merge remote-tracking branch 'origin/master' into lforst-app-dir-browser
lforst 674f58e
Add integration tests
lforst 42bf179
Remove unnecessary warppers
lforst 359baba
Add vscode folder to gitignore
lforst 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,6 @@ yarn-error.log* | |
|
||
# vercel | ||
.vercel | ||
|
||
# Generated by Next.js 13 | ||
.vscode |
3 changes: 3 additions & 0 deletions
3
packages/nextjs/test/integration/app/clientcomponent/layout.tsx
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,3 @@ | ||
export default function ({ children }: { children: React.ReactNode }) { | ||
return <>{children}</>; | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/nextjs/test/integration/app/clientcomponent/page.tsx
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,5 @@ | ||
'use client'; | ||
|
||
export default function () { | ||
return <p>I am a client component!</p>; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/nextjs/test/integration/app/servercomponent/layout.tsx
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,3 @@ | ||
export default function ({ children }: { children: React.ReactNode }) { | ||
return <>{children}</>; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/nextjs/test/integration/app/servercomponent/page.tsx
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,3 @@ | ||
export default async function () { | ||
return <p>I am a server component!</p>; | ||
} |
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 @@ | ||
const { withSentryConfig } = require('@sentry/nextjs'); | ||
|
||
// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5 | ||
const moduleExports = { | ||
webpack5: %RUN_WEBPACK_5%, | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
}, | ||
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'], | ||
sentry: { | ||
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts` | ||
// TODO (v8): This can come out in v8, because this option will get a default value | ||
hideSourceMaps: false, | ||
excludeServerRoutes: [ | ||
'/api/excludedEndpoints/excludedWithString', | ||
/\/api\/excludedEndpoints\/excludedWithRegExp/, | ||
], | ||
}, | ||
}; | ||
|
||
const SentryWebpackPluginOptions = { | ||
dryRun: true, | ||
silent: true, | ||
}; | ||
|
||
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions); |
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,29 @@ | ||
const { withSentryConfig } = require('@sentry/nextjs'); | ||
|
||
// NOTE: This will be used by integration tests to distinguish between Webpack 4 and Webpack 5 | ||
const moduleExports = { | ||
webpack5: %RUN_WEBPACK_5%, | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
}, | ||
experimental: { | ||
appDir: Number(process.env.NODE_MAJOR) >= 16, // experimental.appDir requires Node v16.8.0 or later. | ||
}, | ||
pageExtensions: ['jsx', 'js', 'tsx', 'ts', 'page.tsx'], | ||
sentry: { | ||
// Suppress the warning message from `handleSourcemapHidingOptionWarning` in `src/config/webpack.ts` | ||
// TODO (v8): This can come out in v8, because this option will get a default value | ||
hideSourceMaps: false, | ||
excludeServerRoutes: [ | ||
'/api/excludedEndpoints/excludedWithString', | ||
/\/api\/excludedEndpoints\/excludedWithRegExp/, | ||
], | ||
}, | ||
}; | ||
|
||
const SentryWebpackPluginOptions = { | ||
dryRun: true, | ||
silent: true, | ||
}; | ||
|
||
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions); |
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,7 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => { | ||
res.status(500).json({ statusCode: 500, message: 'Something went wrong' }); | ||
}; | ||
|
||
export default withSentry(handler); | ||
export default handler; |
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,7 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const handler = async (_req: NextApiRequest, _res: NextApiResponse): Promise<void> => { | ||
throw new Error('API Error'); | ||
}; | ||
|
||
export default withSentry(handler); | ||
export default handler; |
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
3 changes: 1 addition & 2 deletions
3
...ages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/[...pathParts].ts
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,7 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => { | ||
res.status(200).json({}); | ||
}; | ||
|
||
export default withSentry(handler); | ||
export default handler; |
3 changes: 1 addition & 2 deletions
3
packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/[animal].ts
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,7 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => { | ||
res.status(200).json({}); | ||
}; | ||
|
||
export default withSentry(handler); | ||
export default handler; |
3 changes: 1 addition & 2 deletions
3
packages/nextjs/test/integration/pages/api/wrapApiHandlerWithSentry/wrapped/noParams.ts
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,7 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void> => { | ||
res.status(200).json({}); | ||
}; | ||
|
||
export default withSentry(handler); | ||
export default handler; |
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,7 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
tracesSampleRate: 1, | ||
debug: process.env.SDK_DEBUG, | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/nextjs/test/integration/test/client/appDirTracingPageloadClientcomponent.js
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,23 @@ | ||
const { expectRequestCount, isTransactionRequest, expectTransaction } = require('../utils/client'); | ||
|
||
module.exports = async ({ page, url, requests }) => { | ||
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) { | ||
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later. | ||
return; | ||
} | ||
|
||
const requestPromise = page.waitForRequest(isTransactionRequest); | ||
await page.goto(`${url}/clientcomponent`); | ||
await requestPromise; | ||
|
||
expectTransaction(requests.transactions[0], { | ||
contexts: { | ||
trace: { | ||
op: 'pageload', | ||
}, | ||
}, | ||
transaction: '/clientcomponent', | ||
}); | ||
|
||
await expectRequestCount(requests, { transactions: 1 }); | ||
}; |
23 changes: 23 additions & 0 deletions
23
packages/nextjs/test/integration/test/client/appDirTracingPageloadServercomponent.js
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,23 @@ | ||
const { expectRequestCount, isTransactionRequest, expectTransaction } = require('../utils/client'); | ||
|
||
module.exports = async ({ page, url, requests }) => { | ||
if (Number(process.env.NEXTJS_VERSION) < 13 || Number(process.env.NODE_MAJOR) < 16) { | ||
// Next.js versions < 13 don't support the app directory and the app dir requires Node v16.8.0 or later. | ||
return; | ||
} | ||
|
||
const requestPromise = page.waitForRequest(isTransactionRequest); | ||
await page.goto(`${url}/servercomponent`); | ||
await requestPromise; | ||
|
||
expectTransaction(requests.transactions[0], { | ||
contexts: { | ||
trace: { | ||
op: 'pageload', | ||
}, | ||
}, | ||
transaction: '/servercomponent', | ||
}); | ||
|
||
await expectRequestCount(requests, { transactions: 1 }); | ||
}; |
35 changes: 19 additions & 16 deletions
35
packages/nextjs/test/integration/test/client/sessionCrashed.js
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,24 +1,27 @@ | ||
const { waitForAll } = require('../utils/common'); | ||
const { expectRequestCount, isSessionRequest, expectSession } = require('../utils/client'); | ||
const { expectRequestCount, isSessionRequest, expectSession, extractEnvelopeFromRequest } = require('../utils/client'); | ||
|
||
module.exports = async ({ page, url, requests }) => { | ||
await waitForAll([ | ||
page.goto(`${url}/crashed`), | ||
page.waitForRequest(isSessionRequest), | ||
page.waitForRequest(isSessionRequest), | ||
]); | ||
|
||
expectSession(requests.sessions[0], { | ||
init: true, | ||
status: 'ok', | ||
errors: 0, | ||
const sessionRequestPromise1 = page.waitForRequest(request => { | ||
if (isSessionRequest(request)) { | ||
const { item } = extractEnvelopeFromRequest(request); | ||
return item.init === true && item.status === 'ok' && item.errors === 0; | ||
} else { | ||
return false; | ||
} | ||
}); | ||
|
||
expectSession(requests.sessions[1], { | ||
init: false, | ||
status: 'crashed', | ||
errors: 1, | ||
const sessionRequestPromise2 = page.waitForRequest(request => { | ||
if (isSessionRequest(request)) { | ||
const { item } = extractEnvelopeFromRequest(request); | ||
return item.init === false && item.status === 'crashed' && item.errors === 1; | ||
} else { | ||
return false; | ||
} | ||
}); | ||
|
||
await page.goto(`${url}/crashed`); | ||
await sessionRequestPromise1; | ||
await sessionRequestPromise2; | ||
|
||
await expectRequestCount(requests, { sessions: 2 }); | ||
}; |
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
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.
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.
lol @ the fact that the nextjs api uses directives like this