Skip to content

Commit c5a9c65

Browse files
authored
docs: update tracer setup documentation (#104)
1 parent 2d280e5 commit c5a9c65

File tree

1 file changed

+20
-25
lines changed
  • docs/user-guide/observability-evaluation

1 file changed

+20
-25
lines changed

docs/user-guide/observability-evaluation/traces.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ Strands natively integrates with OpenTelemetry, an industry standard for distrib
8989
# Specify custom OTLP endpoint if set will enable OTEL by default
9090
export OTEL_EXPORTER_OTLP_ENDPOINT="http://collector.example.com:4318"
9191

92-
# Enable Console debugging
93-
export STRANDS_OTEL_ENABLE_CONSOLE_EXPORT=true
94-
9592
# Set Default OTLP Headers
9693
export OTEL_EXPORTER_OTLP_HEADERS="key1=value1,key2=value2"
9794

@@ -101,16 +98,21 @@ export OTEL_EXPORTER_OTLP_HEADERS="key1=value1,key2=value2"
10198

10299
```python
103100
from strands import Agent
104-
from strands.telemetry.tracer import get_tracer
105-
106-
# Configure the tracer
107-
tracer = get_tracer(
108-
service_name="my-agent-service",
109-
otlp_endpoint="http://localhost:4318",
110-
otlp_headers={"Authorization": "Bearer TOKEN"},
111-
enable_console_export=True # Helpful for development
101+
102+
# Option 1: Skip StrandsTelemetry if global tracer provider is already configured
103+
# (your existing OpenTelemetry setup will be used automatically)
104+
agent = Agent(
105+
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
106+
system_prompt="You are a helpful AI assistant"
112107
)
113108

109+
# Option 2: Use StrandsTelemetry if you need Strands to set up OpenTelemetry
110+
from strands.telemetry import StrandsTelemetry
111+
112+
strands_telemetry = StrandsTelemetry()
113+
strands_telemetry.setup_otlp_exporter() # Send traces to OTLP endpoint
114+
strands_telemetry.setup_console_exporter() # Print traces to console
115+
114116
# Create agent (tracing will be enabled automatically)
115117
agent = Agent(
116118
model="us.anthropic.claude-3-7-sonnet-20250219-v1:0",
@@ -238,22 +240,13 @@ docker run -d --name jaeger \
238240

239241
Then access the Jaeger UI at http://localhost:16686 to view your traces.
240242

241-
You can also enable console export to inspect the spans:
243+
You can also setup console export to inspect the spans:
242244

243245
```python
244-
# By enabling the environment variable
245-
os.environ["STRANDS_OTEL_ENABLE_CONSOLE_EXPORT"] = "true"
246246

247-
# or
248-
249-
# Configure the tracer
250-
tracer = get_tracer(
251-
service_name="my-agent-service",
252-
otlp_endpoint="http://localhost:4318",
253-
otlp_headers={"Authorization": "Bearer TOKEN"},
254-
enable_console_export=True # Helpful for development
255-
)
247+
from strands.telemetry import StrandsTelemetry
256248

249+
StrandsTelemetry().setup_console_exporter()
257250

258251
```
259252

@@ -317,11 +310,13 @@ This example demonstrates capturing a complete trace of an agent interaction:
317310

318311
```python
319312
from strands import Agent
313+
from strands.telemetry import StrandsTelemetry
320314
import os
321315

322-
# Enable tracing with console output for visibility
323316
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = "http://localhost:4318"
324-
os.environ["STRANDS_OTEL_ENABLE_CONSOLE_EXPORT"] = "true"
317+
strands_telemetry = StrandsTelemetry()
318+
strands_telemetry.setup_otlp_exporter() # Send traces to OTLP endpoint
319+
strands_telemetry.setup_console_exporter() # Print traces to console
325320

326321
# Create agent
327322
agent = Agent(

0 commit comments

Comments
 (0)