logger
GalileoLogger Objects
This class can be used to upload traces to Galileo.
First initialize a new GalileoLogger object with an existing project and log stream.
logger = GalileoLogger(project="my_project", log_stream="my_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.
start_trace
Create a new trace and add it to the list of traces.
Simple usage:
Arguments:
input
- StepIOType: Input to the node.output
- Optional[str]: Output of the node.name
- Optional[str]: Name of the trace.duration_ns
- Optional[int]: Duration of the trace in nanoseconds.created_at
- Optional[datetime]: Timestamp of the trace’s creation.metadata
- Optional[Dict[str, str]]: Metadata associated with this trace.ground_truth
- Optional[str]: Ground truth, expected output of the trace.
Returns:
Trace
- The created trace.
add_single_llm_span_trace
Create a new trace with a single span and add it to the list of traces.
Arguments:
input
- LlmStepAllowedIOType: Input to the node.output
- LlmStepAllowedIOType: Output of the node.model
- str: Model used for this span. Feedback from April: Good docs about what model names we use.tools
- Optional[List[Dict]]: List of available tools passed to LLM on invocation.name
- Optional[str]: Name of the span.duration_ns
- Optional[int]: duration_ns of the node in nanoseconds.created_at
- Optional[datetime]: Timestamp of the span’s creation.user_metadata
- Optional[Dict[str, str]]: Metadata associated with this span.num_input_tokens
- Optional[int]: Number of input tokens.num_output_tokens
- Optional[int]: Number of output tokens.output
0 - Optional[int]: Total number of tokens.output
1 - Optional[float]: Temperature used for generation.output
2 - Optional[str]: Ground truth, expected output of the workflow.output
3 - Optional[int]: Status code of the node execution.output
4 - Optional[int]: Time until the first token was returned.
Returns:
output
5 - The created trace.
add_llm_span
Add a new llm span to the current parent.
Arguments:
input
- LlmStepAllowedIOType: Input to the node.output
- LlmStepAllowedIOType: Output of the node.model
- str: Model used for this span.tools
- Optional[List[Dict]]: List of available tools passed to LLM on invocation.name
- Optional[str]: Name of the span.duration_ns
- Optional[int]: duration_ns 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.num_input_tokens
- Optional[int]: Number of input tokens.num_output_tokens
- Optional[int]: Number of output tokens.output
0 - Optional[int]: Total number of tokens.output
1 - Optional[float]: Temperature used for generation.output
2 - Optional[int]: Status code of the node execution.output
3 - Optional[int]: Time until the first token was returned.
Returns:
output
4 - The created span.
add_retriever_span
Add a new retriever span to the current parent.
Arguments:
input
- StepIOType: Input to the node.output
- Union[str, list[str], dict[str, str], list[dict[str, str]], Document, list[Document], None]: Documents retrieved from the retriever.name
- Optional[str]: Name of the span.duration_ns
- Optional[int]: duration_ns 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.
Returns:
RetrieverSpan
- The created span.
add_tool_span
Add a new tool span to the current parent.
Arguments:
input
- StepIOType: Input to the node.output
- StepIOType: Output of the node.name
- Optional[str]: Name of the span.duration_ns
- Optional[int]: duration_ns of the node in nanoseconds.created_at
- Optional[datetime]: Timestamp of the span’s creation.user_metadata
- Optional[Dict[str, str]]: Metadata associated with this span.status_code
- Optional[int]: Status code of the node execution.
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.output
- Optional[str]: Output of the node. This can also be set on conclude().name
- Optional[str]: Name of the span.duration_ns
- Optional[int]: duration_ns 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.
Returns:
WorkflowSpan
- The created span.
add_agent_span
Add an agent type span to the current parent.
Arguments:
input
- str: Input to the node.output
- Optional[str]: Output of the node. This can also be set on conclude().name
- Optional[str]: Name of the span.duration_ns
- Optional[int]: duration_ns 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.agent_type
- Optional[AgentType]: Agent type of the span.
Returns:
AgentSpan
- The created span.
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[StepIOType]: Output of the node.duration_ns
- Optional[int]: duration_ns 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.
flush
Upload all traces to Galileo.
async_flush
Async upload all traces to Galileo.
terminate
Terminate the logger and flush all traces to Galileo.
start_session
Start a new session.
Arguments:
name
- str: Name of the session.previous_session_id
- Optional[str]: ID of the previous session.external_id
- Optional[str]: External ID of the session.
Returns:
str
- The ID of the newly created session.
set_session
Arguments:
session_id
- str: ID of the session to set.
Returns:
None