Skip to main content

Returns

This method returns None. Traces are stored in the context and saved later with save_context().

Example

galtea.traces.add_to_context(
    name="external_api_call",
    node_type="TOOL",
    input_data={"endpoint": "/api/data", "params": {"id": 123}},
    output_data={"status": 200, "data": {"result": "success"}},
    latency_ms=150.5
)
You must call start_collection_context() before using this method.

Parameters

name
string
required
The name of the tool or function that was called.
node_type
string
The type of node. Options: TOOL, CHAIN, RETRIEVER, LLM, CUSTOM. See Node Types for details.
input_data
dict
The input data passed to the tool.
output_data
dict
The output data returned by the tool.
error
string
Error message if the tool call failed.
latency_ms
float
The time in milliseconds the tool call took.
metadata
dict
Additional metadata about the trace.
start_time
string
ISO 8601 timestamp when the trace started.
end_time
string
ISO 8601 timestamp when the trace ended.
Use ISO 8601 timestamps with timezone:
from datetime import datetime, timezone

start = datetime.now(timezone.utc).isoformat()
# ... operation ...
end = datetime.now(timezone.utc).isoformat()

galtea.traces.add_to_context(
    name="my_operation",
    start_time=start,
    end_time=end,
)