Skip to main content
SDK 0.6.0 atlanai SDK buffers spans in a background batch of 64 spans or five seconds, whichever comes first. Use this guide when your TypeScript process exits or freezes before that batch exports, as in functions, Workers, CLIs, and jobs, because those spans are lost. For a Python script or job, call client.flush() in a finally block instead.

Before you begin

Before you start, make sure you have:
  • SDK: @atlanai/sdk installed, as in Install atlanai SDK.
  • Tracing: a working init call that exports traces, as in Trace your first agent run.
  • Runtime: Node 20 or later, or Cloudflare Workers with the nodejs_compat flag.
  • Credentials: an API key and workspace ID, passed to init() where the runtime has no environment variables.
1

Export per span

Set exportMode: "immediate" to replace the batcher with per-span export. Use it whenever the process lifetime is one request.
Still call 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 waitUntil so the runtime keeps the instance alive until export finishes instead of freezing it mid-request.
Workers have no ambient environment, so 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, or init() reports a missing workspace in Workers, see Install and setup errors.

Next steps

See also