Anything not flushed before the runtime suspends is lost. The buffer is
in-memory on purpose, so it never blocks your model calls.
fog.flush() or by passing a waitUntil hook.
Flushing works the same on both entry points. The examples below use the v7
foglamp() collector, but a wrap() handle has the same flush() and
shutdown() methods, the same waitUntil option, and the same automatic
detection on AI SDK v4 to v6.Long-running servers (Node, Bun)
Nothing to do. Batches are sent everyflushIntervalMs (default 5 seconds) and
earlier when batch limits are hit. For a clean shutdown, drain the buffer on
exit:
Vercel functions
Nothing to do. Foglamp detects Vercel and readswaitUntil from the runtime’s
request context to keep the function alive until the send completes. No extra
package needed. If detection ever fails, pass it yourself:
Cloudflare Workers
Workers keepwaitUntil on the request ctx, so pass it in:
AWS Lambda
Lambda freezes the process the moment your handler returns, so a background send may never happen. Await the flush before returning. Do not rely onprocess.on("beforeExit"); it won’t fire.
Manual flush anywhere
fog.flush() works in every runtime and resolves when the send completes. It
is safe to call when the collector is disabled (it resolves immediately), so
you can leave it in unconditionally.
.png?fit=max&auto=format&n=1sml0kwCw1BNtiz-&q=85&s=a7c846a133aa3480dc1e03a2da5fec2b)
.png?fit=max&auto=format&n=1sml0kwCw1BNtiz-&q=85&s=6534218552b79980770f11c40aafd6ec)