Returns
Yields aGalteaSpan object with helper methods for setting trace data dynamically.
Example
Parameters
string
required
Name of the trace.
string
TraceType value:
SPAN, GENERATION, EVENT, AGENT, TOOL, CHAIN, RETRIEVER, EVALUATOR, EMBEDDING, GUARDRAIL. See Trace 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 trace. Accepts any value (non-serializable objects are converted to string). Maximum size: 10MB.
any
Metadata for the trace. 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 yieldedGalteaSpan object provides these methods:
method
Update trace 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
Usestart_trace() instead of @trace when you need:
- Fine-grained control over specific code blocks rather than entire functions
- Dynamic attributes that are only known at runtime
- Conditional tracing based on runtime conditions
- Tracing third-party code that you can’t decorate
Complete Example
Nested Traces
Traces automatically form a parent-child hierarchy when nested:Like
@trace, traces created with start_trace() are automatically exported to Galtea API when clear_context() is called.