GalileoLogger
class provides the most granular control over logging in Galileo. You can create a logger yourself, or use one from the current context from inside a decorated or wrapped function or when using a third-party SDK integration.
Overview
TheGalileoLogger
class allows you to:
- Start sessions
- Manually create and manage traces
- Add spans of different types to your traces
- Control exactly what data gets logged
- Explicitly manage when traces are flushed to Galileo
Python SDK reference
The full SDK reference for the
GalileoLogger
Python class.TypeScript SDK reference
The full SDK reference for the
GalileoLogger
TypeScript class.Basic usage
Here’s a simple example of using theGalileoLogger
to log an LLM call:
- Starts a new session
- Starts a trace inside the session
- Adds an LLM span to the trace
- Concludes the trace
- Flushes the logger to send the session to Galileo
Detailed API
Initialization
GalileoLogger
Python SDK docs or TypeScript SDK docs for more details.
Get the current logger from the current context
The Galileo context management keeps track of loggers. You can get the current logger, which will create a new one if there isn’t an existing logger.@log
decorator, wrapped in the TypeScript log
wrapper, or created automatically by an experiment, then this will return that logger instance so you can manually add additional spans.
galileo_context
Python SDK docs or getLogger
TypeScript SDK docs for more details.
Manage sessions
All traces live inside a session. If you don’t create a session, then one is created automatically with a generated name.Start a session
You can start a new session, providing a name and an external ID.start_session
Python SDK docs or startSession
TypeScript SDK docs for more details.
Continue an existing session
If you want to add a trace to an existing session, you can set the current session for the logger, passing the session ID. This is useful if you want to persist a session, for example saving a chatbot conversation with a user mid conversation, then resuming the next time a user connects.set_session
Python SDK docs or setSession
TypeScript SDK docs for more details.
You can also continue a conversation using an external ID using the start session function.
End a session
To stop logging to a session, you can clear the current session.clear_session
Python SDK docs or clearSession
TypeScript SDK docs for more details.
Start a trace
Once a trace is started, all spans added to that logger will be added to that trace.start_trace
Python SDK docs or startTrace
TypeScript SDK docs for more details.
Add spans
TheGalileoLogger
supports adding different types of spans to your traces. All spans take the input and output, as well as a name, duration, tags, and other metadata.
Span Type | Description |
---|---|
Agent | A span for logging agent actions. You can specify the agent type, for example a supervisor, planner, router, or judge. |
LLM | A span for logging calls to an LLM. You can specify the number of tokens, time to first token, temperature, model, and any tools. |
Retriever | A span for logging RAG actions. In the output for this span you can provide all the data returned from the RAG platform for evaluating your RAG processing, |
Tool | A span for logging calls to tools. You can specify the tool call ID to tie to an LLM tool call. |
Workflow | Workflow spans are for creating logical groupings of spans based on different flows in your app. |
Agent spans
Agent spans are for logging the input and output to agents of different types. The type of agent can be set when creating the span, such as supervisor or planner.add_agent_span
Python SDK docs or addAgentSpan
TypeScript SDK docs for more details.
LLM spans
LLM spans are for logging calls to LLMs. You can log the input and output, tools, and details like input and output tokens.add_llm_span
Python SDK docs or addLlmSpan
TypeScript SDK docs for more details.
Retriever spans
Retriever spans are for logging calls to RAG systems. You can log the output from the RAG system to evaluate metrics like Context Adherence.add_retriever_span
Python SDK docs or addRetrieverSpan
TypeScript SDK docs for more details.
Tool spans
Tool spans log calls to tools.add_tool_span
Python SDK docs or addToolSpan
TypeScript SDK docs for more details.
Workflow spans
Workflow spans allow you to group spans into separate workflows for easier monitoring.add_workflow_span
Python SDK docs or addWorkflowSpan
TypeScript SDK docs for more details.
Conclude
When you have finished logging a trace, you can conclude it with the final output. This ends the trace, and a new trace needs to be created to continue logging. The wrappers and third-party integrations will conclude traces for you.conclude
Python SDK docs or conclude
TypeScript SDK docs for more details.
Flush
Logs are not continuously sent to Galileo to help your application stay performant. You can flush logs when you are ready. The wrappers and third-party integrations will flush logs for you at the end of each trace.flush
Python SDK docs or flush
TypeScript SDK docs for more details.
The flush call on the logger will just flush that specific logger. To flush all loggers, you can flush at the context level.
Advanced usage
Create a single LLM span trace
For simple LLM calls, you can create a trace with a single LLM span in one step:add_single_llm_span_trace
Python SDK docs or addSingleLlmSpanTrace
TypeScript SDK docs for more details.
Complex trace example
Here’s an example of creating a more complex trace with multiple spans:Best practices
- Use higher-level abstractions when possible: The
@log
decorator and wrappers are easier to use and less error-prone. - Flush traces when appropriate: Call
flush()
at the end of a request or user interaction to ensure data is sent to Galileo. - Include relevant metadata: Add tags and metadata to make it easier to filter and analyze your traces.
- Structure spans logically: Create a span hierarchy that reflects the logical structure of your application.
- Handle errors gracefully: Include status codes and error information in your spans to help with debugging.
Next steps
Basic logging components
Log decorator
Quickly add logging to your code with the log decorator and wrapper.
Galileo context
Manage logging using the Galileo context manager.
Integrations with third-party SDKs
OpenAI wrapper
Automatically log calls to the OpenAI SDK with a wrapper.
OpenAI Agents trace processor
Automatically log all the steps in your OpenAI Agent SDK apps using the Galileo trace processor.
LangChain callback
Automatically log all the steps in your LangChain or LangGraph application with the Galileo callback.