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.mdSetup
Install packages
pip install respan-ai respan-instrumentation-strands-agents "strands-agents[openai]"Set environment variables
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
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
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key / apiKey | str | None / string | undefined | RESPAN_API_KEY | Respan API key used to export traces. |
base_url / baseURL | str | None / string | undefined | RESPAN_BASE_URL | Optional Respan trace export API URL. |
instrumentations | list / RespanInstrumentation[] | [] | Include StrandsAgentsInstrumentor() or new StrandsAgentsInstrumentor() to activate Strands tracing. |
includeToolDefinitions | boolean | true | TypeScript option that opts in to Strands tool-definition semantic conventions before export. |
Attributes
In Respan()
Set defaults at initialization. These apply to all spans.
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.
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))| Attribute | Type | Description |
|---|---|---|
customer_identifier | str / string | Identifies the end user in Respan analytics. |
thread_identifier | str / string | Groups related messages into a conversation. |
metadata | dict / Record<string, unknown> | Custom key-value pairs. |