GalileoLogger
This class can be used to upload traces to Galileo. First initialize a new GalileoLogger object with an existing project and log stream.conclude.
add_agent_span
input(str): Input to the node. Expected format: String representation of agent input. Example: “User query to be processed by agent”redacted_input(Optional[str]): Input that removes any sensitive information (redacted input to the node). Same format as input parameter.output(Optional[str]): Output of the node. This can also be set on conclude(). Expected format: String representation of agent output. Example: “Agent completed task with final answer”redacted_output(Optional[str]): Output that removes any sensitive information (redacted output of the node). This can also be set on conclude(). Same format as output parameter.name(Optional[str]): Name of the span. Example: “reasoning_agent”, “planning_agent”, “router_agent”duration_ns(Optional[int]): Duration of the node in nanoseconds.created_at(Optional[datetime]): Timestamp of the span’s creation.metadata(Optional[dict[str, str]]): Metadata associated with this span. Expected format:{"key1": "value1", "key2": "value2"}tags(Optional[list[str]]): Tags associated with this span. Expected format:["tag1", "tag2", "tag3"]agent_type(Optional[AgentType]): Agent type of the span. Expected values: AgentType.CLASSIFIER, AgentType.PLANNER, AgentType.REACT, AgentType.REFLECTION, AgentType.ROUTER, AgentType.SUPERVISOR, AgentType.JUDGE, AgentType.DEFAULTstep_number(Optional[int]): Step number of the span.status_code(Optional[int]): Status code of the span execution (e.g., 200 for success, 500 for error).
LoggedAgentSpan: The created span.
add_control_span
id is used as the canonical Galileo span ID for the
control execution. This is the right place to map an upstream
control-execution identifier such as Agent Control’s
control_execution_id.
Returns
LoggedControlSpan | None: The created span, or None when logging is disabled or span creation is skipped by resilient ingestion error handling.
add_llm_span
-
input(LlmSpanAllowedInputType): Input to the node. Accepted formats: list of Message objects, single Message, plain string, dict, or list of dicts. Example (Messages):[Message(content="Say this is a test", role=MessageRole.user)]Example (string):"Say this is a test"Example (dict):{"content": "Say this is a test", "role": "user"} -
output(LlmSpanAllowedOutputType): Output of the node. Accepted formats: Message object, plain string, or dict. Example (Message):Message(content="The response text", role=MessageRole.assistant)Example (string):"The response text"Example (dict):{"content": "The response text", "role": "assistant"} -
model(Optional[str]): Model used for this span. Example: “gpt-4o”, “claude-4-sonnet” -
redacted_input(Optional[LlmSpanAllowedInputType]): Input that removes any sensitive information (redacted input to the node). Same format as input parameter. -
redacted_output(Optional[LlmSpanAllowedOutputType]): Output that removes any sensitive information (redacted output of the node). Same format as output parameter. -
tools(Optional[list[dict]]): List of available tools passed to LLM on invocation. Expected format for each tool dictionary: -
name(Optional[str]): Name of the span. -
duration_ns(Optional[int]): Duration of the node in nanoseconds. -
created_at(Optional[datetime]): Timestamp of the span’s creation. -
metadata(Optional[dict[str, str]]): Metadata associated with this span. Expected format:{"key1": "value1", "key2": "value2"} -
tags(Optional[list[str]]): Tags associated with this span. Expected format:["tag1", "tag2", "tag3"] -
num_input_tokens(Optional[int]): Number of input tokens. -
num_output_tokens(Optional[int]): Number of output tokens. -
total_tokens(Optional[int]): Total number of tokens. -
temperature(Optional[float]): Temperature used for generation (0.0 to 2.0). -
status_code(Optional[int]): Status code of the node execution. Expected values: 200 (success), 400 (client error), 500 (server error) -
time_to_first_token_ns(Optional[int]): Time until the first token was returned. -
step_number(Optional[int]): Step number of the span.
LlmSpan: The created span.
add_protect_span
payload(Payload): Input to the node. This is the input to the Protectinvokemethod. Expected format: Payload object with input_ and/or output attributes. Example:Payload(input_="User input text", output="Model output text")redacted_payload(Optional[Payload]): Input that removes any sensitive information (redacted input to the node). Same format as payload parameter.response(Optional[Response]): Output of the node. This is the output from the Protectinvokemethod. Expected format: Response object with text, trace_metadata, and status. Example:Response(text="Processed text", status=ExecutionStatus.triggered)redacted_response(Optional[Response]): Output that removes any sensitive information (redacted output of the node). Same format as response parameter.created_at(Optional[datetime]): Timestamp of the span’s creation.metadata(Optional[dict[str, str]]): Metadata associated with this span. Expected format:{"key1": "value1", "key2": "value2"}tags(Optional[list[str]]): Tags associated with this span. Expected format:["tag1", "tag2", "tag3"]status_code(Optional[int]): Status code of the node execution. Expected values: 200 (success), 400 (client error), 500 (server error)step_number(Optional[int]): Step number of the span.
ToolSpan: The created Protect tool span.
add_retriever_span
input(str): Query string passed to the retriever. Example:"What is the capital of France?"output(Union[str, list[str], dict[str, Any], list[dict[str, Any]], Document, list[Document], None]): Documents retrieved by the retriever. Accepted formats: string, list of strings, dict, list of dicts, Document, list of Documents, or None. Example (Documents):[Document(content="Paris is the capital.", metadata={"source": "wiki"})]Example (strings):["Paris is the capital.", "France is in Europe."]Example (dicts):[{"content": "Paris is the capital."}]redacted_input(Optional[str]): Redacted version of the query string (sensitive information removed).redacted_output(Union[str, list[str], dict[str, Any], list[dict[str, Any]], Document, list[Document], None]): Redacted version of the retrieved documents (sensitive information removed). Same accepted formats as output.name(Optional[str]): Name of the span.duration_ns(Optional[int]): Duration of the node in nanoseconds.created_at(Optional[datetime]): Timestamp of the span’s creation.metadata(Optional[dict[str, str]]): Metadata associated with this span.status_code(Optional[int]): Status code of the node execution.step_number(Optional[int]): Step number of the span.
RetrieverSpan: The created span.
add_single_llm_span_trace
-
input(LlmSpanAllowedInputType): Input to the node. Accepted formats: list of Message objects, single Message, plain string, dict, or list of dicts. Example (Messages):[Message(content="Say this is a test", role=MessageRole.user)]Example (string):"Say this is a test"Example (dict):{"content": "Say this is a test", "role": "user"} -
output(LlmSpanAllowedOutputType): Output of the node. Accepted formats: Message object, plain string, or dict. Example (Message):Message(content="The response text", role=MessageRole.assistant)Example (string):"The response text"Example (dict):{"content": "The response text", "role": "assistant"} -
model(Optional[str]): Model used for this span. Example: “gpt-4o”, “claude-4-sonnet” -
redacted_input(Optional[LlmSpanAllowedInputType]): Input that removes any sensitive information (redacted input to the node). Same format as input parameter. -
redacted_output(Optional[LlmSpanAllowedOutputType]): Output that removes any sensitive information (redacted output of the node). Same format as output parameter. -
tools(Optional[List[dict]]): List of available tools passed to LLM on invocation. Expected format for each tool dictionary: -
name(Optional[str]): Name of the span. -
duration_ns(Optional[int]): Duration of the node in nanoseconds. -
created_at(Optional[datetime]): Timestamp of the span’s creation. -
metadata(Optional[dict[str, str]]): Metadata associated with this span. Expected format:{"key1": "value1", "key2": "value2"} -
tags(Optional[list[str]]): Tags associated with this span. Expected format:["tag1", "tag2", "tag3"] -
num_input_tokens(Optional[int]): Number of input tokens. -
num_output_tokens(Optional[int]): Number of output tokens. -
total_tokens(Optional[int]): Total number of tokens. -
temperature(Optional[float]): Temperature used for generation (0.0 to 2.0). -
status_code(Optional[int]): Status code of the node execution. Expected values: 200 (success), 400 (client error), 500 (server error) -
time_to_first_token_ns(Optional[int]): Time until the first token was returned. -
dataset_input(Optional[str]): Input from the associated dataset. -
dataset_output(Optional[str]): Expected output from the associated dataset. -
dataset_metadata(Optional[dict[str, str]]): Metadata from the associated dataset. Expected format:{"key1": "value1", "key2": "value2"} -
span_step_number(Optional[int]): Step number of the span.
LoggedTrace: The created trace.
add_tool_span
input(str): Input to the node. Expected format: String representation of tool input/arguments. Example: “search_query: python best practices”redacted_input(Optional[str]): Input that removes any sensitive information (redacted input to the node). Same format as input parameter.output(Optional[str]): Output of the node. Expected format: String representation of tool result. Example: “Found 10 results for python best practices”redacted_output(Optional[str]): Output that removes any sensitive information (redacted output of the node). Same format as output parameter.name(Optional[str]): Name of the span. Example: “search_tool”, “calculator”, “weather_api”duration_ns(Optional[int]): Duration of the node in nanoseconds.created_at(Optional[datetime]): Timestamp of the span’s creation.metadata(Optional[dict[str, str]]): Metadata associated with this span. Expected format:{"key1": "value1", "key2": "value2"}tags(Optional[list[str]]): Tags associated with this span. Expected format:["tag1", "tag2", "tag3"]status_code(Optional[int]): Status code of the node execution. Expected values: 200 (success), 400 (client error), 500 (server error)tool_call_id(Optional[str]): Tool call ID. Expected format: Unique identifier for the tool call.step_number(Optional[int]): Step number of the span.
ToolSpan: The created span.
add_workflow_span
input(str): Input to the node. Expected format: String representation of workflow input. Example: “Start workflow with user request: analyze data”redacted_input(Optional[str]): Input that removes any sensitive information (redacted input to the node). Same format as input parameter.output(Optional[str]): Output of the node. This can also be set on conclude(). Expected format: String representation of workflow output. Example: “Workflow completed successfully with results”redacted_output(Optional[str]): Output that removes any sensitive information (redacted output of the node). This can also be set on conclude(). Same format as output parameter.name(Optional[str]): Name of the span. Example: “data_analysis_workflow”, “user_onboarding_flow”duration_ns(Optional[int]): Duration of the node in nanoseconds.created_at(Optional[datetime]): Timestamp of the span’s creation.metadata(Optional[dict[str, str]]): Metadata associated with this span. Expected format:{"key1": "value1", "key2": "value2"}tags(Optional[list[str]]): Tags associated with this span. Expected format:["tag1", "tag2", "tag3"]step_number(Optional[int]): Step number of the span.status_code(Optional[int]): Status code of the span execution (e.g., 200 for success, 500 for error).
LoggedWorkflowSpan: The created span.
async_flush
list[LoggedTrace]: The list of uploaded traces.
async_ingest_traces
ingestion_hook to ingest modified traces.
async_start_session
name(Optional[str]:): Name of the session. Only used to set name for new sessions. If not provided, a session name will be generated automatically. Example: “user_session_123”, “customer_support_chat”previous_session_id(Optional[str]): ID of the previous session. Expected format: UUID string format. Example: “12345678-1234-5678-9012-123456789012”external_id(Optional[str]): External ID of the session. If a session in the current project and log stream with this external ID is found, it will be used instead of creating a new one. Expected format: Unique identifier string. Example: “user_session_abc123”, “support_ticket_456”metadata(Optional[dict[str, str]]): User metadata to attach to the session. Example: {“brand_id”: “acme”, “environment”: “production”}
str: The ID of the session (existing or newly created).
conclude
output(Optional[IngestOutputType]): Output of the node. For traces, only str or list[IngestContentBlock] are stored directly; other types (Message, Sequence[Document]) are auto-coerced to JSON strings. For workflow/agent spans, all IngestOutputType variants are accepted as-is.redacted_output(Optional[IngestOutputType]): Output that removes any sensitive information (redacted output of the node).duration_ns(Optional[int]): Duration of the node in nanoseconds.status_code(Optional[int]): Status code of the node execution.conclude_all(bool): If True, all spans will be concluded, including the current span. False by default.
Optional[StepWithChildSpans]: The parent of the current workflow. None if no parent exists.
disable_agent_control
enable_agent_control
flush
on_error(Optional[Callable[[Exception], None]]): Callback invoked when a flush error occurs. When provided the exception is passed to the callback instead of being logged as a warning. The callback itself is protected: if it raises, the exception is logged as a warning. Defaults to None (swallow and log warning).
list[LoggedTrace]: The list of uploaded traces.
get_tracing_headers
GalileoLoggerException: If not in distributed mode or if no trace has been started.
dict[str, str]: Dictionary with the following headers:- X-Galileo-Trace-ID: The root trace ID
- X-Galileo-Parent-ID: The ID of the current parent (trace or span) that downstream spans should attach to
ingest_traces
ingestion_hook to ingest modified traces.
set_session
session_id(str): ID of the session to set.
start_session
name(Optional[str]): Name of the session. If omitted, the server will assign a name. Example: “user_session_123”, “customer_support_chat”previous_session_id(Optional[str]): UUID string of a prior session to link to. Expected format: UUID string format. Example: “12345678-1234-5678-9012-123456789012”external_id(Optional[str]): External identifier to dedupe against existing sessions within the same project/log stream or experiment; if found, that session will be reused instead of creating a new one. Expected format: Unique identifier string. Example: “user_session_abc123”, “support_ticket_456”metadata(Optional[dict[str, str]]): User metadata to attach to the session. Example: {“brand_id”: “acme”, “environment”: “production”}
str: The ID of the session (existing or newly created).
start_trace
input(str | TextOrContentBlocks | dict | list[dict[str, Any]]): Input to the node. Accepted formats: string, dict (auto-converted to JSON string), list of dicts (auto-converted to JSON string), or list of content block objects for multimodal content. Examples -- String:
"User query: What is the weather today?" - Dict:
{"query": "hello", "context": "world"}(auto-converted to JSON string) - List of dicts:
[{"role": "user", "content": "hello"}](auto-converted to JSON string) - Content blocks:
[TextContentBlock(text="Analyze"), DataContentBlock(...)]
- String:
redacted_input(Optional[str | TextOrContentBlocks | dict | list[dict[str, Any]]]): Input that removes any sensitive information (redacted input). Same format as input parameter.name(Optional[str]): Name of the trace. Example: “weather_query_trace”, “customer_support_session”duration_ns(Optional[int]): Duration of the trace in nanoseconds.created_at(Optional[datetime]): Timestamp of the trace’s creation.metadata(Optional[dict[str, MetadataValue]]): Metadata associated with this trace. Expected format:{"key1": "value1", "enabled": True, "count": 42}Accepted value types: str, bool, int, float, None (auto-converted to strings). Note: Nested structures (dict, list) are NOT supported by the API.tags(Optional[list[str]]): Tags associated with this trace. Expected format:["tag1", "tag2", "tag3"]dataset_input(Optional[str]): Input from the associated dataset.dataset_output(Optional[str]): Expected output from the associated dataset.dataset_metadata(Optional[dict[str, MetadataValue]]): Metadata from the associated dataset. Expected format:{"key1": "value1", "enabled": True, "count": 42}Accepted value types: str, bool, int, float, None (auto-converted to strings).external_id(Optional[str]): External ID for this trace to connect to external systems. Expected format: Unique identifier string.
LoggedTrace: The created trace.
terminate
terminate() returns the logger
instance must NOT be reused: in distributed mode the underlying
EventLoopThreadPool is stopped (its worker threads are joined), so
any subsequent call that submits a new task will hang silently. Create
a new GalileoLogger if you need to log again.
The wait for in-flight background tasks is bounded by
DEFAULT_TERMINATE_TIMEOUT_SECONDS. After waiting (whether tasks
completed or the timeout fired) the underlying EventLoopThreadPool
is stopped so its worker threads no longer hold the process open.