Skip to main content

Strands Agents

Strands Agents traces every agent run, event-loop cycle, model call and tool call in GenAI semantic conventions through your OpenTelemetry tracer provider. Pass gen_ai.conversation.id in trace_attributes to group the turns of a conversation. For an agent served by Amazon Bedrock AgentCore Runtime, see Amazon Bedrock AgentCore.

New to Oodle?

Oodle is a managed observability platform for metrics, logs, traces and agent traces. It ingests OpenTelemetry natively, so the snippet on this page is the complete setup.

Each trace shows the full transcript, the token counts and cost of every call, the agent structure (runs, steps and tool calls) and Signals: labels for loops, rate limits, refusals and tool failures, detected as the trace arrives.

Sign up for free to get an instance ID and an API key, or see the Agent Observability overview first.

You will need:

  • OODLE_INSTANCE: your Oodle instance ID (ap1, us1)
  • OODLE_API_KEY: an Oodle API key (ap1, us1)
  • OTLP_ENDPOINT: your OTLP collector domain, shown on the tile

Open the Strands Agents tile on the ap1, us1 page to get these filled in for you, or let an agent do the setup with /oodle-onboarding set up the llm_observability_strands integration.

Install​

Install Strands with the OpenTelemetry SDK and the OTLP exporter:

pip install strands-agents \
opentelemetry-sdk \
opentelemetry-exporter-otlp-proto-http

Instrument​

Set up OpenTelemetry before the first agent is built. Strands then traces every agent run, event-loop cycle, model call and tool call in GenAI semantic conventions:

from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from strands import Agent, tool
from strands.models import BedrockModel


def setup_opentelemetry():
resource = Resource.create({"service.name": "my-strands-agent"})

tracer_provider = TracerProvider(resource=resource)
tracer_provider.add_span_processor(
BatchSpanProcessor(OTLPSpanExporter())
)
trace.set_tracer_provider(tracer_provider)
return tracer_provider


# Before the first Agent: Strands traces through the global provider.
tracer_provider = setup_opentelemetry()


@tool
def get_weather(city: str) -> str:
"""Return the weather for a city."""
return f"Sunny in {city}"


agent = Agent(
name="weather-agent",
model=BedrockModel(model_id="us.amazon.nova-lite-v1:0"),
system_prompt="Use tools when asked about the weather.",
tools=[get_weather],
callback_handler=None,
# Groups the turns of one conversation in Oodle.
trace_attributes={"gen_ai.conversation.id": "conversation-123"},
)

print(agent("What is the weather in Paris?"))

# Short-lived processes must flush before they exit.
tracer_provider.force_flush()

Environment​

Point the application at Oodle:

# OTLP endpoint (points straight at Oodle)
export OTEL_EXPORTER_OTLP_ENDPOINT=https://<OTLP_ENDPOINT>

export OTEL_EXPORTER_OTLP_HEADERS="X-API-KEY=<OODLE_API_KEY>,X-OODLE-INSTANCE=<OODLE_INSTANCE>"

# Compress the export: prompt payloads are large
export OTEL_EXPORTER_OTLP_COMPRESSION=gzip

# GenAI semantic conventions, with prompts and replies on the spans
export OTEL_SEMCONV_STABILITY_OPT_IN=gen_ai_latest_experimental,gen_ai_span_attributes_only

What each run becomes​

Strands activitySpan
One call of the agentinvoke_agent <agent>, the root of the trace
One reasoning cycleexecute_event_loop_cycle
A model callchat, with the messages, system instructions and token counts
A tool callexecute_tool <tool>, with its arguments and result

The invoke_agent span repeats the token totals of its chat spans; only the chat spans are counted, so totals are not doubled. The snippet uses Amazon Bedrock; Strands traces its other model providers the same way.

Content​

Strands puts prompts, replies, system instructions and tool arguments and results on the spans with the opt-in shown. To redact them, add gen_ai_unredacted_attributes= to OTEL_SEMCONV_STABILITY_OPT_IN: Strands then replaces every content attribute it would send. Token counts, timings, model and tool names, and errors remain.

Verify​

Run your application, then open ap1, us1. Spans carry gen_ai.* attributes: the model, token counts, and the prompt and response content. Click a trace for the Transcript, the waterfall, and the cost breakdown.

Trace detail showing the Transcript tab with system, user, and assistant messages

If nothing arrives, check that the exporter can reach https://<OTLP_ENDPOINT> and that the instance and key are set: the OTLP gateway answers 401 without them.


Support

If you need assistance or have any questions, please reach out to us through: