fix: posthog init and shutdown

This commit is contained in:
NanoCode012
2025-10-27 15:51:30 +07:00
parent f147a9370c
commit 4193c4bdcb

View File

@@ -10,10 +10,10 @@ import uuid
from pathlib import Path
from typing import Any
import posthog
import psutil
import torch
import yaml
from posthog import PostHog
LOG = logging.getLogger(__name__)
@@ -240,8 +240,7 @@ class TelemetryManager:
def _init_posthog(self):
"""Initialize PostHog client"""
posthog.host = POSTHOG_HOST
posthog.project_api_key = POSTHOG_WRITE_KEY
self.posthog = PostHog(POSTHOG_WRITE_KEY, host=POSTHOG_HOST)
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
try:
# Send event via PostHog
posthog.capture(
self.posthog.capture(
distinct_id=self.run_id,
event=event_type,
properties=properties,
@@ -412,4 +411,4 @@ class TelemetryManager:
def shutdown(self):
"""Ensure all queued events are processed before shutdown"""
if self.enabled:
posthog.flush()
self.posthog.shutdown()