Strands Agents
cetra traces Strands Agents runs as agent, event loop, model call and tool spans, with the messages and the time to first token.
Install
Section titled “Install”pip install cetra-sdk "strands-agents[openai]"Set up
Section titled “Set up”Strands writes its spans to the global OpenTelemetry tracer provider. Start cetra with use_global_provider=True so that it joins that provider. Set CETRA_API_KEY to your sk-cetra-… key and OPENAI_API_KEY to your OpenAI key.
import os
import cetrafrom strands import Agent, toolfrom strands.models.openai import OpenAIModel
cetra.init(use_global_provider=True)
@tooldef get_weather(city: str) -> str: """Get the weather.""" return f"sunny in {city}"
model = OpenAIModel( client_args={"api_key": os.environ["OPENAI_API_KEY"]}, model_id="gpt-4o-mini",)agent = Agent( model=model, tools=[get_weather], name="weather_agent", system_prompt="You are a weather bot.", callback_handler=None, trace_attributes={"session.id": "s1"},)agent("What is the weather in Paris?")
cetra.flush()trace_attributes sets the session of the run: session.id becomes the cetra session.
Strands has two ways to record message content, and cetra reads both. The default writes events on the spans. Set OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental before you import Strands to use the latest GenAI conventions instead. The fixtures have the messages with either setting.
What you get
Section titled “What you get”With one tool call, a run produces:
- an
agentspan namedinvoke_agent weather_agent, with the prompt as its input and the answer as its output; - a
chainspan namedexecute_event_loop_cyclefor each event loop cycle; - an
llmspan namedchatfor each model call, with the provideropenai, the request and response models, the token counts, the cost computed from the built-in prices, the messages, and the time to first token (TTFT) in milliseconds; - a
toolspan for each tool call, with the arguments as its input and the result as its output.
Limits
Section titled “Limits”- The fixtures were captured with
strands-agents1.65.0 and the OpenTelemetry SDK 1.45.2. - The time to first token comes from Strands’
gen_ai.server.time_to_first_tokenattribute. - Each event loop cycle is a
chainspan. It is not a model call, so it adds no tokens or cost. - If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Online rules: score these traces automatically.