client.flush() in a finally block instead.
Before you begin
Before you start, make sure you have:- SDK:
@atlanai/sdkinstalled, as in Install atlanai SDK. - Tracing: a working
initcall that exports traces, as in Trace your first agent run. - Runtime: Node 20 or later, or Cloudflare Workers with the
nodejs_compatflag. - Credentials: an API key and workspace ID, passed to
init()where the runtime has no environment variables.
1
Export per span
Set Still call
exportMode: "immediate" to replace the batcher with per-span export. Use it whenever the process lifetime is one request.flush() before returning, because the export itself is asynchronous. ATLAN_DEBUG=true also forces immediate mode, so debug runs surface a rejected export straight away.flush() rejects, or raises in Python, if any export from this client has failed, not only the export it just forced. The failure count never resets, so after one failed export every later flush() rejects. Check client.exportHealth (client.export_health in Python) for the failure count and last error.2
Keep instance alive
Pass Workers have no ambient environment, so
waitUntil so the runtime keeps the instance alive until export finishes instead of freezing it mid-request.- Cloudflare Workers
- Vercel
- CLI or job
ATLAN_* variables are not readable. Pass apiKey, workspaceId, and every other option through init() from the env binding.3
Bundle for Cloudflare Workers
Wrangler gets what it needs from
compatibility_flags = ["nodejs_compat"] with a recent compatibility_date. Skip this step unless you bundle with esbuild directly.The OTLP exporter chain loads lazily, so injecting your own
spanExporter keeps Worker startup clean.4
Verify export
Deploy, trigger one request, then open Atlan Trident and confirm the trace appears for that
service_name. A 200 from your handler does not prove the export completed, because a frozen instance returns successfully while dropping the batch. Check the trace, not the response.If the trace is missing, see init() disables tracing and no traces are exported.Troubleshooting
If traces are missing from short-lived processes, orinit() reports a missing workspace in Workers, see Install and setup errors.
Next steps
- Send and verify traces: confirm ingestion end to end.