Configure zero-code instrumentation for Python AI applications
Instrument your backend Python AI applications to send metrics and traces to Splunk Observability Cloud.
Instrument your backend Python AI applications to send traces and metrics to Splunk Observability Cloud.
Zero-code instrumentation exports telemetry data using the OpenTelemetry GenAI utility and does not require changes to your application code. The instrumentation agent configures the source application to export data in a supported format to an OTLP endpoint, on either an OTLP receiver or the Splunk Observability Cloud backend.
For examples of applications using the instrumentation frameworks, see the examples directory of each instrumentation framework in splunk-otel-python-contrib/instrumentation-genai.
Prerequisite
Zero-code instrumentation requires Python 3.10 or higher.
Additional prerequisites may apply for certain instrumentation frameworks. For more details, see the respective section for your instrumentation framework.
Zero-code instrumentation integrations
CrewAI
Prerequisites
To instrument a CrewAI application, you must have access to an LLM provider, either through the OpenAI API key or OAuth2 credentials.
The CrewAI instrumentation captures workflow orchestration for crews, tasks, agents, and tools, but does not directly instrument LLM and embedding calls. For complete observability, including LLM call details such as token usage, model names, and latency, you must also install and enable provider-specific instrumentation packages:
-
OpenAI and Azure OpenAI:
pip install opentelemetry-instrumentation-openai-v2 -
Anthropic:
pip install opentelemetry-instrumentation-anthropic -
Other providers: Check the splunk-otel-python-contrib/instrumentation-genai directory for available providers.
Without provider instrumentation, you'll see workflow structure but not the detailed LLM call spans shown in the trace view. These LLM call spans are represented by chat (OpenAI/LiteLLM) in the Expected Trace Structure diagram.
Steps
- Install the instrumentation package:
CODE
pip install splunk-otel-instrumentation-crewai -
Run your application with the instrumentation:CODE
opentelemetry-instrument python <your_app>.py
FastMCP
Prerequisites
To instrument a MCP server built with FastMCP, you must meet the fastmcp and util-genai version requirements specified in the Compatibility Matrix.
Steps
- Install the instrumentation package:
(Optional) To install both the instrumentation package and the latest version of FastMCP, run:CODE
pip install splunk-otel-instrumentation-fastmcpCODEpip install 'splunk-otel-instrumentation-fastmcp[instruments]' -
Run your server with the instrumentation:CODE
opentelemetry-instrument python your_mcp_server.py -
Configure the telemetry for your MCP transport mode. For more information on the configuration settings in this step, see Configure the Python agent for AI applications (0.1.14 and higher).
- stdio
-
By default, stdio servers run in isolated environments and do not inherit the environment variables from your shell. You must explicitly pass required configurations to the server. When you spawn the FastMCP server from the
Client, ensure that you passOTEL_*inenvandopentelemetry-instrumenttocommandtoStdioTransportas shown in the following command.- Start the server (spawned from
<your_fastmcp_client>.py):CODEtransport = StdioTransport(command="opentelemetry-instrument", args=["python", "your_fastmcp_server.py"], env=<ADD_OTEL_*_env_vars>) client = Client(transport) -
Run the client:
CODEOTEL_SERVICE_NAME=<your_fastmcp_client_app> \ opentelemetry-instrument python <your_fastmcp_client_app>.py # zero-codeNote: In stdio mode, the server'sOTEL_SERVICE_NAMEmust be set in the server process environment. The client and server get separate service names because they are separate processes.
- Start the server (spawned from
- HTTP
-
- Set the following OpenTelemetry-specific environment variables in your server's
.envfile:CODEOTEL_SERVICE_NAME=<your_fastmcp_server_app> \ OTEL_INSTRUMENTATION_GENAI_EMITTERS=span_metric -
Start the server:CODE
opentelemetry-instrument python <your_fastmcp_server_app>.py # zero-code -
Run the client:CODE
OTEL_SERVICE_NAME=<your_fastmcp_client_app> \ opentelemetry-instrument python <your_fastmcp_client_app>.py # zero-code
- Set the following OpenTelemetry-specific environment variables in your server's
GCP VertexAI
Prerequisites
- You have access to a Google Cloud project with the Vertex AI API enabled and valid Google Cloud credentials.
-
Your application uses
google-cloud-aiplatformversion 1.64.0 or higher. Google has deprecated this module and plans to remove it on June 24, 2026.
Steps
- Install the instrumentation package:
CODE
pip install splunk-otel-instrumentation-vertexai -
Run your application with the instrumentation:CODE
opentelemetry-instrument python <your_app>.py
LangChain/LangGraph
Prerequisites
If your application is already instrumented with an OpenTelemetry SDK, you must upgrade your OpenTelemetry dependencies to version 1.38.0 or higher.
SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY=true setting.
Steps
- Configure your LangChain/LangGraph application for AI Agent Monitoring:
-
Set the
agent_namefor your Chains. This setting ensures that the instrumentation will promote your Chains to theAgentInvocationand evaluate your Chains with LLM-as-a-Judge evaluators. For example:JSONagent = _create_react_agent(llm, tools=[]).with_config( "metadata": { "agent_name": "coordinator"} ) -
Set the
workflow_nameto promote the Chain or Graph to your workflow. For example:JSONapp = StateGraph(state).compile().with_config(metadata={"workflow_name": "multi_agent_travel_planner"})
-
-
Install the instrumentation package:CODE
pip install splunk-otel-instrumentation-langchain -
Run your application with the instrumentation:CODE
opentelemetry-instrument python <your_app>.py
LlamaIndex
Steps
- Install the instrumentation package:
CODE
pip install splunk-otel-instrumentation-llamaindex -
Run your application with the instrumentation:CODE
opentelemetry-instrument python <your_app>.py
OpenAI
Prerequisites
To instrument an OpenAI agent application, you must have an OpenAI API key (OPENAI_API_KEY) or access to an OpenAI-compatible LLM endpoint.
- Install the instrumentation package:
CODE
pip install splunk-otel-instrumentation-openai -
Run your application with the instrumentation:CODE
opentelemetry-instrument python <your_app>.py
OpenAI agents
Prerequisites
-
You have an OpenAI API key (
OPENAI_API_KEY) or access to an OpenAI-compatible LLM endpoint. -
You have installed
openai-agents-pythonSDK 0.3.3 or higher.
Steps
- Install the instrumentation package:
CODE
pip install splunk-otel-instrumentation-openai-agents -
Run your application with the instrumentation:CODE
opentelemetry-instrument python <your_app>.py
Weaviate
Steps
- Install the instrumentation package:
CODE
pip install splunk-otel-instrumentation-weaviate -
Run your application with the instrumentation:CODE
opentelemetry-instrument python <your_app>.py
Next steps
To finish setting up AI Agent Monitoring, proceed to the next step in Set up AI Agent Monitoring.