Skip to main content
Foglamp batches spans in memory and sends them in the background. On a long-running server you never notice this. In serverless environments the process can freeze or stop before a batch is sent.
Anything not flushed before the runtime suspends is lost. The buffer is in-memory on purpose, so it never blocks your model calls.
The collector detects its runtime and picks a flush strategy on its own. You can always override it with 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 every flushIntervalMs (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 reads waitUntil 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 keep waitUntil 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 on process.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.