@@ -18,8 +18,7 @@ class Posthog:
18
18
19
19
RUN_EVENT = "run"
20
20
DAILY_EVENT = "daily"
21
-
22
- TEST_UUID = "test"
21
+ _should_capture = False
23
22
_identified_uuid : Optional [str ] = None
24
23
25
24
@classmethod
@@ -42,29 +41,24 @@ def _identify(cls):
42
41
logger .info (f"Skipping identify due to already identified UUID { cls ._identified_uuid } " )
43
42
return
44
43
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" )
55
46
return
56
47
57
- if existing_uuid is None :
48
+ user_uuid = cls ._read_uuid_file ()
49
+ if user_uuid is None :
58
50
new_uuid = str (uuid .uuid4 ())
59
51
logger .info (f"Generated new UUID: { new_uuid } " )
60
52
cls ._create_uuid_file (new_uuid )
61
- cls . _identified_uuid = new_uuid
53
+ user_uuid = new_uuid
62
54
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 } " )
65
56
66
57
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
68
62
except Exception as e :
69
63
logger .exception ("Failed to identify posthog UUID" )
70
64
@@ -73,12 +67,7 @@ def _capture(cls, event: str):
73
67
if cls ._identified_uuid is None :
74
68
cls ._identify ()
75
69
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 :
82
71
return
83
72
84
73
try :
0 commit comments