Skip to content

Commit 5d6beb0

Browse files
authored
docs: add Strands built-in telemetry example to integrations page (opensearch-project#130)
Add a second Strands example showing how to use StrandsTelemetry() for native OTel instrumentation pointed at the collector, with @observe for custom spans Strands doesn't emit automatically. Signed-off-by: Vamsi Manohar <reddyvam@amazon.com>
1 parent fa0c68e commit 5d6beb0

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

docs/starlight-docs/src/content/docs/send-data/ai-agents/integrations.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,49 @@ def run_agent(query: str) -> str:
4545
run_agent("What's the weather in Seattle?")
4646
```
4747

48+
### Using Strands built-in telemetry
49+
50+
Strands Agents has native OpenTelemetry support via `StrandsTelemetry`. It automatically emits spans for agent invocations, tool executions, and LLM calls following GenAI semantic conventions. Point it at the OTel collector, then use `@observe` from the SDK to add spans for any custom logic that Strands doesn't instrument automatically.
51+
52+
```bash
53+
pip install opensearch-genai-observability-sdk-py strands-agents strands-agents-bedrock
54+
```
55+
56+
```python
57+
from opensearch_genai_observability_sdk_py import observe, Op
58+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
59+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
60+
from strands import Agent
61+
from strands.models.bedrock import BedrockModel
62+
from strands.telemetry import StrandsTelemetry
63+
64+
# Initialize Strands' built-in telemetry — automatically creates spans for:
65+
# invoke_agent, execute_tool, chat (LLM calls)
66+
telemetry = StrandsTelemetry()
67+
68+
# Point the exporter at the OTel collector (gRPC on port 4317)
69+
exporter = OTLPSpanExporter(endpoint="localhost:4317", insecure=True)
70+
telemetry.tracer_provider.add_span_processor(BatchSpanProcessor(exporter))
71+
72+
# Use @observe for custom logic that Strands doesn't auto-instrument
73+
@observe(op=Op.EXECUTE_TOOL)
74+
def fetch_hotel_ratings(city: str) -> str:
75+
"""Fetch hotel ratings from an external API."""
76+
# Custom API call — not covered by Strands auto-instrumentation
77+
return f"4.5 stars average in {city}"
78+
79+
model = BedrockModel(model_id="us.anthropic.claude-sonnet-4-20250514-v1:0")
80+
agent = Agent(
81+
model=model,
82+
tools=[fetch_hotel_ratings],
83+
system_prompt="You are a helpful travel assistant.",
84+
)
85+
86+
agent("Find top-rated hotels in Seattle")
87+
```
88+
89+
> **Tip:** `StrandsTelemetry` handles agent, tool, and LLM spans automatically. Use `@observe` only for custom functions (API calls, database queries, post-processing) where you need visibility that Strands doesn't provide out of the box.
90+
4891
## LangGraph
4992

5093
[LangGraph](https://langchain-ai.github.io/langgraph/) builds stateful, multi-step agent workflows. Install the LangChain auto-instrumentor for automatic LLM tracing.

0 commit comments

Comments
 (0)