Galileo Logger
Get granular control over logging with the GalileoLogger class
The 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
The GalileoLogger
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
This approach requires more code than using wrappers or decorators but gives you the most control over the logging process.
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 the GalileoLogger
to log an LLM call:
This example:
- 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
See the 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.
If you are using any of the decorators, wrappers, or third-party integrations then this allows you to get the logger created by those components. For example, if you are adding a call inside a method decorated by the Python @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.
See the 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.
The name and external ID fields are optional. If you want to connect a session to another ID that you are using internally, for example a unique id for a chatbot conversation, then you can set this in the external ID field.
See the 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.
See the 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.
See the 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.
See the start_trace
Python SDK docs or startTrace
TypeScript SDK docs for more details.
Add Spans
The GalileoLogger
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. |
You can read more about spans including how and when to use the different types in out Spans documentation.
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.
See the 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.
See the 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.
See the add_retriever_span
Python SDK docs or addRetrieverSpan
TypeScript SDK docs for more details.
Tool Spans
Tool spans log calls to tools.
See the 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.
See the 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.
See the 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.
See the 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:
See the 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.