Skip to content

Commit 4fa04d7

Browse files
docs(js): move API-related content from Manual Setup to APIs page (#13327)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Added the APIs mentioned from our Next.js manual setup QS guide to the APIs page. Removed content from Next.js manual setup QS guide we no longer need there (and have documented elsewhere). Closes: #13289 ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 2b3040f commit 4fa04d7

File tree

3 files changed

+160
-165
lines changed

3 files changed

+160
-165
lines changed

docs/platforms/javascript/common/apis.mdx

Lines changed: 140 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ Messages show up as issues on your issue stream, with the message as the issue n
330330
You cannot search these, but they are viewable on the issue page - if you
331331
need to be able to filter for certain data, use [tags](./#setTag) instead.
332332

333-
There are no restrictions on context name. In the context object, all keys are allowed except for `type`, which is used internally.
333+
There are no restrictions on context name. In the context object, all keys are allowed except for `type`, which is used internally.
334334

335335
By default, Sentry SDKs normalize nested structured context data up to three levels deep.
336336
Any data beyond this depth will be trimmed and marked using its type instead.
@@ -341,13 +341,14 @@ Learn more about conventions for common contexts in the [contexts interface deve
341341
<Expandable title='Example'>
342342
Context data is structured and can contain any data you want:
343343

344-
```javascript
345-
Sentry.setContext("character", {
346-
name: "Mighty Fighter",
347-
age: 19,
348-
attack_type: "melee",
349-
});
350-
```
344+
```javascript
345+
Sentry.setContext("character", {
346+
name: "Mighty Fighter",
347+
age: 19,
348+
attack_type: "melee",
349+
});
350+
```
351+
351352
</Expandable>
352353

353354
</SdkApi>
@@ -426,7 +427,6 @@ Learn more about conventions for common contexts in the [contexts interface deve
426427

427428
</Expandable>
428429

429-
430430
<PlatformCategorySection supported={["server"]}>
431431
<Expandable title="Setting The User For the Current Request ">
432432
<PlatformSection notSupported={['javascript.bun', 'javascript.cloudflare', 'javascript.deno', 'javascript.react-router', 'javascript.aws-lambda', 'javascript.azure-functions', 'javascript.gcp-functions']}>
@@ -1077,3 +1077,134 @@ parameters={[
10771077
Wraps a callback with a cron monitor check in. The check in will be sent to Sentry when the callback finishes.
10781078
</SdkApi>
10791079
</PlatformCategorySection>
1080+
1081+
<PlatformSection supported={["javascript.nextjs"]}>
1082+
## Server Actions
1083+
1084+
<SdkApi
1085+
name="withServerActionInstrumentation"
1086+
signature={`function withServerActionInstrumentation(
1087+
serverActionName: string,
1088+
options?: Options,
1089+
callback: A
1090+
): Promise<ReturnType<A>>`}
1091+
>
1092+
To instrument Next.js Server Actions, wrap their content in `withServerActionInstrumentation`, along with a name to describe your server action.
1093+
You can optionally pass form data and headers to record them, and configure the wrapper to record the Server Action responses.
1094+
1095+
<Expandable title="Examples">
1096+
```tsx
1097+
import * as Sentry from "@sentry/nextjs";
1098+
import { headers } from "next/headers";
1099+
1100+
export default function ServerComponent() {
1101+
async function myServerAction(formData: FormData) {
1102+
"use server";
1103+
return await Sentry.withServerActionInstrumentation(
1104+
"myServerAction", // The name you want to associate this Server Action with in Sentry
1105+
{
1106+
formData, // Optionally pass in the form data
1107+
headers: await headers(), // Optionally pass in headers
1108+
recordResponse: true, // Optionally record the server action response
1109+
},
1110+
async () => {
1111+
// ... Your Server Action code
1112+
1113+
return { name: "John Doe" };
1114+
}
1115+
);
1116+
}
1117+
1118+
return (
1119+
<form action={myServerAction}>
1120+
<input type="text" name="some-input-value" />
1121+
<button type="submit">Run Action</button>
1122+
</form>
1123+
);
1124+
}
1125+
```
1126+
1127+
</Expandable>
1128+
</SdkApi>
1129+
1130+
## Route and Data Fetching Instrumentation
1131+
1132+
<SdkApi
1133+
name="wrapApiHandlerWithSentry"
1134+
signature={`function wrapApiHandlerWithSentry(
1135+
apiHandler: NextApiHandler,
1136+
parameterizedRoute: string
1137+
): NextApiHandler`}
1138+
>
1139+
Instrument the provided API route handler with Sentry for error and
1140+
performance monitoring. This function wraps the handler exported from the
1141+
user's API page route file (which may or may not already be wrapped with
1142+
`withSentry`).
1143+
</SdkApi>
1144+
1145+
<SdkApi
1146+
name="wrapGetInitialPropsWithSentry "
1147+
signature={`function wrapGetInitialPropsWithSentry(
1148+
origGetInitialProps: GetInitialProps
1149+
): GetInitialProps`}
1150+
>
1151+
Instrument a `getInitialProps` function with Sentry error and performance
1152+
monitoring by creating and returning a wrapped version of the function.
1153+
</SdkApi>
1154+
1155+
<SdkApi
1156+
name="wrapGetServerSidePropsWithSentry "
1157+
signature={`function wrapGetServerSidePropsWithSentry(
1158+
origGetInitialProps: GetInitialProps,
1159+
parameterizedRoute: string
1160+
): GetServerSideProps`}
1161+
>
1162+
Instrument a `getServerSideProps` function with Sentry error and performance
1163+
monitoring by creating and returning a wrapped version of the function.
1164+
</SdkApi>
1165+
1166+
<SdkApi
1167+
name="wrapGetStaticPropsWithSentry "
1168+
signature={`function wrapGetStaticPropsWithSentry(
1169+
origGetStaticPropsa: GetStaticProps<Props>,
1170+
_parameterizedRoute: string
1171+
): GetStaticProps<Props>`}
1172+
>
1173+
Instrument a `getStaticProps` function with Sentry error and performance
1174+
monitoring by creating and returning a wrapped version of the function.
1175+
</SdkApi>
1176+
1177+
<SdkApi
1178+
name="wrapErrorGetInitialPropsWithSentry "
1179+
signature={`function wrapErrorGetInitialPropsWithSentry(
1180+
origErrorGetInitialProps: ErrorGetInitialProps
1181+
): ErrorGetInitialProps`}
1182+
>
1183+
Instrument a `getInitialProps` function in a custom error page (`_error.js`)
1184+
with Sentry error and performance monitoring by creating and returning a
1185+
wrapped version of the function.
1186+
</SdkApi>
1187+
1188+
<SdkApi
1189+
name="wrapAppGetInitialPropsWithSentry "
1190+
signature={`function wrapAppGetInitialPropsWithSentry(
1191+
origAppGetInitialProps: AppGetInitialProps
1192+
): AppGetInitialProps`}
1193+
>
1194+
Instrument a `getInitialProps` function in a custom app (`_app.js`) with
1195+
Sentry error and performance monitoring by creating and returning a wrapped
1196+
version of the function.
1197+
</SdkApi>
1198+
1199+
<SdkApi
1200+
name="wrapDocumentGetInitialPropsWithSentry "
1201+
signature={`function wrapDocumentGetInitialPropsWithSentry(
1202+
origDocumentGetInitialProps: DocumentGetInitialProps
1203+
): DocumentGetInitialProps`}
1204+
>
1205+
Instrument a `getInitialProps` function in a custom document (`_document.js`)
1206+
with Sentry error and performance monitoring by creating and returning a
1207+
wrapped version of the function.
1208+
</SdkApi>
1209+
1210+
</PlatformSection>

docs/platforms/javascript/guides/nextjs/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ At this point, you should have integrated Sentry into your Next.js application a
7171
Now's a good time to customize your setup and look into more advanced topics.
7272
Our next recommended steps for you are:
7373

74+
- Learn about [instrumenting Next.js server actions](/platforms/javascript/guides/nextjs/apis/#server-actions)
7475
- Learn how to [manually capture errors](/platforms/javascript/guides/nextjs/usage/)
7576
- Continue to [customize your configuration](/platforms/javascript/guides/nextjs/configuration/)
7677
- Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts

0 commit comments

Comments
 (0)