refactor: disable Mixpanel and add PostHog error handling

This commit is contained in:
Paul Gauthier 2024-12-04 11:46:27 -08:00 committed by Paul Gauthier (aider)
parent 26ddb1e479
commit ff5a947a16

View file

@ -50,8 +50,10 @@ class Analytics:
self.disable(False)
return
self.mp = Mixpanel(mixpanel_project_token)
self.ph = Posthog(project_api_key=posthog_project_api_key, host=posthog_host)
# self.mp = Mixpanel(mixpanel_project_token)
self.ph = Posthog(
project_api_key=posthog_project_api_key, host=posthog_host, on_error=self.posthog_error
)
def disable(self, permanently):
self.mp = None
@ -172,6 +174,12 @@ class Analytics:
return model.name.split("/")[0] + "/REDACTED"
return None
def posthog_error(self):
"""disable posthog if we get an error"""
# https://github.com/PostHog/posthog-python/blob/9e1bb8c58afaa229da24c4fb576c08bb88a75752/posthog/consumer.py#L86
# https://github.com/Aider-AI/aider/issues/2532
self.ph = None
def event(self, event_name, main_model=None, **kwargs):
if not self.mp and not self.ph and not self.logfile:
return