From 1dc2d69f1671072e325cbe9cda13e99ddf719620 Mon Sep 17 00:00:00 2001 From: James Murdza Date: Mon, 11 Aug 2025 08:50:57 -0400 Subject: [PATCH] Remove unused functions --- .../core/core/telemetry/posthog_client.py | 58 +------------------ libs/python/core/core/telemetry/telemetry.py | 40 +------------ 2 files changed, 2 insertions(+), 96 deletions(-) diff --git a/libs/python/core/core/telemetry/posthog_client.py b/libs/python/core/core/telemetry/posthog_client.py index 788f59b9..0643de9a 100644 --- a/libs/python/core/core/telemetry/posthog_client.py +++ b/libs/python/core/core/telemetry/posthog_client.py @@ -213,41 +213,6 @@ class PostHogTelemetryClient: logger.warning("Using random installation ID (will not persist across runs)") return str(uuid.uuid4()) - def increment(self, counter_name: str, value: int = 1) -> None: - """Increment a named counter. - - Args: - counter_name: Name of the counter - value: Amount to increment by (default: 1) - """ - if not self.config.enabled: - return - - # Apply sampling to reduce number of events - if random.random() * 100 > self.config.sample_rate: - return - - properties = { - "value": value, - "counter_name": counter_name, - "version": __version__, - } - - if self.initialized: - try: - posthog.capture( - distinct_id=self.installation_id, - event="counter_increment", - properties=properties, - ) - except Exception as e: - logger.debug(f"Failed to send counter event to PostHog: {e}") - else: - # Queue the event for later - self.queued_events.append({"event": "counter_increment", "properties": properties}) - # Try to initialize now if not already - self._initialize_posthog() - def record_event(self, event_name: str, properties: Optional[Dict[str, Any]] = None) -> None: """Record an event with optional properties. @@ -307,21 +272,6 @@ class PostHogTelemetryClient: logger.debug(f"Failed to flush PostHog events: {e}") return False - def enable(self) -> None: - """Enable telemetry collection.""" - self.config.enabled = True - if posthog: - posthog.disabled = False - logger.info("Telemetry enabled") - self._initialize_posthog() - - def disable(self) -> None: - """Disable telemetry collection.""" - self.config.enabled = False - if posthog: - posthog.disabled = True - logger.info("Telemetry disabled") - # Global telemetry client instance _client: Optional[PostHogTelemetryClient] = None @@ -338,10 +288,4 @@ def get_posthog_telemetry_client() -> PostHogTelemetryClient: if _client is None: _client = PostHogTelemetryClient() - return _client - - -def disable_telemetry() -> None: - """Disable telemetry collection globally.""" - if _client is not None: - _client.disable() + return _client \ No newline at end of file diff --git a/libs/python/core/core/telemetry/telemetry.py b/libs/python/core/core/telemetry/telemetry.py index b8608caf..300e036d 100644 --- a/libs/python/core/core/telemetry/telemetry.py +++ b/libs/python/core/core/telemetry/telemetry.py @@ -5,7 +5,6 @@ Usage: from core.telemetry import record_event, increment record_event("my_event", {"foo": "bar"}) - increment("my_counter") Configuration: • Disable telemetry globally by setting the environment variable @@ -90,45 +89,8 @@ def is_telemetry_enabled() -> bool: _ensure_client() return _ENABLED and not _telemetry_disabled() - -def enable() -> None: - """Enable telemetry collection for this process (unless globally disabled).""" - global _ENABLED - - if _telemetry_disabled(): - _LOGGER.info("Telemetry has been disabled via environment variable.") - return - - _ensure_client() - if _CLIENT: - _CLIENT.enable() - _ENABLED = True - - -def disable() -> None: - """Disable telemetry for this process.""" - global _ENABLED - - if _CLIENT: - _CLIENT.disable() - _ENABLED = False - - def record_event(event_name: str, properties: Optional[Dict[str, Any]] | None = None) -> None: """Send an arbitrary PostHog event.""" _ensure_client() if _CLIENT and _ENABLED: - _CLIENT.record_event(event_name, properties or {}) - - -def increment(counter_name: str, value: int = 1) -> None: - """Increment a named counter.""" - _ensure_client() - if _CLIENT and _ENABLED: - _CLIENT.increment(counter_name, value) - - -def flush() -> bool: - """Flush any queued analytics events to PostHog.""" - _ensure_client() - return bool(_CLIENT and _ENABLED and _CLIENT.flush()) + _CLIENT.record_event(event_name, properties or {}) \ No newline at end of file