Skip to main content
You are reading the docs of Galtea 5.15. Read this page in the latest version.
The Span Service in the Galtea SDK allows you to collect, manage, and persist spans that capture the internal operations of your AI agents during inference. This Service is exposed by the galtea.spans object.
Remember that we will be using the galtea object. More information here.

Two Approaches to Span Collection

The SDK provides two ways to collect spans:

1. Automatic Collection with with generate()

When using galtea.traces.generate(), span collection is handled automatically:

2. Manual Collection with Context Management

For full control over the span lifecycle, use set_context() and clear_context(): Set context before running traced functions:
Then run your traced functions within this context set/open. Once done, clear the context to flush and detach:
Use galtea.traces.generate() for automatic span collection instead of manual collection.
One process exports collected spans (from @traced, start_span, or traces.generate()) through one client: the most recently created Galtea object. spans.create() and spans.create_batch() are not affected: they always use their own object’s settings. To change the API key, the API URL or the extra headers in a running process such as a notebook, create a new Galtea object. Spans then go out with the new settings, including spans not sent yet. Calling shutdown() on an older object only flushes pending spans; span export stops only when the latest object shuts down. Do not use two Galtea objects with API keys of different organizations in one process: spans of the older object’s traces are sent with the newer key, the API refuses them, and they are lost.

Service Methods

Context Management

Direct API Methods

Span

Understand how spans capture the internal operations of your AI agents.