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.

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

Run npx @respan/cli setup to set up with your coding agent.

See Strands Agents gateway setup to route model calls through the Respan gateway.

Setup

1

Install packages

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

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.

3

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)
4

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.

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))
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.