-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Develop #624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Develop #624
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Telemetry Implementation Summary | ||
|
|
||
| ## What Was Fixed | ||
|
|
||
| 1. **PostHog initialization error** - Removed invalid `events_to_ignore` parameter | ||
| 2. **Missing imports** - Added `MinimalTelemetry` and `TelemetryCollector` imports to telemetry `__init__.py` | ||
| 3. **Wrong method instrumentation** - Changed from `agent.execute()` to `agent.chat()` | ||
| 4. **Task tracking** - Added instrumentation for `workflow.execute_task()` | ||
| 5. **Automatic setup** - Added `auto_instrument_all()` in main `__init__.py` | ||
| 6. **Automatic flush** - Added `atexit` handler to send data on program exit | ||
|
|
||
| ## Current Status | ||
|
|
||
| ✅ **Telemetry is now working automatically!** | ||
|
|
||
| - Enabled by default (opt-out via environment variables) | ||
| - Tracks agent executions and task completions | ||
| - Sends anonymous data to PostHog on program exit | ||
| - No manual setup required | ||
|
|
||
| ## Metrics Example | ||
| ``` | ||
| Telemetry metrics collected: | ||
| - Agent executions: 4 | ||
| - Task completions: 2 | ||
| - Errors: 0 | ||
| - Session ID: 33873e62396d8b4c | ||
| ``` | ||
|
|
||
| ## To Disable | ||
| Set any of these environment variables: | ||
| - `PRAISONAI_TELEMETRY_DISABLED=true` | ||
| - `DO_NOT_TRACK=true` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Debug auto-instrumentation. | ||
| """ | ||
|
|
||
| print("1. Import telemetry module...") | ||
| import praisonaiagents.telemetry | ||
| print(" Telemetry module imported") | ||
|
|
||
| print("\n2. Check if auto_instrument_all was called...") | ||
| print(f" _initialized: {praisonaiagents.telemetry._initialized}") | ||
|
|
||
| print("\n3. Import Agent and PraisonAIAgents...") | ||
| from praisonaiagents import Agent, PraisonAIAgents | ||
| print(" Classes imported") | ||
|
|
||
| print("\n4. Check if classes are instrumented...") | ||
| agent = Agent(name="Test", role="Test", goal="Test", instructions="Test") | ||
| print(f" Agent.__init__ name: {Agent.__init__.__name__}") | ||
| print(f" agent.execute exists: {hasattr(agent, 'execute')}") | ||
|
|
||
| print("\n5. Manually call auto_instrument_all...") | ||
| from praisonaiagents.telemetry.integration import auto_instrument_all | ||
| auto_instrument_all() | ||
| print(" auto_instrument_all() called") | ||
|
|
||
| print("\n6. Create new agent after instrumentation...") | ||
| agent2 = Agent(name="Test2", role="Test2", goal="Test2", instructions="Test2") | ||
| print(f" Agent.__init__ name after: {Agent.__init__.__name__}") | ||
| print(f" agent2.execute exists: {hasattr(agent2, 'execute')}") | ||
|
|
||
| print("\n7. Check if execute is wrapped...") | ||
| if hasattr(agent2, 'execute'): | ||
| print(f" agent2.execute name: {agent2.execute.__name__}") | ||
| print(f" agent2.execute wrapped: {hasattr(agent2.execute, '__wrapped__')}") | ||
|
|
||
| print("\n8. Import telemetry and check if it's working...") | ||
| from praisonaiagents.telemetry import get_telemetry | ||
| telemetry = get_telemetry() | ||
| print(f" Telemetry enabled: {telemetry.enabled}") | ||
| print(f" PostHog available: {telemetry._posthog is not None}") | ||
|
|
||
| # The key insight: auto_instrument_all needs to be called AFTER | ||
| # the Agent and PraisonAIAgents classes are imported! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Debug telemetry instrumentation to see what's happening. | ||
| """ | ||
|
|
||
| import os | ||
| # Make sure telemetry is enabled | ||
| if 'PRAISONAI_TELEMETRY_DISABLED' in os.environ: | ||
| del os.environ['PRAISONAI_TELEMETRY_DISABLED'] | ||
|
|
||
| print("1. Importing modules...") | ||
| from praisonaiagents import Agent, Task, PraisonAIAgents | ||
| from praisonaiagents.telemetry import get_telemetry | ||
|
|
||
| print("\n2. Checking telemetry status...") | ||
| telemetry = get_telemetry() | ||
| print(f"Telemetry enabled: {telemetry.enabled}") | ||
| print(f"PostHog available: {telemetry._posthog is not None}") | ||
|
|
||
| print("\n3. Creating agent...") | ||
| agent = Agent( | ||
| name="TestAgent", | ||
| role="Test Role", | ||
| goal="Test Goal", | ||
| instructions="Test instructions" | ||
| ) | ||
|
|
||
| # Check if agent.execute is instrumented | ||
| print(f"\n4. Checking agent instrumentation...") | ||
| print(f"Agent has execute method: {hasattr(agent, 'execute')}") | ||
| if hasattr(agent, 'execute'): | ||
| print(f"Execute method type: {type(agent.execute)}") | ||
| print(f"Execute method name: {agent.execute.__name__ if hasattr(agent.execute, '__name__') else 'No name'}") | ||
| print(f"Is wrapped: {'instrumented' in str(agent.execute.__name__) if hasattr(agent.execute, '__name__') else 'Unknown'}") | ||
|
|
||
| print("\n5. Creating task...") | ||
| task = Task( | ||
| description="Test task", | ||
| expected_output="Test output", | ||
| agent=agent | ||
| ) | ||
|
|
||
| print("\n6. Creating workflow...") | ||
| workflow = PraisonAIAgents( | ||
| agents=[agent], | ||
| tasks=[task], | ||
| process="sequential" | ||
| ) | ||
|
|
||
| # Check if workflow.start is instrumented | ||
| print(f"\n7. Checking workflow instrumentation...") | ||
| print(f"Workflow has start method: {hasattr(workflow, 'start')}") | ||
| if hasattr(workflow, 'start'): | ||
| print(f"Start method type: {type(workflow.start)}") | ||
| print(f"Start method name: {workflow.start.__name__ if hasattr(workflow.start, '__name__') else 'No name'}") | ||
| print(f"Is wrapped: {'instrumented' in str(workflow.start.__name__) if hasattr(workflow.start, '__name__') else 'Unknown'}") | ||
|
|
||
| print("\n8. Running workflow...") | ||
| result = workflow.start() | ||
|
|
||
| print("\n9. Checking metrics...") | ||
| metrics = telemetry.get_metrics() | ||
| print(f"Metrics: {metrics}") | ||
|
|
||
| print("\n10. Manually tracking to verify telemetry works...") | ||
| telemetry.track_agent_execution("ManualTest", success=True) | ||
| telemetry.track_task_completion("ManualTask", success=True) | ||
| manual_metrics = telemetry.get_metrics() | ||
| print(f"After manual tracking: {manual_metrics['metrics']}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Debug double-counting in telemetry. | ||
| """ | ||
|
|
||
| from praisonaiagents import Agent, Task, PraisonAIAgents | ||
| from praisonaiagents.telemetry import get_telemetry | ||
|
|
||
| # Get telemetry instance | ||
| telemetry = get_telemetry() | ||
|
|
||
| # Clear any existing metrics by flushing | ||
| telemetry.flush() | ||
|
|
||
| print("Starting fresh telemetry tracking...\n") | ||
|
|
||
| # Create ONE agent | ||
| print("Creating 1 agent...") | ||
| agent = Agent( | ||
| name="SingleAgent", | ||
| role="Test Role", | ||
| goal="Test Goal", | ||
| instructions="Test instructions" | ||
| ) | ||
|
|
||
| # Create ONE task | ||
| print("Creating 1 task...") | ||
| task = Task( | ||
| description="Single test task", | ||
| expected_output="Test output", | ||
| agent=agent | ||
| ) | ||
|
|
||
| # Create workflow with ONE agent and ONE task | ||
| print("Creating workflow with 1 agent and 1 task...") | ||
| workflow = PraisonAIAgents( | ||
| agents=[agent], | ||
| tasks=[task], | ||
| process="sequential" | ||
| ) | ||
|
|
||
| # Check metrics before running | ||
| metrics_before = telemetry.get_metrics() | ||
| print(f"\nMetrics BEFORE running workflow:") | ||
| print(f" Agent executions: {metrics_before['metrics']['agent_executions']}") | ||
| print(f" Task completions: {metrics_before['metrics']['task_completions']}") | ||
|
|
||
| # Run the workflow | ||
| print("\nRunning workflow...") | ||
| result = workflow.start() | ||
|
|
||
| # Check metrics after running | ||
| metrics_after = telemetry.get_metrics() | ||
| print(f"\nMetrics AFTER running workflow:") | ||
| print(f" Agent executions: {metrics_after['metrics']['agent_executions']} (expected: 1)") | ||
| print(f" Task completions: {metrics_after['metrics']['task_completions']} (expected: 1)") | ||
|
|
||
| if metrics_after['metrics']['agent_executions'] > 1: | ||
| print("\n❌ ISSUE: Agent executions are being double-counted!") | ||
| print(" Possible causes:") | ||
| print(" - Agent method is being called multiple times") | ||
| print(" - Instrumentation is being applied twice") | ||
| print(" - Multiple tracking calls for same execution") | ||
|
|
||
| if metrics_after['metrics']['task_completions'] > 1: | ||
| print("\n❌ ISSUE: Task completions are being double-counted!") | ||
| print(" Possible causes:") | ||
| print(" - Task completion is tracked in multiple places") | ||
| print(" - Instrumentation is being applied twice") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to catch more specific exceptions here instead of a general
Exception? While the comment indicates that silent failure is intentional for auto-instrumentation, catching specific exceptions (e.g.,ImportError,AttributeError, or custom exceptions from the telemetry module) could provide more targeted resilience. If a general catch is necessary, consider logging the exception at a DEBUG level. This could help diagnose issues during development or if telemetry setup becomes problematic in certain environments, without crashing the main application.