Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,14 @@ Wrap your Server Actions with `Sentry.withServerActionInstrumentation()`.
```typescript {filename:app/actions.ts}
"use server";
import * as Sentry from "@sentry/nextjs";
import { headers } from "next/headers";

export async function submitForm(formData: FormData) {
return Sentry.withServerActionInstrumentation(
"submitForm", // Action name for Sentry
{
headers: await headers(), // Connect client and server traces
formData, // Attach form data to events
recordResponse: true, // Include response data
},
async () => {
Expand Down
13 changes: 9 additions & 4 deletions docs/platforms/javascript/guides/nextjs/tracing/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ Server Actions are **not** automatically instrumented. Without wrapping, they ap
Use `withServerActionInstrumentation` to:
- Create named spans for each action
- Capture timing and errors
- Connect client and server traces
- Connect client and server traces via `headers`
- Attach form data to Sentry events via `formData`

</SplitSectionText>
<SplitSectionCode>
Expand Down Expand Up @@ -148,9 +149,9 @@ export async function createOrder(formData: FormData) {
<SplitSection>
<SplitSectionText>

### With Headers
### With Headers and Form Data

Pass headers to connect client-side traces with server-side spans. This enables full distributed tracing across the browser-to-server boundary.
Pass `headers` to connect client-side traces with server-side spans for full distributed tracing across the browser-to-server boundary. Pass `formData` to attach submitted form data to Sentry events for easier debugging.

</SplitSectionText>
<SplitSectionCode>
Expand All @@ -164,7 +165,11 @@ import { headers } from "next/headers";
export async function submitForm(formData: FormData) {
return Sentry.withServerActionInstrumentation(
"submitForm",
{ headers: await headers() },
{
headers: await headers(), // Connect client and server traces
formData, // Attach form data to events
recordResponse: true, // Include response data
},
async () => {
// Action logic with full trace context
}
Expand Down