Server Actions
Logging in Next.js Server Actions with automatic correlation and timing.
NNode.jsServer
Request Context
Correlation IDs from the current request
Result
Request ID: ea0f9fc1-eafd-4370-aa4a-f40195c749f4
Trace ID: 5f298bab79e25e4086cbbb3e2e19c904
Interactive Demo
Try calling server actions and watch the logs
💡 Click the buttons above and watch the log panel below for real-time action logs
Code Example
How to use vestigAction wrapper for server actions
typescript
// app/actions/example.ts
'use server'
import { vestigAction } from '@vestig/next'
export const submitForm = vestigAction(
async (data: FormData, { log, ctx }) => {
log.info('Processing form submission', {
requestId: ctx.requestId,
})
const name = data.get('name')
const email = data.get('email')
log.debug('Validating input', { name, email })
// Simulate processing
await new Promise((r) => setTimeout(r, 500))
log.info('Form submitted successfully')
return { success: true, id: crypto.randomUUID() }
},
{ namespace: 'actions:submitForm' }
)— Key Features
- ›vestigAction Wrapper — Automatic logging setup for server actions
- ›Correlation Propagation — Request IDs flow from client to server action
- ›Timing Metrics — Automatic duration tracking
- ›Error Handling — Errors are logged automatically with context
- ›Input/Output Logging — Optional logging of action inputs and outputs