Returns
Yields aGalteaSpan object with helper methods for setting trace data dynamically.
Example
Parameters
Name of the trace.
TraceType value:
SPAN, GENERATION, EVENT, AGENT, TOOL, CHAIN, RETRIEVER, EVALUATOR, EMBEDDING, GUARDRAIL. See Trace Types for details.Human-readable description of what this operation does. Useful for documentation and debugging. Maximum size: 32KB.
Input data for the trace. Accepts any value (non-serializable objects are converted to string). Maximum size: 128KB.
Metadata for the trace. Accepts any value (non-serializable objects are converted to string). Maximum size: 128KB.
Custom OpenTelemetry attributes to add to the span.
GalteaSpan Methods
The yieldedGalteaSpan object provides these methods:
Update trace attributes. All parameters are optional and accept any value (non-serializable objects are converted to string).
Set a custom attribute on the span.
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.