Skip to main content

GalileoLogger

This class can be used to upload traces to Galileo. First initialize a new GalileoLogger object with an existing project and log stream.
Next, we can add traces. Let’s add a simple trace with just one span (llm call) in it, and log it to Galileo using conclude.
Now we have our first trace fully created and logged. Why don’t we log one more trace. This time lets include a RAG step as well. And let’s add some more complex inputs/outputs using some of our helper classes.

add_agent_span

Add an agent type span to the current parent. Arguments
  • 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.DEFAULT
  • 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).
Returns
  • LoggedAgentSpan: The created span.

add_control_span

Add a control span to the current parent. Control spans are leaf spans representing a single Agent Control evaluation result attached to the active Galileo parent. When provided, 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

Add a new llm span to the current parent. Arguments
  • 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.
Returns
  • LlmSpan: The created span.

add_protect_span

Add a new Protect tool span to the current parent. Arguments
  • payload (Payload): Input to the node. This is the input to the Protect invoke method. 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 Protect invoke method. 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.
Returns
  • ToolSpan: The created Protect tool span.

add_retriever_span

Add a new retriever span to the current parent. Arguments
  • 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.
Returns
  • RetrieverSpan: The created span.

add_single_llm_span_trace

Create a new trace with a single span and add it to the list of traces. The trace is automatically concluded. Arguments
  • 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.
Returns
  • LoggedTrace: The created trace.

add_tool_span

Add a new tool span to the current parent. Arguments
  • 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.
Returns
  • ToolSpan: The created span.

add_workflow_span

Add a workflow span to the current parent. This is useful when you want to create a nested workflow span within the trace or current workflow span. The next span you add will be a child of the current parent. To move out of the nested workflow, use conclude(). Arguments
  • 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).
Returns
  • LoggedWorkflowSpan: The created span.

async_flush

Async upload all traces to Galileo. Returns
  • list[LoggedTrace]: The list of uploaded traces.

async_ingest_traces

Async ingest traces to Galileo. Can be used in combination with the ingestion_hook to ingest modified traces.

async_start_session

Async start a new session or use an existing session if an external ID is provided. Arguments
  • 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”}
Returns
  • str: The ID of the session (existing or newly created).

conclude

Conclude the current trace or workflow span by setting the output of the current node. In the case of nested workflow spans, this will point the workflow back to the parent of the current workflow span. Arguments
  • 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.
Returns
  • Optional[StepWithChildSpans]: The parent of the current workflow. None if no parent exists.

disable_agent_control

Unregister this logger from Agent Control if a bridge is active.

enable_agent_control

Register this logger as the active Agent Control bridge target.

flush

Upload all traces to Galileo. Arguments
  • 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).
Returns
  • list[LoggedTrace]: The list of uploaded traces.

get_tracing_headers

Get tracing headers for distributed tracing. Returns headers that can be passed to downstream services to continue the distributed trace. Raises
  • GalileoLoggerException: If not in distributed mode or if no trace has been started.
Returns
  • 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
Examples
Note: Project and log_stream are configured per service (via env vars or logger initialization), not propagated via headers, following standard distributed tracing patterns.

ingest_traces

Ingest traces to Galileo. Can be used in combination with the ingestion_hook to ingest modified traces.

set_session

Set the session ID for the logger. Arguments
  • session_id (str): ID of the session to set.

start_session

Start a new session or use an existing session if an external ID is provided. Arguments
  • 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”}
Returns
  • str: The ID of the session (existing or newly created).

start_trace

Create a new trace and add it to the list of traces. Once this trace is complete, you can close it out by calling conclude(). Arguments
  • 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(...)]
  • 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.
Returns
  • LoggedTrace: The created trace.

terminate

Terminate the logger and flush all traces to Galileo. This is a lifecycle-end call. After 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.