1+ #!/usr/bin/env python3
2+ """
3+ Test PostHog integration after fix.
4+ """
5+
6+ import os
7+ import time
8+
9+ # Ensure telemetry is enabled
10+ for var in ['PRAISONAI_TELEMETRY_DISABLED' , 'PRAISONAI_DISABLE_TELEMETRY' , 'DO_NOT_TRACK' ]:
11+ if var in os .environ :
12+ del os .environ [var ]
13+
14+ print ("=== Testing PostHog Fix ===\n " )
15+
16+ # Test PostHog directly first
17+ print ("1. Testing PostHog directly:" )
18+ try :
19+ from posthog import Posthog
20+
21+ # Create PostHog client
22+ ph = Posthog (
23+ project_api_key = 'phc_skZpl3eFLQJ4iYjsERNMbCO6jfeSJi2vyZlPahKgxZ7' ,
24+ host = 'https://eu.i.posthog.com'
25+ )
26+
27+ # Send test event
28+ ph .capture ('test-user' , 'direct_test' , {'timestamp' : time .time ()})
29+
30+ # Flush and shutdown properly
31+ ph .flush ()
32+ ph .shutdown ()
33+
34+ print ("✓ Direct PostHog test successful\n " )
35+ except Exception as e :
36+ print (f"✗ Direct PostHog test failed: { e } \n " )
37+
38+ # Test telemetry module
39+ print ("2. Testing telemetry module:" )
40+ from praisonaiagents .telemetry .telemetry import MinimalTelemetry
41+
42+ # Create telemetry instance
43+ telemetry = MinimalTelemetry (enabled = True )
44+
45+ # Track events
46+ telemetry .track_agent_execution ("TestAgent" , success = True )
47+ telemetry .track_task_completion ("TestTask" , success = True )
48+ telemetry .track_tool_usage ("TestTool" , success = True )
49+
50+ print (f"✓ Events tracked" )
51+ print (f"✓ PostHog client available: { telemetry ._posthog is not None } " )
52+
53+ # Flush
54+ print ("\n 3. Flushing telemetry..." )
55+ telemetry .flush ()
56+ print ("✓ Flush completed" )
57+
58+ # Shutdown
59+ print ("\n 4. Shutting down telemetry..." )
60+ telemetry .shutdown ()
61+ print ("✓ Shutdown completed" )
62+
63+ print ("\n === Test Complete ===" )
64+ print ("\n PostHog should now be receiving data properly!" )
65+ print ("The fix adds:" )
66+ print ("1. posthog.flush() call in the flush() method" )
67+ print ("2. shutdown() method that properly closes the connection" )
0 commit comments