Next.js — Flush and shutdown
Flush queued events immediately withflush(), or stop the flush timer and flush with shutdown() before process exit. Both are async (return a Promise). Note: These methods are server-side only. For client-side flushing, see Recording control.
flush()
Flush all queued events to the server immediately. Returns a Promise. When to use: When you need to ensure events are sent before a response or before the process exits (e.g. in a serverless function or after a critical path).shutdown()
Stop the flush timer and flush remaining events. Call before process exit for graceful shutdown. Returns a Promise. When to use: In cleanup handlers (e.g.process.on('SIGTERM', ...)) so no events are lost when the process exits.
Automatic flushing
By default, the server client automatically flushes events:- When
flushBatchSize(default: 20) events are queued - Every
flushIntervalmilliseconds (default: 10000ms)
createSignalServer options. See Configuration.
See also
- Configuration — flushBatchSize, flushInterval
- Recording control — Client-side flush()
- Server tracking — Server-side patterns
