OpenInference span processor for Strands Agents - transforms native OpenTelemetry spans to OpenInference format
Project description
OpenInference Strands Agents Instrumentation
Python instrumentation library for Strands Agents.
This package provides a span processor that transforms Strands' native OpenTelemetry spans to OpenInference format. The traces are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as arize-phoenix.
Installation
pip install openinference-instrumentation-strands-agents
Quickstart
In this example we will instrument a small Strands agent program and observe the traces via arize-phoenix.
Install packages.
pip install openinference-instrumentation-strands-agents strands-agents arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp
Start the phoenix server so that it is ready to collect traces. The Phoenix server runs entirely on your machine and does not send data over the internet.
python -m phoenix.server.main serve
In a python file, setup the Strands telemetry and add the StrandsAgentsToOpenInferenceProcessor to transform spans.
import os
from strands import Agent, tool
from strands.models.openai import OpenAIModel
from strands.telemetry import StrandsTelemetry
from openinference.instrumentation.strands_agents import StrandsAgentsToOpenInferenceProcessor
# Setup Strands native telemetry
telemetry = StrandsTelemetry()
telemetry.setup_otlp_exporter(endpoint="http://127.0.0.1:6006/v1/traces")
# Add OpenInference processor to transform spans
telemetry.tracer_provider.add_span_processor(StrandsAgentsToOpenInferenceProcessor())
@tool
def get_weather(city: str) -> dict:
"""Get the current weather for a city.
Args:
city: The name of the city
"""
return {
"status": "success",
"content": [{"text": f"The weather in {city} is sunny and 72°F."}],
}
if __name__ == "__main__":
# Create and run agent
model = OpenAIModel(model_id="gpt-4o-mini")
agent = Agent(
name="WeatherAgent",
model=model,
tools=[get_weather],
system_prompt="You are a helpful weather assistant.",
)
result = agent("What's the weather in San Francisco?")
print(result)
Since we are using OpenAI, we must set the OPENAI_API_KEY environment variable to authenticate with the OpenAI API.
export OPENAI_API_KEY=your-api-key
Now simply run the python file and observe the traces in Phoenix.
python your_file.py
Important: Processor Ordering
The StrandsAgentsToOpenInferenceProcessor mutates spans in-place. This means the order in which you add span processors matters.
Add the StrandsAgentsToOpenInferenceProcessor before any exporters that should receive the transformed OpenInference spans:
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
# Correct order: processor first, then exporter
telemetry.tracer_provider.add_span_processor(StrandsAgentsToOpenInferenceProcessor())
telemetry.tracer_provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
If you need to export both the original GenAI spans and transformed OpenInference spans to different destinations, you'll need to set up the processors carefully or consider using separate tracer providers.
More Info
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openinference_instrumentation_strands_agents-0.1.2.tar.gz.
File metadata
- Download URL: openinference_instrumentation_strands_agents-0.1.2.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fb6703ea08560be4b1b889cf1264851b1d49a68d710815dc81f387455344121
|
|
| MD5 |
536f47a08a7fb0d241739debc5efbba7
|
|
| BLAKE2b-256 |
fd83bb322106dfed2fe7273d30779c24f6504bf3a27d09dcd307917823d75db4
|
File details
Details for the file openinference_instrumentation_strands_agents-0.1.2-py3-none-any.whl.
File metadata
- Download URL: openinference_instrumentation_strands_agents-0.1.2-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dab72a8b70017eb4653f597dbfe2d77df970c08d93ec6181607fd0735c8819f
|
|
| MD5 |
9507f468e8f36f431f1777042778bc0f
|
|
| BLAKE2b-256 |
4519cd1cd57f327cee122d82f8dc17cebcdb9817a6687abd6f00746e1175793a
|