Skip to main content

OpenInference Strands Agents Instrumentation

pypi

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 or Arize AX.

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

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

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file openinference_instrumentation_strands_agents-0.1.8.tar.gz.

File metadata

File hashes

Hashes for openinference_instrumentation_strands_agents-0.1.8.tar.gz
Algorithm Hash digest
SHA256 778f0403fbe1c41be709004355c8fe877c939091cc315277ffdeb32446515e3d
MD5 564826c56c0b179a06fd7355b664885b
BLAKE2b-256 8b6a2215c54815b849bdf80659f8e2d2a85d9927e027e0d57b8645ca931c3576

See more details on using hashes here.

Provenance

The following attestation bundles were made for openinference_instrumentation_strands_agents-0.1.8.tar.gz:

Publisher: publish.yaml on Arize-ai/openinference

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openinference_instrumentation_strands_agents-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for openinference_instrumentation_strands_agents-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0c324bf81a16c771ffbd4fc92875b9f375ba9164ab5b77dfa4bd07ee0cee428c
MD5 e66bdb758a6bfee8b7235c3729a0709f
BLAKE2b-256 e11d4e5abc10b505286ca989c280b325e1596a36b864f96653cefaf4a5b67b8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for openinference_instrumentation_strands_agents-0.1.8-py3-none-any.whl:

Publisher: publish.yaml on Arize-ai/openinference

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page