You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: docs/user-guide/observability-evaluation/traces.md
+29-3Lines changed: 29 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -225,7 +225,7 @@ Strands traces include rich attributes that provide context for each operation:
225
225
|`tool.status`| Execution status (success/error) |
226
226
|`gen_ai.tool.name`| Name of the tool called |
227
227
|`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 |
229
229
|`gen_ai.event.start_time`| When tool execution began |
230
230
|`gen_ai.event.end_time`| When tool execution completed |
231
231
|`gen_ai.choice`| Formatted tool result |
@@ -289,8 +289,6 @@ For high-volume applications, you may want to implement sampling to reduce the v
289
289
# Example: Sample 10% of traces
290
290
os.environ["OTEL_TRACES_SAMPLER"] ="traceidratio"
291
291
os.environ["OTEL_TRACES_SAMPLER_ARG"] ="0.5"
292
-
293
-
294
292
```
295
293
296
294
### Custom Attribute Tracking
@@ -313,6 +311,34 @@ agent = Agent(
313
311
)
314
312
```
315
313
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=lambdaspan: 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
+
316
342
## Best Practices
317
343
318
344
1.**Use appropriate detail level**: Balance between capturing enough information and avoiding excessive data
0 commit comments