fix: posthog init and shutdown
This commit is contained in:
@@ -10,10 +10,10 @@ import uuid
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import posthog
|
|
||||||
import psutil
|
import psutil
|
||||||
import torch
|
import torch
|
||||||
import yaml
|
import yaml
|
||||||
|
from posthog import PostHog
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -240,8 +240,7 @@ class TelemetryManager:
|
|||||||
|
|
||||||
def _init_posthog(self):
|
def _init_posthog(self):
|
||||||
"""Initialize PostHog client"""
|
"""Initialize PostHog client"""
|
||||||
posthog.host = POSTHOG_HOST
|
self.posthog = PostHog(POSTHOG_WRITE_KEY, host=POSTHOG_HOST)
|
||||||
posthog.project_api_key = POSTHOG_WRITE_KEY
|
|
||||||
|
|
||||||
def _redact_paths(self, properties: dict[str, Any]) -> dict[str, Any]:
|
def _redact_paths(self, properties: dict[str, Any]) -> dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
@@ -390,7 +389,7 @@ class TelemetryManager:
|
|||||||
# Wrap PostHog errors in try / except to not raise errors during Axolotl usage
|
# Wrap PostHog errors in try / except to not raise errors during Axolotl usage
|
||||||
try:
|
try:
|
||||||
# Send event via PostHog
|
# Send event via PostHog
|
||||||
posthog.capture(
|
self.posthog.capture(
|
||||||
distinct_id=self.run_id,
|
distinct_id=self.run_id,
|
||||||
event=event_type,
|
event=event_type,
|
||||||
properties=properties,
|
properties=properties,
|
||||||
@@ -412,4 +411,4 @@ class TelemetryManager:
|
|||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
"""Ensure all queued events are processed before shutdown"""
|
"""Ensure all queued events are processed before shutdown"""
|
||||||
if self.enabled:
|
if self.enabled:
|
||||||
posthog.flush()
|
self.posthog.shutdown()
|
||||||
|
|||||||
Reference in New Issue
Block a user