From efd9179253f066f78e47d01345d5d34688401b79 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Sep 2022 12:33:38 +0200 Subject: [PATCH 1/6] Add docs for Next.js SDK option `autoInstrumentServerFunctions` --- .../javascript/guides/nextjs/manual-setup.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/platforms/javascript/guides/nextjs/manual-setup.mdx b/src/platforms/javascript/guides/nextjs/manual-setup.mdx index ac1878172d557a..88cdfa384a39a7 100644 --- a/src/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/src/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -184,6 +184,7 @@ const moduleExports = { // sections below for information on the following options: // - disableServerWebpackPlugin // - disableClientWebpackPlugin + // - autoInstrumentServerFunctions // - hideSourceMaps // - widenClientFileUpload // - transpileClientSDK @@ -242,6 +243,20 @@ module.exports = withSentryConfig(moduleExports); In that case you can also skip the `sentry-cli` configuration step below. +### Automatically Instrument API Routes And Data Fetching Methods + +_(New in version TODO)_ + +The SDK provides an option to automatcally instrument API routes and [Next.js Data Fetching Methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring, removing the need to manually wrap API routes in `withSentry`. + +```javascript {filename:next.config.js} +const moduleExports = { + sentry: { + autoInstrumentServerFunctions: true, + }, +}; +``` + ### Use `hidden-source-map` _(New in version 6.17.1, will default to `true` in 8.0.0 and beyond.)_ From c9ac149e2f435c7fd4bed9b0dd127a60e553b29d Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Sep 2022 13:15:01 +0200 Subject: [PATCH 2/6] Add a lil bit more explanation of what is going on --- src/platforms/javascript/guides/nextjs/manual-setup.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platforms/javascript/guides/nextjs/manual-setup.mdx b/src/platforms/javascript/guides/nextjs/manual-setup.mdx index 88cdfa384a39a7..1d1042c7027fe6 100644 --- a/src/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/src/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -257,6 +257,8 @@ const moduleExports = { }; ``` +Under the hood, the SDK is using a Webpack loader to wrap all your API route handlers and data fetching methods. + ### Use `hidden-source-map` _(New in version 6.17.1, will default to `true` in 8.0.0 and beyond.)_ From d24cae5a05764fe616a23b3847b046eaf285ce7b Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Sep 2022 13:47:32 +0200 Subject: [PATCH 3/6] Improve description --- .../javascript/guides/nextjs/manual-setup.mdx | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/platforms/javascript/guides/nextjs/manual-setup.mdx b/src/platforms/javascript/guides/nextjs/manual-setup.mdx index 1d1042c7027fe6..8e7f871a9c6be1 100644 --- a/src/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/src/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -247,7 +247,7 @@ In that case you can also skip the `sentry-cli` configuration step below. _(New in version TODO)_ -The SDK provides an option to automatcally instrument API routes and [Next.js Data Fetching Methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring, removing the need to manually wrap API routes in `withSentry`. +The SDK provides an option to automatcally instrument API routes and serverside [Next.js Data Fetching Methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring, removing the need to manually wrap API routes in `withSentry`. ```javascript {filename:next.config.js} const moduleExports = { @@ -259,6 +259,38 @@ const moduleExports = { Under the hood, the SDK is using a Webpack loader to wrap all your API route handlers and data fetching methods. +In case the automatic instrumentation does not work for your use-case, API routes can also be wrapped manually using the `withSentry` function. + +```javascript {filename:pages/api/*} +import { withSentry } from "@sentry/nextjs"; + +const handler = (req, res) => { + res.status(200).json({ name: "John Doe" }); +}; + +export default withSentry(handler); +``` + +```typescript {filename:pages/api/*} +import type { NextApiRequest, NextApiResponse } from "next" +import { withSentry } from "@sentry/nextjs"; + +const handler = (req: NextApiRequest, res: NextApiResponse) => { + res.status(200).json({ name: "John Doe" }); +}; + +export default withSentry(handler); +``` + +Data Fetching Methods can also be manually wrapped using the following functions: + +- `withSentryServerSideGetInitialProps` for `getInitialProps` +- `withSentryGetServerSideProps` for `getServerSideProps` +- `withSentryGetStaticProps` for `getStaticProps` +- `withSentryServerSideErrorGetInitialProps` for `getInitialProps` in [custom Error pages](https://nextjs.org/docs/advanced-features/custom-error-page) +- `withSentryServerSideAppGetInitialProps` for `getInitialProps` in [custom `App` components](https://nextjs.org/docs/advanced-features/custom-app) +- `withSentryServerSideDocumentGetInitialProps` for `getInitialProps` in [custom `Document` components](https://nextjs.org/docs/advanced-features/custom-document) + ### Use `hidden-source-map` _(New in version 6.17.1, will default to `true` in 8.0.0 and beyond.)_ From 53cec08ef88c65e3ee109295974765ce34808ddd Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Sep 2022 13:49:45 +0200 Subject: [PATCH 4/6] Typos --- src/platforms/javascript/guides/nextjs/manual-setup.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/javascript/guides/nextjs/manual-setup.mdx b/src/platforms/javascript/guides/nextjs/manual-setup.mdx index 8e7f871a9c6be1..98c8a95dd53d67 100644 --- a/src/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/src/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -247,7 +247,7 @@ In that case you can also skip the `sentry-cli` configuration step below. _(New in version TODO)_ -The SDK provides an option to automatcally instrument API routes and serverside [Next.js Data Fetching Methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring, removing the need to manually wrap API routes in `withSentry`. +The SDK provides an option to automatically instrument API routes and serverside [Next.js Data Fetching Methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring, removing the need to manually wrap API routes in `withSentry`. ```javascript {filename:next.config.js} const moduleExports = { @@ -259,7 +259,7 @@ const moduleExports = { Under the hood, the SDK is using a Webpack loader to wrap all your API route handlers and data fetching methods. -In case the automatic instrumentation does not work for your use-case, API routes can also be wrapped manually using the `withSentry` function. +In case the automatic instrumentation does not work for your use case, API routes can also be wrapped manually using the `withSentry` function. ```javascript {filename:pages/api/*} import { withSentry } from "@sentry/nextjs"; From 29dc042d5d9688c2eb5c32a94eed7b6c10cea9b2 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 22 Sep 2022 17:13:38 +0200 Subject: [PATCH 5/6] Apply suggestions Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com> --- src/platforms/javascript/guides/nextjs/manual-setup.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platforms/javascript/guides/nextjs/manual-setup.mdx b/src/platforms/javascript/guides/nextjs/manual-setup.mdx index 98c8a95dd53d67..54e491c2523b0f 100644 --- a/src/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/src/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -243,11 +243,11 @@ module.exports = withSentryConfig(moduleExports); In that case you can also skip the `sentry-cli` configuration step below. -### Automatically Instrument API Routes And Data Fetching Methods +### Automatically Instrument API Routes and Data Fetching Methods _(New in version TODO)_ -The SDK provides an option to automatically instrument API routes and serverside [Next.js Data Fetching Methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring, removing the need to manually wrap API routes in `withSentry`. +The SDK provides an option to automatically instrument API routes and server-side [Next.js data fetching methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring, removing the need to manually wrap API routes in `withSentry`: ```javascript {filename:next.config.js} const moduleExports = { @@ -259,7 +259,7 @@ const moduleExports = { Under the hood, the SDK is using a Webpack loader to wrap all your API route handlers and data fetching methods. -In case the automatic instrumentation does not work for your use case, API routes can also be wrapped manually using the `withSentry` function. +If the automatic instrumentation doesn't work for your use case, API routes can also be wrapped manually using the `withSentry` function: ```javascript {filename:pages/api/*} import { withSentry } from "@sentry/nextjs"; @@ -282,7 +282,7 @@ const handler = (req: NextApiRequest, res: NextApiResponse) => { export default withSentry(handler); ``` -Data Fetching Methods can also be manually wrapped using the following functions: +Data fetching methods can also be manually wrapped using the following functions: - `withSentryServerSideGetInitialProps` for `getInitialProps` - `withSentryGetServerSideProps` for `getServerSideProps` From b3fb2ea9a96353303e5bd2c681aa70cc61f88ca2 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Wed, 28 Sep 2022 12:15:05 +0200 Subject: [PATCH 6/6] Add version --- src/platforms/javascript/guides/nextjs/manual-setup.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/javascript/guides/nextjs/manual-setup.mdx b/src/platforms/javascript/guides/nextjs/manual-setup.mdx index 54e491c2523b0f..a070c49b6c1c42 100644 --- a/src/platforms/javascript/guides/nextjs/manual-setup.mdx +++ b/src/platforms/javascript/guides/nextjs/manual-setup.mdx @@ -245,7 +245,7 @@ In that case you can also skip the `sentry-cli` configuration step below. ### Automatically Instrument API Routes and Data Fetching Methods -_(New in version TODO)_ +_(New in version 7.14.0)_ The SDK provides an option to automatically instrument API routes and server-side [Next.js data fetching methods](https://nextjs.org/docs/basic-features/data-fetching/overview) with error and performance monitoring, removing the need to manually wrap API routes in `withSentry`: