Skip to content

Commit 2ff83b7

Browse files
committed
fix telemetry.py
1 parent d923c02 commit 2ff83b7

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ COPY ./app/requirements.txt /tmp/requirements.txt
66

77
RUN pip install -r /tmp/requirements.txt
88

9+
ENV CAPTURE_TELEMETRY=1
10+
911
COPY ./app/models.py /tmp/models.py
1012

1113
# cache the models

app/telemetry.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class Posthog:
1818

1919
RUN_EVENT = "run"
2020
DAILY_EVENT = "daily"
21-
22-
TEST_UUID = "test"
21+
_should_capture = False
2322
_identified_uuid: Optional[str] = None
2423

2524
@classmethod
@@ -42,29 +41,24 @@ def _identify(cls):
4241
logger.info(f"Skipping identify due to already identified UUID {cls._identified_uuid}")
4342
return
4443

45-
if os.environ.get('TEST') == "1":
46-
cls._create_uuid_file(cls.TEST_UUID)
47-
cls._identified_uuid = cls.TEST_UUID
48-
logger.info("Identified as test UUID")
49-
return
50-
51-
existing_uuid = cls._read_uuid_file()
52-
if cls.TEST_UUID in existing_uuid:
53-
cls._identified_uuid = cls.TEST_UUID
54-
logger.info("Identified as test UUID")
44+
if not os.environ.get('CAPTURE_TELEMETRY'):
45+
logger.info("Skipping identify due to CAPTURE_TELEMETRY not being set")
5546
return
5647

57-
if existing_uuid is None:
48+
user_uuid = cls._read_uuid_file()
49+
if user_uuid is None:
5850
new_uuid = str(uuid.uuid4())
5951
logger.info(f"Generated new UUID: {new_uuid}")
6052
cls._create_uuid_file(new_uuid)
61-
cls._identified_uuid = new_uuid
53+
user_uuid = new_uuid
6254
else:
63-
cls._identified_uuid = existing_uuid
64-
logger.info(f"Using existing UUID: {cls._identified_uuid}")
55+
logger.info(f"Using existing UUID: {user_uuid}")
6556

6657
try:
67-
posthog.identify(cls._identified_uuid)
58+
posthog.api_key = cls.API_KEY
59+
posthog.host = cls.HOST
60+
posthog.identify(user_uuid)
61+
cls._identified_uuid = user_uuid
6862
except Exception as e:
6963
logger.exception("Failed to identify posthog UUID")
7064

@@ -73,12 +67,7 @@ def _capture(cls, event: str):
7367
if cls._identified_uuid is None:
7468
cls._identify()
7569

76-
if cls._identified_uuid is None:
77-
logger.error(f"Failed to identify UUID, skipping event {event}")
78-
return
79-
80-
if cls._identified_uuid == cls.TEST_UUID:
81-
logger.info(f"Skipping event {event} due to test UUID")
70+
if not cls._should_capture:
8271
return
8372

8473
try:

0 commit comments

Comments
 (0)