Skip to Content

Strands Agents (tracing)

Strands Agents  is an SDK for building model-driven agents with tools, sessions, and orchestration. Respan captures agent runs, reasoning loops, model calls, tool invocations, graph spans, and swarm spans.

This tracing setup uses your model provider credentials directly. To route model calls through Respan instead, use the Strands Agents gateway setup .

Set up Respan

Create an account at platform.respan.ai  and grab an API key .

Paste this into your coding agent:

Help me set up Respan tracing with the Strands Agents integration. Follow https://www.respan.ai/docs/integrations/strands-agents.md

Setup

Install packages

Terminal
pip install respan-ai respan-instrumentation-strands-agents "strands-agents[openai]"

Set environment variables

Terminal
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY" export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

OPENAI_API_KEY is used for direct provider calls. RESPAN_API_KEY exports traces to Respan.

Initialize and run

Python
import os from strands import Agent from strands.models.openai import OpenAIModel from strands.tools import tool from respan import Respan from respan_instrumentation_strands_agents import StrandsAgentsInstrumentor respan = Respan(instrumentations=[StrandsAgentsInstrumentor()]) @tool def get_weather(location: str) -> str: """Get the current weather for a location.""" return f"The weather in {location} is sunny, 72F." model = OpenAIModel( model_id="gpt-4o-mini", client_args={"api_key": os.environ["OPENAI_API_KEY"]}, ) agent = Agent(model=model, tools=[get_weather]) response = agent("What is the weather in Seattle?") print(response)

View your trace

Open the Traces page  to see Strands agent, model, tool, loop, graph, swarm, and node spans.

Configuration

ParameterTypeDefaultDescription
api_key / apiKeystr | None / string | undefinedRESPAN_API_KEYRespan API key used to export traces.
base_url / baseURLstr | None / string | undefinedRESPAN_BASE_URLOptional Respan trace export API URL.
instrumentationslist / RespanInstrumentation[][]Include StrandsAgentsInstrumentor() or new StrandsAgentsInstrumentor() to activate Strands tracing.
includeToolDefinitionsbooleantrueTypeScript option that opts in to Strands tool-definition semantic conventions before export.

Attributes

In Respan()

Set defaults at initialization. These apply to all spans.

Python
from respan import Respan from respan_instrumentation_strands_agents import StrandsAgentsInstrumentor respan = Respan( instrumentations=[StrandsAgentsInstrumentor()], customer_identifier="user_123", metadata={"service": "strands-api", "version": "1.0.0"}, )

With propagate_attributes

Override per-request attributes using a context scope.

Python
from respan import Respan, propagate_attributes from respan_instrumentation_strands_agents import StrandsAgentsInstrumentor respan = Respan(instrumentations=[StrandsAgentsInstrumentor()]) async def handle_request(user_id: str, message: str): with propagate_attributes( customer_identifier=user_id, thread_identifier="conv_abc_123", metadata={"plan": "pro"}, ): print(agent(message))
AttributeTypeDescription
customer_identifierstr / stringIdentifies the end user in Respan analytics.
thread_identifierstr / stringGroups related messages into a conversation.
metadatadict / Record<string, unknown>Custom key-value pairs.