- Set the project and Agent Stream for all logs
- Get the current logger
- Flush traces
- Set the project and Agent Stream for a particular scope
- Manage sessions
- Get the current span and trace
splunk_ao_context object.
Set the project and Agent Stream
By default, Splunk Agent Observability uses theSPLUNK_AO_PROJECT and SPLUNK_AO_AGENT_STREAM environment variables to determine which project and Agent Stream to log to. You can override this by initializing the Splunk Agent Observability context with a project and Agent Stream name.
Set the project and Agent Stream for a single scope in Python
You can set the project and Agent Stream for a scope using the Pythonsplunk_ao_context, object in a with statement. Every log inside this block, including nested calls, will use the specified project and Agent Stream.
@log decorator.
Nesting scopes
You can nestsplunk_ao_context calls to temporarily override the project or Agent Stream:
Get the current logger
The Splunk Agent Observability 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 or created automatically by an experiment, then this will return that logger instance so you can manually add additional spans.
Flush logs
To keep your app performant, logs are not continually flushed. In some cases, you may want to flush traces explicitly:When using a Python Notebook (such as Jupyter, Google Colab, etc.), you should use the
splunk_ao_context and make sure to call splunk_ao_context.flush() at the end of your notebook.Manage sessions in Python
With the Python SDK, you can manage sessions from the context level in addition to the logger level. All the session management functions are applied to the current logger if called from the context. If you want to apply these to a specific logger instance, call the same methods directly on that logger instance.Create a new session
To create a new session, use thestart_session function.
Continue an existing session
If you want to add a trace to an existing session, you can use theset_session function, 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.
start_session function.
End a session
To stop logging to a session, you can clear the current session.Next steps
Basic logging components
Splunk Agent Observability logger
Log with full control over sessions, traces, and spans using the Splunk Agent Observability logger.
Log decorator
Quickly add logging to your code with the log decorator and wrapper.
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 Splunk Agent Observability trace processor.
LangChain callback
Automatically log all the steps in your LangChain or LangGraph application with the Splunk Agent Observability callback.