Telemetry API
The Telemetry API provides comprehensive monitoring and observability features for PraisonAI agents. It allows you to track performance metrics, usage patterns, and system behavior while maintaining privacy.Import
Telemetry features require installation with the telemetry extra:
pip install praisonaiagents[telemetry]
Functions
get_telemetry
Retrieves the current telemetry instance.Optional[TelemetryCollector]
: The current telemetry collector instance, or None if telemetry is disabled
enable_telemetry
Enables telemetry collection with specified configuration.level
(str, optional): Telemetry level (“minimal”, “basic”, “detailed”). Defaults to “minimal”custom_collector
(TelemetryCollector, optional): Custom telemetry collector instanceexport_endpoint
(str, optional): Endpoint for exporting telemetry dataexport_interval
(int, optional): Export interval in seconds. Defaults to 60include_prompts
(bool, optional): Include prompt content in telemetry. Defaults to Falseinclude_results
(bool, optional): Include result content in telemetry. Defaults to False
TelemetryCollector
: The enabled telemetry collector instance
"minimal"
: Basic metrics only (counts, timings)"basic"
: Includes error information and performance metrics"detailed"
: Full telemetry including traces and detailed metrics
disable_telemetry
Disables telemetry collection completely.Classes
MinimalTelemetry
A lightweight telemetry collector that captures essential metrics only.record_metric
Records a custom metric.name
(str): Metric namevalue
(Union[int, float]): Metric valueunit
(str, optional): Unit of measurementlabels
(Dict[str, str], optional): Additional labels for the metric
record_event
Records a custom event.name
(str): Event nameattributes
(Dict[str, Any], optional): Event attributes
TelemetryCollector
Full-featured telemetry collector with advanced capabilities.service_name
(str, optional): Name of the service. Defaults to “praisonai”service_version
(str, optional): Service versionexport_endpoint
(str, optional): OpenTelemetry export endpointexport_interval
(int, optional): Export interval in secondsenable_traces
(bool, optional): Enable trace collection. Defaults to Trueenable_metrics
(bool, optional): Enable metrics collection. Defaults to Trueenable_logs
(bool, optional): Enable log collection. Defaults to True
start_span
Starts a new telemetry span for tracing.name
(str): Span namekind
(str, optional): Span kind (“internal”, “client”, “server”). Defaults to “internal”attributes
(Dict[str, Any], optional): Span attributes
record_agent_execution
Records agent execution metrics.agent_name
(str): Name of the agentduration
(float): Execution duration in secondsstatus
(str): Execution status (“success”, “failure”, “partial”)error
(str, optional): Error message if failedmetadata
(Dict[str, Any], optional): Additional metadata
record_tool_usage
Records tool usage metrics.tool_name
(str): Name of the toolagent_name
(str): Name of the agent using the toolduration
(float): Tool execution durationsuccess
(bool): Whether the tool execution was successfulparameters
(Dict[str, Any], optional): Tool parameters (if include_prompts is enabled)
export_metrics
Manually triggers metric export.shutdown
Gracefully shuts down the telemetry collector.Environment Variables
Telemetry behavior can be configured via environment variables:PRAISONAI_TELEMETRY_ENABLED
: Enable/disable telemetry (“true”/“false”)PRAISONAI_TELEMETRY_LEVEL
: Set telemetry level (“minimal”/“basic”/“detailed”)PRAISONAI_TELEMETRY_ENDPOINT
: Set export endpointPRAISONAI_TELEMETRY_EXPORT_INTERVAL
: Set export interval in secondsPRAISONAI_TELEMETRY_INCLUDE_PROMPTS
: Include prompts in telemetry (“true”/“false”)PRAISONAI_TELEMETRY_INCLUDE_RESULTS
: Include results in telemetry (“true”/“false”)
Privacy and Security
- No PII by Default: Telemetry does not collect personally identifiable information
- Opt-in for Content: Prompt and result content is only collected if explicitly enabled
- Local First: Telemetry data stays local unless an export endpoint is configured
- Minimal by Default: Default configuration collects only essential metrics
Example: Complete Telemetry Setup
Integration with Observability Platforms
PraisonAI telemetry is compatible with OpenTelemetry and can export to:- Prometheus: Metrics collection and alerting
- Jaeger: Distributed tracing
- Grafana: Visualization and dashboards
- Datadog: Full-stack monitoring
- New Relic: Application performance monitoring
- CloudWatch: AWS monitoring service
Example: Prometheus Integration
Best Practices
- Start Minimal: Begin with minimal telemetry and increase as needed
- Respect Privacy: Never enable prompt/result collection without user consent
- Monitor Performance: Use telemetry to identify bottlenecks and optimize
- Set Up Alerts: Configure alerts for critical metrics
- Regular Reviews: Periodically review collected metrics for insights
- Graceful Shutdown: Always call shutdown() in production applications