Skip to content

Commit 4179508

Browse files
authored
feat(telemetry): Add usage examples for setup_console_exporter and setup_otlp_exporter arguments (#162)
* docs(telemetry): Add usage examples for setup_console_exporter and setup_otlp_exporter arguments * docs(telemetry) Change order of exporters config section
1 parent 1e56c90 commit 4179508

File tree

1 file changed

+29
-3
lines changed
  • docs/user-guide/observability-evaluation

1 file changed

+29
-3
lines changed

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ Strands traces include rich attributes that provide context for each operation:
225225
| `tool.status` | Execution status (success/error) |
226226
| `gen_ai.tool.name` | Name of the tool called |
227227
| `gen_ai.tool.call.id` | Unique identifier for the tool call |
228-
| `gen_ai.operation.name` | Gen-AI operation name |
228+
| `gen_ai.operation.name` | Gen-AI operation name |
229229
| `gen_ai.event.start_time` | When tool execution began |
230230
| `gen_ai.event.end_time` | When tool execution completed |
231231
| `gen_ai.choice` | Formatted tool result |
@@ -289,8 +289,6 @@ For high-volume applications, you may want to implement sampling to reduce the v
289289
# Example: Sample 10% of traces
290290
os.environ["OTEL_TRACES_SAMPLER"] = "traceidratio"
291291
os.environ["OTEL_TRACES_SAMPLER_ARG"] = "0.5"
292-
293-
294292
```
295293

296294
### Custom Attribute Tracking
@@ -313,6 +311,34 @@ agent = Agent(
313311
)
314312
```
315313

314+
### Configuring the exporters from source code
315+
316+
The `StrandsTelemetry().setup_console_exporter()` and `StrandsTelemetry().setup_otlp_exporter()` methods accept keyword arguments that are passed to OpenTelemetry's [`ConsoleSpanExporter`](https://opentelemetry-python.readthedocs.io/en/latest/sdk/trace.export.html#opentelemetry.sdk.trace.export.ConsoleSpanExporter) and [`OTLPSpanExporter`](https://opentelemetry-python.readthedocs.io/en/latest/exporter/otlp/otlp.html#opentelemetry.exporter.otlp.proto.http.trace_exporter.OTLPSpanExporter) initializers, respectively. This allows you to save the log lines to a file or set up the OTLP endpoints from Python code:
317+
318+
```python
319+
from os import linesep
320+
from strands.telemetry import StrandsTelemetry
321+
322+
strands_telemetry = StrandsTelemetry()
323+
324+
# Save telemetry to a local file and configure the serialization format
325+
logfile = open("my_log.jsonl", "wt")
326+
strands_telemetry.setup_console_exporter(
327+
out=logfile,
328+
formatter=lambda span: span.to_json() + linesep,
329+
)
330+
# ... your agent-running code goes here ...
331+
logfile.close()
332+
333+
# Configure OTLP endpoints programmatically
334+
strands_telemetry.setup_otlp_exporter(
335+
endpoint="http://collector.example.com:4318",
336+
headers={"key1": "value1", "key2": "value2"},
337+
)
338+
```
339+
340+
For more information about the accepted arguments, refer to `ConsoleSpanExporter` and `OTLPSpanExporter` in the [OpenTelemetry API documentation](https://opentelemetry-python.readthedocs.io).
341+
316342
## Best Practices
317343

318344
1. **Use appropriate detail level**: Balance between capturing enough information and avoiding excessive data

0 commit comments

Comments
 (0)