feat(telemetry): add daily base heartbeat and trigger opt-in ping on enable

- Register send_base_telemetry_heartbeat_with_app cron at 03:00 UTC
- setup: call check_and_send_telemetry when user opts in during setup
- admin: call check_and_send_telemetry when toggling detailed analytics on
This commit is contained in:
Dries Peeters
2026-03-16 13:01:09 +01:00
parent 287020d30c
commit cd0ccd61c7
3 changed files with 41 additions and 1 deletions
+8 -1
View File
@@ -1086,7 +1086,14 @@ def toggle_telemetry():
installation_config.set_telemetry_preference(new_state)
# Log the change
if new_state:
try:
from app.utils.telemetry import check_and_send_telemetry
check_and_send_telemetry()
except Exception:
pass
app_module.log_event("admin.telemetry_toggled", user_id=current_user.id, new_state=new_state)
app_module.track_event(current_user.id, "admin.telemetry_toggled", {"enabled": new_state})
+6
View File
@@ -116,6 +116,12 @@ def initial_setup():
)
if telemetry_enabled:
try:
from app.utils.telemetry import check_and_send_telemetry
check_and_send_telemetry()
except Exception:
pass
flash(_("Setup complete! Thank you for helping us improve TimeTracker."), "success")
else:
flash(_("Setup complete! Telemetry is disabled."), "success")
+27
View File
@@ -591,6 +591,33 @@ def register_scheduled_tasks(scheduler, app=None):
)
logger.info("Registered remind-to-log task")
# Base telemetry heartbeat (daily) always-on minimal install footprint
def send_base_telemetry_heartbeat_with_app():
app_instance = app
if app_instance is None:
try:
app_instance = current_app._get_current_object()
except RuntimeError:
return
with app_instance.app_context():
try:
from app.telemetry.service import send_base_heartbeat
send_base_heartbeat()
except Exception:
pass
scheduler.add_job(
func=send_base_telemetry_heartbeat_with_app,
trigger="cron",
hour=3,
minute=0,
id="send_base_telemetry_heartbeat",
name="Base telemetry heartbeat",
replace_existing=True,
)
logger.info("Registered base telemetry heartbeat task")
except Exception as e:
logger.error(f"Error registering scheduled tasks: {e}")