ragas icon indicating copy to clipboard operation
ragas copied to clipboard

fix(analytics): run telemetry in daemon thread to prevent DNS blocking

Open aashishkumar-tech opened this issue 6 months ago • 1 comments

Summary

When t.explodinggradients.com cannot be resolved (e.g. in CI or air-gapped environments), DNS retry delays block the main evaluation thread for 15–30s per track() call, causing severe slowdowns and timeouts.

Root Cause

requests.post(..., timeout=1) only covers TCP connect + read. DNS resolution happens before a socket is opened and is completely unaffected by the timeout parameter.

Changes

  • src/ragas/_analytics.py: wrap requests.post() in a daemon thread so telemetry is fire-and-forget and never blocks evaluation
  • src/ragas/_analytics.py: add support for standard do-not-track env vars (DO_NOT_TRACK=1, DISABLE_TELEMETRY=1, RAGAS_ANALYTICS_ENABLED=false, RAGAS_TELEMETRY_ENABLED=false)
  • tests/unit/test_analytics.py: add regression tests for both fixes

Testing

  • test_do_not_track_standard_env_vars — verifies all 4 new env vars correctly disable telemetry
  • test_track_runs_in_daemon_thread — verifies track() uses a daemon thread
  • test_track_dns_failure_does_not_block — simulates 10s DNS hang, verifies main thread returns in under 1s

Fixes #2751 Closes #2603

aashishkumar-tech avatar Jun 01 '26 00:06 aashishkumar-tech

✅ No documentation update needed — Internal bug fix for telemetry: runs in daemon thread to prevent DNS blocking and adds standard do-not-track env var support. No user-facing API changes; env var names are internal opt-out flags that don't require documentation updates.

github-actions[bot] avatar Jun 01 '26 00:06 github-actions[bot]