For detailed information about span properties, node types, and hierarchy, see the Span concept page.
Setup
There are two primary ways to set up tracing in your agent. Choose the option that fits your needs.a) The @traced Decorator
Add the @traced decorator to any function you want to track. It automatically captures: name, inputs, outputs, timing, errors, and parent-child relationships.
b) The start_span Context Manager
For fine-grained control over specific code blocks, use start_span.
span.update() method lets you add output, metadata, or change the type after execution.
Both
@traced and start_span automatically capture parent-child relationships between operations when they are nested inside each other, giving you a full hierarchical view of your agent’s behavior.Collection
Spans are built locally. To send them to Galtea, you need to associate them with atrace_id. There are two approaches:
a) Automatic Collection
Usetraces.generate() or simulator.simulate() for hands-free span management. These methods automatically:
- Set the span context (with the appropriate setup)
- Execute your agent
- Flush all collected spans to Galtea
- Clean up the context
Agent abstract class and decorate your methods with @traced:
Single-Turn with generate()
When using generate(), the span context is automatically set for the entire duration of the agent’s execution. Just call generate() with your agent and session:
Multi-Turn with simulate()
When using the Conversation Simulator, tracing works out-of-the-box. Decorate your agent methods with @traced and run:
b) Manual Collection
If you’re using Direct Inference (where Galtea calls your endpoint), the
trace_id is sent automatically via the X-Galtea-Inference-Id HTTP header. Read it in your handler and use set_context to collect spans. See Collecting Spans During Direct Inference for the full walkthrough.set_context() and clear_context() to manually manage the span lifecycle:
clear_context(token, flush=True) automatically flushes all pending spans for the trace before clearing. Set flush=False if you want to discard spans without sending them.Remote Agent Tracing
When your agent runs on a remote server (e.g., deployed as a FastAPI service), OpenTelemetry’s thread-local context does not cross the HTTP boundary. The remote server cannot discover thetrace_id to correlate spans.
To solve this, AgentInput includes a trace_id field that is automatically populated during generate() and simulate() calls. Forward this ID to your remote server so it can attach spans to the same trace.
Agent / Client Side
In your agent function, readinput_data.trace_id and send it alongside the request payload:
Remote Server Side
On the remote server, useset_context() and clear_context() with the received trace_id:
The remote server must have the Galtea SDK installed (
pip install galtea) to use set_context() and clear_context().Next Steps
If your system already emits OpenTelemetry traces, see Monitor Real User Traffic via OpenTelemetry for how to export them to Galtea and turn them into production sessions. For the span attribute reference, see How span content maps to Span records.
Span Concept
Node types, hierarchy, and best practices.
Span API Reference
All span service methods.