Easy self-onboarding has been hardest to get right in complex business apps, even though we have worked on this for long long time we have no clear idea on how well it works, or if it's severly lacking. We want to improve this by first understanding how efficient current system is. This PR adds basic telemetry for which steps are being completed, which are skipped and what onboarding group is dismissed completely.
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
""" Basic telemetry for improving apps.
|
|
|
|
WARNING: Everything in this file should be treated "internal" and is subjected to change or get
|
|
removed without any warning.
|
|
"""
|
|
from contextlib import suppress
|
|
|
|
from posthog import Posthog
|
|
|
|
import frappe
|
|
|
|
POSTHOG_PROJECT_FIELD = "posthog_project_id"
|
|
POSTHOG_HOST_FIELD = "posthog_host"
|
|
|
|
|
|
def add_bootinfo(bootinfo):
|
|
if not frappe.get_system_settings("enable_telemetry"):
|
|
return
|
|
|
|
bootinfo.posthog_host = frappe.conf.get(POSTHOG_HOST_FIELD)
|
|
bootinfo.posthog_project_id = frappe.conf.get(POSTHOG_PROJECT_FIELD)
|
|
bootinfo.enable_telemetry = True
|
|
|
|
|
|
def init_telemetry():
|
|
"""Init posthog for server side telemetry."""
|
|
if hasattr(frappe.local, "posthog"):
|
|
return
|
|
|
|
if not frappe.get_system_settings("enable_telemetry"):
|
|
return
|
|
|
|
posthog_host = frappe.conf.get(POSTHOG_HOST_FIELD)
|
|
posthog_project_id = frappe.conf.get(POSTHOG_PROJECT_FIELD)
|
|
|
|
if not posthog_host or not posthog_project_id:
|
|
return
|
|
|
|
with suppress(Exception):
|
|
frappe.local.posthog = Posthog(posthog_project_id, host=posthog_host)
|
|
|
|
|
|
def capture(event, app, **kwargs):
|
|
init_telemetry()
|
|
ph: Posthog = getattr(frappe.local, "posthog", None)
|
|
with suppress(Exception):
|
|
ph and ph.capture(distinct_id=frappe.local.site, event=f"{app}_{event}", **kwargs)
|