Skip to content

Commit

Permalink
fix: posthog to None if disabled (#2989)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matvey-Kuk authored Jan 6, 2025
1 parent ee49e7c commit 84aa526
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
16 changes: 9 additions & 7 deletions keep/api/core/posthog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@

POSTHOG_DISABLED = os.getenv("POSTHOG_DISABLED", "false").lower() == "true"

if POSTHOG_DISABLED:
posthog.disabled = True

POSTHOG_API_KEY = (
os.getenv("POSTHOG_API_KEY")
or "phc_muk9qE3TfZsX3SZ9XxX52kCGJBclrjhkP9JxAQcm1PZ" # It's a public PH API key, not a leaked secret ;)
)
posthog_client = Posthog(
api_key=POSTHOG_API_KEY,
host="https://app.posthog.com",
)

if POSTHOG_DISABLED:
posthog.disabled = True
posthog_client = None
else:
posthog_client = Posthog(
api_key=POSTHOG_API_KEY,
host="https://app.posthog.com",
)


def is_posthog_reachable():
Expand Down
19 changes: 10 additions & 9 deletions keep/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,15 @@ def cli(ctx, info: Info, verbose: int, json: bool, keep_config: str):
# https://posthog.com/tutorials/identifying-users-guide#identifying-and-setting-user-ids-for-every-other-library
# random user id
info.set_config(keep_config)
posthog_client.capture(
info.random_user_id,
"keep-cli-started",
properties={
"args": sys.argv,
"keep_version": KEEP_VERSION,
},
)
if posthog_client is not None:
posthog_client.capture(
info.random_user_id,
"keep-cli-started",
properties={
"args": sys.argv,
"keep_version": KEEP_VERSION,
},
)
# Use the verbosity count to determine the logging level...
if verbose > 0:
# set the verbosity level to debug
Expand All @@ -208,7 +209,7 @@ def cli(ctx, info: Info, verbose: int, json: bool, keep_config: str):

@ctx.call_on_close
def cleanup():
if posthog_client:
if posthog_client is not None:
posthog_client.flush()


Expand Down

0 comments on commit 84aa526

Please sign in to comment.