Skip to content

Commit

Permalink
Add debug mode to Posthog (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
NolanTrem authored and emrgnt-cmplxty committed Jun 21, 2024
1 parent 6054cd2 commit 954ec84
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions r2r/telemetry/posthog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,25 @@ class PosthogClient:
read events or any of your other data stored with PostHog, so it's safe to use in public apps.
"""

def __init__(self, api_key: str, enabled: bool = True):
def __init__(
self, api_key: str, enabled: bool = True, debug: bool = False
):
self.enabled = enabled
self.debug = debug

if self.enabled:
logger.info(
"Initializing anonymized telemetry. To disable, set TELEMETRY_ENABLED=false in your environment."
)
posthog.project_api_key = api_key
else:
posthog.disabled = True

if self.debug:
posthog.debug = True

logger.info(
f"Posthog telemetry {'enabled' if self.enabled else 'disabled'}"
f"Posthog telemetry {'enabled' if self.enabled else 'disabled'}, debug mode {'on' if self.debug else 'off'}"
)

def capture(self, event: BaseTelemetryEvent):
Expand All @@ -38,6 +46,11 @@ def capture(self, event: BaseTelemetryEvent):
"1",
"t",
)
debug_mode = os.getenv("DEBUG_MODE", "false").lower() in (
"true",
"1",
"t",
)
telemetry_client = PosthogClient(
api_key="phc_OPBbibOIErCGc4NDLQsOrMuYFTKDmRwXX6qxnTr6zpU",
enabled=telemetry_enabled,
Expand Down

0 comments on commit 954ec84

Please sign in to comment.