Skip to main content

Telemetry Module

The Telemetry Module provides comprehensive monitoring and observability features for PraisonAI agents.

Installation

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.
Returns:
  • MinimalTelemetry: The global telemetry instance. Always returns an instance (never None). Check .enabled to see if telemetry is active.
Example:

enable_telemetry

Programmatically enables telemetry. If an environment opt-out variable is set, this call is a no-op.
Returns: None
Precedence: Explicit environment opt-out always wins over programmatic calls. Setting DO_NOT_TRACK=true (or any *_DISABLED flag) makes enable_telemetry() a no-op. Otherwise, telemetry is off by default until enable_telemetry() is called or an opt-in env var is exported.
Example:

disable_telemetry

Programmatically disables telemetry. Instrumentation hooks stop installing after this call.
Returns: None Example:

Classes

MinimalTelemetry

A lightweight telemetry collector that captures essential metrics only.
Methods:

record_metric

Records a custom metric.
Parameters:
  • name (str): Metric name
  • value (Union[int, float]): Metric value
  • unit (str, optional): Unit of measurement
  • labels (Dict[str, str], optional): Additional labels for the metric

record_event

Records a custom event.
Parameters:
  • name (str): Event name
  • attributes (Dict[str, Any], optional): Event attributes
Example:

TelemetryCollector

Full-featured telemetry collector with advanced capabilities.
Parameters:
  • service_name (str, optional): Name of the service. Defaults to “praisonai”
  • service_version (str, optional): Service version
  • export_endpoint (str, optional): OpenTelemetry export endpoint
  • export_interval (int, optional): Export interval in seconds
  • enable_traces (bool, optional): Enable trace collection. Defaults to True
  • enable_metrics (bool, optional): Enable metrics collection. Defaults to True
  • enable_logs (bool, optional): Enable log collection. Defaults to True
Methods:

start_span

Starts a new telemetry span for tracing.
Parameters:
  • name (str): Span name
  • kind (str, optional): Span kind (“internal”, “client”, “server”). Defaults to “internal”
  • attributes (Dict[str, Any], optional): Span attributes

record_agent_execution

Records agent execution metrics.
Parameters:
  • agent_name (str): Name of the agent
  • duration (float): Execution duration in seconds
  • status (str): Execution status (“success”, “failure”, “partial”)
  • error (str, optional): Error message if failed
  • metadata (Dict[str, Any], optional): Additional metadata

record_tool_usage

Records tool usage metrics.
Parameters:
  • tool_name (str): Name of the tool
  • agent_name (str): Name of the agent using the tool
  • duration (float): Tool execution duration
  • success (bool): Whether the tool execution was successful
  • parameters (Dict[str, Any], optional): Tool parameters (if include_prompts is enabled)

export_metrics

Manually triggers metric export.

shutdown

Gracefully shuts down the telemetry collector.
Example:

Environment Variables

Telemetry behavior is controlled by these environment variables: Opt-in (enables telemetry when set to true):
  • PRAISONAI_TELEMETRY_ENABLED=true
  • PRAISONAI_PERFORMANCE_ENABLED=true
Opt-out (disables telemetry; always wins over programmatic calls):
  • PRAISONAI_TELEMETRY_DISABLED=true
  • PRAISONAI_DISABLE_TELEMETRY=true
  • PRAISONAI_PERFORMANCE_DISABLED=true
  • DO_NOT_TRACK=true
Precedence: env opt-out > programmatic override > cached env-default

Privacy and Security

  1. No PII by Default: Telemetry does not collect personally identifiable information
  2. Opt-in for Content: Prompt and result content is only collected if explicitly enabled
  3. Local First: Telemetry data stays local unless an export endpoint is configured
  4. Minimal by Default: Default configuration collects only essential metrics

Example: Complete Telemetry Setup

Integration with Observability Platforms

For OpenTelemetry, Langfuse, and Prometheus integrations, see the Observability documentation.

Best Practices

  1. Start Minimal: Begin with minimal telemetry and increase as needed
  2. Respect Privacy: Never enable prompt/result collection without user consent
  3. Monitor Performance: Use telemetry to identify bottlenecks and optimize
  4. Set Up Alerts: Configure alerts for critical metrics
  5. Regular Reviews: Periodically review collected metrics for insights
  6. Graceful Shutdown: Always call shutdown() in production applications

See Also