Logging in Next.js Server Actions with correlation
Try calling server actions and watch the logs in the Dev Overlay
// 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' }
)