mirror of
https://github.com/trycua/computer.git
synced 2026-01-05 12:59:58 -06:00
Format codebase with uv run pre-commit run --all-files
This commit is contained in:
@@ -8,10 +8,11 @@
|
||||
</picture>
|
||||
</div>
|
||||
|
||||
[](#)
|
||||
[](#)
|
||||
[](https://discord.com/invite/mVnXXpdE85)
|
||||
[](https://pypi.org/project/cua-core/)
|
||||
[](#)
|
||||
[](#)
|
||||
[](https://discord.com/invite/mVnXXpdE85)
|
||||
[](https://pypi.org/project/cua-core/)
|
||||
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
@@ -25,4 +26,4 @@
|
||||
|
||||
```bash
|
||||
pip install cua-core
|
||||
```
|
||||
```
|
||||
|
||||
@@ -4,12 +4,11 @@ It provides a low-overhead way to collect anonymous usage data.
|
||||
"""
|
||||
|
||||
from core.telemetry.posthog import (
|
||||
record_event,
|
||||
is_telemetry_enabled,
|
||||
destroy_telemetry_client,
|
||||
is_telemetry_enabled,
|
||||
record_event,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"record_event",
|
||||
"is_telemetry_enabled",
|
||||
|
||||
@@ -4,8 +4,8 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import uuid
|
||||
import sys
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
@@ -20,6 +20,7 @@ logger = logging.getLogger("core.telemetry")
|
||||
PUBLIC_POSTHOG_API_KEY = "phc_eSkLnbLxsnYFaXksif1ksbrNzYlJShr35miFLDppF14"
|
||||
PUBLIC_POSTHOG_HOST = "https://eu.i.posthog.com"
|
||||
|
||||
|
||||
class PostHogTelemetryClient:
|
||||
"""Collects and reports telemetry data via PostHog."""
|
||||
|
||||
@@ -47,7 +48,8 @@ class PostHogTelemetryClient:
|
||||
# Legacy opt-out flag
|
||||
os.environ.get("CUA_TELEMETRY", "").lower() != "off"
|
||||
# Opt-in flag (defaults to enabled)
|
||||
and os.environ.get("CUA_TELEMETRY_ENABLED", "true").lower() in { "1", "true", "yes", "on" }
|
||||
and os.environ.get("CUA_TELEMETRY_ENABLED", "true").lower()
|
||||
in {"1", "true", "yes", "on"}
|
||||
)
|
||||
|
||||
def _get_or_create_installation_id(self) -> str:
|
||||
@@ -150,14 +152,12 @@ class PostHogTelemetryClient:
|
||||
logger.debug(
|
||||
f"Setting up PostHog user properties for: {self.installation_id} with properties: {properties}"
|
||||
)
|
||||
|
||||
|
||||
# In the Python SDK, we capture an identification event instead of calling identify()
|
||||
posthog.capture(
|
||||
distinct_id=self.installation_id,
|
||||
event="$identify",
|
||||
properties={"$set": properties}
|
||||
distinct_id=self.installation_id, event="$identify", properties={"$set": properties}
|
||||
)
|
||||
|
||||
|
||||
logger.info(f"Set up PostHog user properties for installation: {self.installation_id}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to set up PostHog user properties: {e}")
|
||||
@@ -224,13 +224,16 @@ class PostHogTelemetryClient:
|
||||
"""Destroy the global PostHogTelemetryClient instance."""
|
||||
cls._singleton = None
|
||||
|
||||
|
||||
def destroy_telemetry_client() -> None:
|
||||
"""Destroy the global PostHogTelemetryClient instance (class-managed)."""
|
||||
PostHogTelemetryClient.destroy_client()
|
||||
|
||||
|
||||
def is_telemetry_enabled() -> bool:
|
||||
return PostHogTelemetryClient.is_telemetry_enabled()
|
||||
|
||||
|
||||
def record_event(event_name: str, properties: Optional[Dict[str, Any]] | None = None) -> None:
|
||||
"""Record an arbitrary PostHog event."""
|
||||
PostHogTelemetryClient.get_client().record_event(event_name, properties or {})
|
||||
PostHogTelemetryClient.get_client().record_event(event_name, properties or {})
|
||||
|
||||
Reference in New Issue
Block a user