-
-
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
Changes from 3 commits
4c3e556
be1e9f3
674f58e
42bf179
359baba
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
"typescript.enablePromptUseWorkspaceTsdk": true | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function ({ children }: { children: React.ReactNode }) { | ||
return <>{children}</>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client'; | ||
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. lol @ the fact that the nextjs api uses directives like this |
||
|
||
export default function () { | ||
return <p>I am a client component!</p>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function ({ children }: { children: React.ReactNode }) { | ||
return <>{children}</>; | ||
} |
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>; | ||
} |
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); |
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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { wrapApiHandlerWithSentry } 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 wrapApiHandlerWithSentry(handler, '/api/broken'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { wrapApiHandlerWithSentry } 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 wrapApiHandlerWithSentry(handler, '/api/error'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { wrapApiHandlerWithSentry } from '@sentry/nextjs'; | ||
import { get } from 'http'; | ||
import { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
|
@@ -9,4 +9,4 @@ const handler = async (_req: NextApiRequest, res: NextApiResponse): Promise<void | |
res.status(200).json({}); | ||
}; | ||
|
||
export default withSentry(handler); | ||
export default wrapApiHandlerWithSentry(handler, '/api/http'); | ||
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. shouldn't we be autowrapping these anyway? 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. Actually yes. I removed the wrappers and everything still seems to pass 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { wrapApiHandlerWithSentry } 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 wrapApiHandlerWithSentry(handler, '/api/wrapApiHandlerWithSentry/wrapped/[...pathParts]'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { wrapApiHandlerWithSentry } 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 wrapApiHandlerWithSentry(handler, '/api/wrapApiHandlerWithSentry/wrapped/[animal]'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { withSentry } from '@sentry/nextjs'; | ||
import { wrapApiHandlerWithSentry } 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 wrapApiHandlerWithSentry(handler, '/api/wrapApiHandlerWithSentry/wrapped/noParams'); |
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, | ||
}); |
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 }); | ||
}; |
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 }); | ||
}; |
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 }); | ||
}; |
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.
Can we remove?
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.
Ah yeah. Next.js 13 seems to auto-generate this - I gitignored it.