Promise<void>. Both honor the timeout — if events are still buffered when the deadline hits, they’re dropped and onError fires. Without a timeout, they wait as long as it takes (unbounded).
What the SDK wires up for you
By default (flushOnExit: true), createBoundaryLogger attaches listeners to runtime lifecycle hooks that are safe to attach silently:
What the SDK does not do
The SDK deliberately does not attach handlers forSIGTERM or SIGINT. Those signals belong to your application’s lifecycle — web servers, database clients, and queue consumers install their own handlers, and a silent SDK listener would either race with yours or keep the process alive past what Ctrl+C should do.
For signal coverage, install your own handler and call shutdown():
flush() vs shutdown()
Safe to call
shutdown() multiple times — every call after the first resolves immediately.
Timeout semantics
- Waits up to 2000ms for in-flight writes to finish.
- Events still queued after the deadline are dropped;
onErrorfires with aShutdownTimeoutError-like diagnostic. - Without a timeout,
shutdown()waits indefinitely — fine for short-lived scripts, not for signal handlers (you’ll block Ctrl+C).
Opting out of the exit hooks
If you own all shutdown pathways yourself and don’t want the SDK attaching anything:flush() or shutdown() explicitly. Good for tightly-controlled runtimes (custom process supervisors, test harnesses).
Recipes by runtime
Long-running Node server
AWS Lambda / Vercel Function
Cloudflare Workers
ctx.waitUntil lets the runtime keep the isolate alive until the flush resolves, without blocking the response.
Next.js App Router route handler
See also
Node
Long-running servers, beforeExit
Cloudflare / Workers / Edge
ctx.waitUntil pattern
Lambda / Vercel Functions
Per-invocation flush
Browser
pagehide + visibilitychange