Skip to main content

Returns

Yields a GalteaSpan object with helper methods for setting span data dynamically.

Example

Parameters

string
required
Name of the span.
string
SpanType value: SPAN, GENERATION, EVENT, AGENT, TOOL, CHAIN, RETRIEVER, EVALUATOR, EMBEDDING, GUARDRAIL. See Span Types for details. An unrecognized value emits a UserWarning and is still sent as-is, so values added in newer API versions can be used without upgrading the SDK.
string
Human-readable description of what this operation does. Useful for documentation and debugging. Maximum size: 1MB.
any
Input data for the span. Accepts any value (non-serializable objects are converted to string). Maximum size: 10MB.
any
Metadata for the span. Accepts any value (non-serializable objects are converted to string). Maximum size: 10MB.
dict
Custom OpenTelemetry attributes to add to the span.

GalteaSpan Methods

The yielded GalteaSpan object provides these methods:
method
Update span attributes. All parameters are optional and accept any value (non-serializable objects are converted to string).
method
Set a custom attribute on the span.
method
Manually record an exception on the span.

When to Use

Use start_span() instead of @traced when you need:
  1. Fine-grained control over specific code blocks rather than entire functions
  2. Dynamic attributes that are only known at runtime
  3. Conditional tracing based on runtime conditions
  4. Tracing third-party code that you can’t decorate

Complete Example

Nested Spans

Spans automatically form a parent-child hierarchy when nested:
Like @traced, spans created with start_span() are automatically exported to Galtea API when clear_context() is called.