Skip to content

Commit 37c5aa9

Browse files
committed
Add logic switch
1 parent 20a67b0 commit 37c5aa9

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

src/platforms/javascript/guides/nextjs/manual-setup.mdx

+36-4
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,53 @@ module.exports = withSentryConfig(moduleExports);
220220

221221
In that case you can also skip the `sentry-cli` configuration step below.
222222

223-
### Automatically Instrument API Routes And Data Fetching Methods
223+
### Disable Automatic Instrumentation of API Routes And Data Fetching Methods
224224

225225
_(New in version TODO)_
226226

227-
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`.
227+
The SDK will 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 To turn it off, set the `autoInstrumentServerFunctions` to `false`.
228228

229229
```javascript {filename:next.config.js}
230230
const moduleExports = {
231231
sentry: {
232-
autoInstrumentServerFunctions: true,
232+
autoInstrumentServerFunctions: false,
233233
},
234234
};
235235
```
236236

237-
Under the hood, the SDK is using a Webpack loader to wrap all your API route handlers and data fetching methods.
237+
Under the hood, when using this option, the SDK is utilizing a Webpack loader to wrap all your API route handlers and data fetching methods.
238+
239+
In case the automatic instrumentation does not work for your use-case, API routes can also be wrapped manually using the `withSentry` function.
240+
241+
```javascript {filename:pages/api/*}
242+
import { withSentry } from "@sentry/nextjs";
243+
244+
const handler = (req, res) => {
245+
res.status(200).json({ name: "John Doe" });
246+
};
247+
248+
export default withSentry(handler);
249+
```
250+
251+
```typescript {filename:pages/api/*}
252+
import type { NextApiRequest, NextApiResponse } from "next"
253+
import { withSentry } from "@sentry/nextjs";
254+
255+
const handler = (req: NextApiRequest, res: NextApiResponse) => {
256+
res.status(200).json({ name: "John Doe" });
257+
};
258+
259+
export default withSentry(handler);
260+
```
261+
262+
Data Fetching Methods can also be manually wrapped using the following functions:
263+
264+
- `withSentryServerSideGetInitialProps` for `getInitialProps`
265+
- `withSentryGetServerSideProps` for `getServerSideProps`
266+
- `withSentryGetStaticProps` for `getStaticProps`
267+
- `withSentryServerSideErrorGetInitialProps` for `getInitialProps` in [custom Error pages](https://nextjs.org/docs/advanced-features/custom-error-page)
268+
- `withSentryServerSideAppGetInitialProps` for `getInitialProps` in [custom `App` components](https://nextjs.org/docs/advanced-features/custom-app)
269+
- `withSentryServerSideDocumentGetInitialProps` for `getInitialProps` in [custom `Document` components](https://nextjs.org/docs/advanced-features/custom-document)
238270

239271
### Use `hidden-source-map`
240272

0 commit comments

Comments
 (0)