1+ #!/usr/bin/env python3
2+ """
3+ Debug telemetry instrumentation to see what's happening.
4+ """
5+
6+ import os
7+ # Make sure telemetry is enabled
8+ if 'PRAISONAI_TELEMETRY_DISABLED' in os .environ :
9+ del os .environ ['PRAISONAI_TELEMETRY_DISABLED' ]
10+
11+ print ("1. Importing modules..." )
12+ from praisonaiagents import Agent , Task , PraisonAIAgents
13+ from praisonaiagents .telemetry import get_telemetry
14+
15+ print ("\n 2. Checking telemetry status..." )
16+ telemetry = get_telemetry ()
17+ print (f"Telemetry enabled: { telemetry .enabled } " )
18+ print (f"PostHog available: { telemetry ._posthog is not None } " )
19+
20+ print ("\n 3. Creating agent..." )
21+ agent = Agent (
22+ name = "TestAgent" ,
23+ role = "Test Role" ,
24+ goal = "Test Goal" ,
25+ instructions = "Test instructions"
26+ )
27+
28+ # Check if agent.execute is instrumented
29+ print (f"\n 4. Checking agent instrumentation..." )
30+ print (f"Agent has execute method: { hasattr (agent , 'execute' )} " )
31+ if hasattr (agent , 'execute' ):
32+ print (f"Execute method type: { type (agent .execute )} " )
33+ print (f"Execute method name: { agent .execute .__name__ if hasattr (agent .execute , '__name__' ) else 'No name' } " )
34+ print (f"Is wrapped: { 'instrumented' in str (agent .execute .__name__ ) if hasattr (agent .execute , '__name__' ) else 'Unknown' } " )
35+
36+ print ("\n 5. Creating task..." )
37+ task = Task (
38+ description = "Test task" ,
39+ expected_output = "Test output" ,
40+ agent = agent
41+ )
42+
43+ print ("\n 6. Creating workflow..." )
44+ workflow = PraisonAIAgents (
45+ agents = [agent ],
46+ tasks = [task ],
47+ process = "sequential"
48+ )
49+
50+ # Check if workflow.start is instrumented
51+ print (f"\n 7. Checking workflow instrumentation..." )
52+ print (f"Workflow has start method: { hasattr (workflow , 'start' )} " )
53+ if hasattr (workflow , 'start' ):
54+ print (f"Start method type: { type (workflow .start )} " )
55+ print (f"Start method name: { workflow .start .__name__ if hasattr (workflow .start , '__name__' ) else 'No name' } " )
56+ print (f"Is wrapped: { 'instrumented' in str (workflow .start .__name__ ) if hasattr (workflow .start , '__name__' ) else 'Unknown' } " )
57+
58+ print ("\n 8. Running workflow..." )
59+ result = workflow .start ()
60+
61+ print ("\n 9. Checking metrics..." )
62+ metrics = telemetry .get_metrics ()
63+ print (f"Metrics: { metrics } " )
64+
65+ print ("\n 10. Manually tracking to verify telemetry works..." )
66+ telemetry .track_agent_execution ("ManualTest" , success = True )
67+ telemetry .track_task_completion ("ManualTask" , success = True )
68+ manual_metrics = telemetry .get_metrics ()
69+ print (f"After manual tracking: { manual_metrics ['metrics' ]} " )
0 commit comments