client.flush() in a finally block.
Export per span instead of batching
exportMode: "immediate" replaces the batcher with per-span export. Use it
whenever the process lifetime is one request.
flush() before returning — the export itself is asynchronous.
ATLAN_DEBUG=true forces immediate mode as well, which is why debug runs
surface a rejected export straight away.
Keep the instance alive with waitUntil
waitUntil hands every background flush promise to the platform, so the
runtime keeps the instance alive until export finishes instead of freezing it
mid-request.
after from next/server:
Cloudflare Workers have no ambient environment, so
ATLAN_* variables are
not readable. Pass apiKey, workspaceId, and everything else through
init() from the Worker’s env binding.CLIs and jobs
Node runs a best-effort flush onbeforeExit, but being explicit is reliable:
Bundling for Cloudflare Workers
Wrangler users get what they need fromcompatibility_flags = ["nodejs_compat"]
with a recent compatibility_date.
For a direct esbuild bundle, this is the supported configuration — it matches
the SDK’s own Workers smoke test:
The SDK’s OTLP exporter chain is lazy-loaded, so injecting your own
spanExporter keeps Worker startup clean.
Verify it works
Deploy, trigger one request, then confirm the trace appears in Agent Registry for thatservice_name. A 200 from your handler does not prove the export
completed — a frozen instance returns successfully while dropping the batch.
Check the trace, not the response.
Next steps
Configuration
Export modes, flush tuning, and every option.
Send and verify traces
Confirm ingestion end to end.