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

1import os
2
3from strands import Agent
4from strands.models.openai import OpenAIModel
5from strands.tools import tool
6from respan import Respan
7from respan_instrumentation_strands_agents import StrandsAgentsInstrumentor
8
9respan = Respan(instrumentations=[StrandsAgentsInstrumentor()])
10
11@tool
12def get_weather(location: str) -> str:
13 """Get the current weather for a location."""
14 return f"The weather in {location} is sunny, 72F."
15
16model = OpenAIModel(
17 model_id="gpt-4o-mini",
18 client_args={"api_key": os.environ["OPENAI_API_KEY"]},
19)
20
21agent = Agent(model=model, tools=[get_weather])
22response = agent("What is the weather in Seattle?")
23print(response)
24respan.flush()
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.

1from respan import Respan
2from respan_instrumentation_strands_agents import StrandsAgentsInstrumentor
3
4respan = Respan(
5 instrumentations=[StrandsAgentsInstrumentor()],
6 customer_identifier="user_123",
7 metadata={"service": "strands-api", "version": "1.0.0"},
8)

With propagate_attributes

Override per-request attributes using a context scope.

1from respan import Respan, propagate_attributes
2from respan_instrumentation_strands_agents import StrandsAgentsInstrumentor
3
4respan = Respan(instrumentations=[StrandsAgentsInstrumentor()])
5
6async def handle_request(user_id: str, message: str):
7 with propagate_attributes(
8 customer_identifier=user_id,
9 thread_identifier="conv_abc_123",
10 metadata={"plan": "pro"},
11 ):
12 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.