Before you begin
Before you start, make sure you have:- SDK: atlanai SDK installed with tracing, as in Install atlanai SDK.
- Tracing:
initconfigured and exporting, as in Trace your first agent run.
1
Create span
start_as_current_span (Python) or startAsCurrentSpan (TypeScript) opens a span, makes it the active parent for anything started inside, and closes it on exit.- Python
- TypeScript
start_span or startSpan. End detached spans explicitly. A span that covers work begun earlier, such as a model call an integration sees only when its first message arrives, takes start_time (Python, epoch nanoseconds, as from time.time_ns()) or startTime (TypeScript, any OpenTelemetry TimeInput).2
Set observation type
Pass 

as_type (Python) or asType (TypeScript) to classify the span. Atlan Trident uses the type to decide how to render the step and which metrics apply.3
Record model usage and cost
Call
update on the llm span that spent the tokens. Record usage and cost there, not on the root.- Python
- TypeScript
cost accepts input, output, and total. Provide total when your provider bills one figure you cannot split.usage keys are agent-sdk.v1 attribute names, so they stay snake_case in both languages: input_tokens, not inputTokens. If a trace shows no token counts, check these key names first.4
Record failure
record_failure (Python) or recordFailure (TypeScript) marks the span as errored and records the exception without re-raising it, so tracing never changes your control flow.- Python
- TypeScript
start_as_current_span and startAsCurrentSpan already record a failure that escapes their block. Call record_failure yourself only on a span you started with start_span or startSpan.5
Verify spans
Call
client.flush() before the script exits. flush() fails when the asynchronous exporter reports a delivery error; inspect client.export_health in Python or client.exportHealth in TypeScript for a sticky status, failure count, and safe error category. The health object does not include an endpoint or token. Do not mark an evaluation complete after a failed flush.Then open the trace in Atlan Trident. Confirm the span tree matches your code, the chat span shows model, token counts, and cost, and a failed span shows the error.If no trace appears, see init() disables tracing and no traces are exported.Troubleshooting
If traces do not appear, see Install and setup errors.Next steps
- Wrap functions with observe: trace functions without restructuring them.