Skip to main content

What is a Span?

A span in Galtea represents a single operation or function call that occurs during an AI agent’s execution. Spans capture the internal workings of your agent—such as tool calls, retrieval operations, chain orchestrations, and LLM invocations—providing deep visibility into how your agent processes requests. Spans are always linked to a trace, enabling you to understand not just what your agent responded, but how it arrived at that response. Every span must belong to a specific trace. Spans can also be ingested directly from OpenTelemetry spans; see Send OpenTelemetry Traces to Galtea.
This entity was called Trace before SDK 5.0.0. The name galtea.traces now belongs to the Trace, so span code must move to galtea.spans. See Dataset, Trace, and Span Renames.

Why Use Spans?

Debugging

Identify exactly where and why your agent failed or produced unexpected results.

Performance Optimization

Pinpoint slow operations with latency tracking at every step.

Compliance & Auditing

Maintain a complete audit trail of all operations for regulatory requirements.

Cost Analysis

Understand which operations consume the most resources.

Span Hierarchy

Spans support parent-child relationships, allowing you to visualize the complete execution flow of your agent. When a traced function calls another traced function, the hierarchy is automatically captured.
Each span includes:
  • id: Unique identifier for the span
  • parent_trace_id: Reference to the parent span (null for root spans)
  • name: The operation name
  • type: Classification of the operation (SpanType)
  • description: Human-readable description of what the operation does

Span Types

Spans are classified by type to help you understand the nature of each operation and debug issues more effectively.

Retrieval context in RETRIEVER spans

If your product uses RAG (retrieval-augmented generation, where the model reads retrieved documents before answering), the convention for recording what was retrieved is a RETRIEVER span:
  • Put the retrieved data in the span’s output. This is how Galtea reads retrieval context: it is derived from your RETRIEVER spans. It is no longer a stored field on the trace.
  • The output has no required shape. It is stored as-is, so a plain string, a list of chunks, or any other structure all work.
  • One RETRIEVER span per retrieval step is fine. If a trace has several RETRIEVER spans, Galtea joins their outputs in chronological order (by start time).

Best Practices

Choose descriptive names that clearly indicate the operation being traced — e.g., search_documents rather than step_2.
Trace operations that represent logical units of work (tool calls, LLM invocations, retrieval steps), not every single function.
Classify operations correctly (TOOL, GENERATION, RETRIEVER, etc.) to enable better filtering and analysis in the dashboard.
The @traced decorator captures function arguments automatically. Avoid tracing functions that receive very large inputs (e.g., full documents) — pass summaries or IDs instead.

SDK Integration

Tracing Tutorial

Step-by-step guide to instrumenting your agent and collecting spans.

Span Service

Manage and collect spans for your AI agent operations using the SDK.

Span Properties

Trace
required
The trace this span belongs to. Every span must be linked to a trace.
string
required
The name of the traced operation (e.g., function name).
SpanType
The type of operation: SPAN, GENERATION, EVENT, AGENT, TOOL, CHAIN, RETRIEVER, EVALUATOR, EMBEDDING, or GUARDRAIL.
string
A human-readable description of the operation. Can be set manually via start_span(description=...) or automatically from function docstrings using @traced(include_docstring=True). Maximum size: 1MB.
string
The ID of the parent span for hierarchical relationships.
any
The input parameters passed to the operation. Maximum size: 10MB.
any
The result returned by the operation. Maximum size: 10MB.
string
Error message if the operation failed.
float
The execution time of the operation in milliseconds.
string
ISO 8601 timestamp when the operation started.
string
ISO 8601 timestamp when the operation completed.
any
Additional custom metadata about the span. Maximum size: 10MB.

Concepts overview

How Galtea’s concepts connect — diagram + per-entity quick reference.

Tracing Agent Operations

Step-by-step guide to capturing and analyzing agent spans.

Trace

The traces that spans are linked to.