Skip to main content

Returns

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

Example

Parameters

name
string
required
Name of the trace.
type
string
TraceType value: SPAN, GENERATION, EVENT, AGENT, TOOL, CHAIN, RETRIEVER, EVALUATOR, EMBEDDING, GUARDRAIL. See Trace Types for details.
description
string
Human-readable description of what this operation does. Useful for documentation and debugging. Maximum size: 1MB.
input
any
Input data for the trace. Accepts any value (non-serializable objects are converted to string). Maximum size: 10MB.
metadata
any
Metadata for the trace. Accepts any value (non-serializable objects are converted to string). Maximum size: 10MB.
attributes
dict
Custom OpenTelemetry attributes to add to the span.

GalteaSpan Methods

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

When to Use

Use start_trace() instead of @trace 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 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.