-
Notifications
You must be signed in to change notification settings - Fork 0
feat: posthog integration #1
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
base: eval-pr-771-target-1758284466333
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,6 +53,11 @@ APP_FULL_URL= | |||||||||||||||||||||||||||||||||
| QDRANT_FULL_URL= | ||||||||||||||||||||||||||||||||||
| ADDITIONAL_CORS_ORIGINS= | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Posthog Configuration | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use correct PostHog capitalization in the section heading for consistency and branding. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use correct brand capitalization "PostHog" in the comment header for consistency and clarity. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact. Prompt for AI agents[internal] Confidence score: 10/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use correct brand capitalization "PostHog" for consistency and clarity. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brand capitalization inconsistency: use "PostHog" for the comment header to match docs and variable naming. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact. Reasoning: Prompt for AI agents[internal] Confidence score: 10/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brand capitalization inconsistency in comment; use "PostHog" to match documentation and project style. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact. Reasoning: Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct brand capitalization to PostHog for clarity and consistency. Prompt for AI agents[internal] Confidence score: 10/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brand capitalization inconsistency. Use "PostHog" for consistency across docs and code comments. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact, documentationImpact. Reasoning: Prompt for AI agents[internal] Confidence score: 10/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brand casing is inconsistent; use "PostHog" for clarity and consistency in comments. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact, objectivity. Reasoning: Prompt for AI agents[internal] Confidence score: 10/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spelling/casing inconsistency: use "PostHog" (capital H) for brand consistency across docs and code. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
|
||||||||||||||||||||||||||||||||||
| POSTHOG_API_KEY=phc_your_api_key_here | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-empty placeholder enables analytics unintentionally and triggers failed PostHog calls; leave API key blank in example to avoid accidental enablement. Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid real-looking secret prefixes in example values to prevent false-positive secret scanning and confusion. Prefer empty or a neutral placeholder. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: documentationImpact. Reasoning: Prompt for AI agents[internal] Confidence score: 7/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid plausible-looking secret placeholders; leave the example value empty to reduce confusion and accidental misuse. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: documentationImpact. Reasoning: Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-empty placeholder enables analytics with an invalid key when ANALYTICS_ENABLED=true, causing unnecessary PostHog initialization and failing requests. Use a blank value in the example to avoid accidental enablement. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use an empty value for the example API key to match existing style and avoid false-positive secret scans. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-empty placeholder API key enables analytics by default when copying .env.example, causing initialization with an invalid key and noisy event attempts. Use an empty value to avoid unintended enablement. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
|
||||||||||||||||||||||||||||||||||
| POSTHOG_HOST=https://app.posthog.com | ||||||||||||||||||||||||||||||||||
| ANALYTICS_ENABLED=true | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Analytics enabled by default in example may lead to unintended telemetry from local/test; consider defaulting to false in the sample env. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: documentationImpact. Reasoning: Prompt for AI agents[internal] Confidence score: 6/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaulting analytics to true in the example .env risks unintentionally sending local/dev data to PostHog. Prefer disabling by default to avoid unintended telemetry. Reasoning: Prompt for AI agents[internal] Confidence score: 7/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default analytics to disabled in the example to follow privacy-by-default and avoid accidental telemetry in local/dev. Reasoning: Prompt for AI agents[internal] Confidence score: 6/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default analytics to disabled to prevent unintentional data capture in local/test environments; developers can opt-in by setting it to true. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: documentationImpact. Prompt for AI agents[internal] Confidence score: 7/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Analytics enabled by default in the example env may cause unintended telemetry in local/test. Prefer defaulting to false in .env.example to minimize accidental data collection. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: documentationImpact. Reasoning: Prompt for AI agents[internal] Confidence score: 7/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaulting analytics to true in the example env can unintentionally emit analytics from local/test environments; set false by default to avoid accidental event leakage. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ANALYTICS_ENABLED is set to true in the example while ENVIRONMENT=local; this likely enables analytics in local dev with a placeholder key, causing noisy errors and unintended telemetry. Set to false by default for local/test to match docs and reduce risk. Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Other Settings | ||||||||||||||||||||||||||||||||||
| PROJECT_NAME=Airweave | ||||||||||||||||||||||||||||||||||
| LOG_LEVEL=INFO | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,293 @@ | ||||||||||||||
| # Airweave Analytics Module | ||||||||||||||
|
|
||||||||||||||
| This module provides PostHog analytics integration for Airweave, enabling comprehensive tracking of user behavior, business metrics, and system performance. | ||||||||||||||
|
|
||||||||||||||
| ## 🏗️ Architecture | ||||||||||||||
|
|
||||||||||||||
| The analytics module is organized into several components: | ||||||||||||||
|
|
||||||||||||||
| - **`service.py`**: Core PostHog integration service | ||||||||||||||
| - **`decorators/`**: Decorators for automatic tracking of API endpoints and operations | ||||||||||||||
| - **`events/`**: Business event tracking classes for high-level metrics | ||||||||||||||
| - **`config.py`**: Analytics configuration (integrated into core config) | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect component listed: no Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
|
|
||||||||||||||
| ## 🚀 Quick Start | ||||||||||||||
|
|
||||||||||||||
| ### 1. Environment Setup | ||||||||||||||
|
|
||||||||||||||
| Add these variables to your `.env` file: | ||||||||||||||
|
|
||||||||||||||
| ```bash | ||||||||||||||
| # PostHog Configuration | ||||||||||||||
| POSTHOG_API_KEY=phc_your_api_key_here | ||||||||||||||
| POSTHOG_HOST=https://app.posthog.com | ||||||||||||||
| ANALYTICS_ENABLED=true | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ### 2. Basic Usage | ||||||||||||||
|
|
||||||||||||||
| ```python | ||||||||||||||
| from airweave.analytics import analytics, business_events | ||||||||||||||
|
|
||||||||||||||
| # Track a custom event | ||||||||||||||
| analytics.track_event( | ||||||||||||||
| event_name="custom_event", | ||||||||||||||
| distinct_id="user_123", | ||||||||||||||
| properties={"key": "value"} | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| # Track business events | ||||||||||||||
| business_events.track_organization_created( | ||||||||||||||
| organization_id=org_id, | ||||||||||||||
| user_id=user_id, | ||||||||||||||
| properties={"plan": "trial"} | ||||||||||||||
| ) | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ### 3. Using Decorators | ||||||||||||||
|
|
||||||||||||||
| ```python | ||||||||||||||
| from airweave.analytics import track_api_endpoint, track_search_operation | ||||||||||||||
|
|
||||||||||||||
| @track_api_endpoint("create_collection") | ||||||||||||||
| async def create_collection(ctx: ApiContext, ...): | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Examples should make Reasoning: Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decorator expects ctx in kwargs, but the example uses positional ctx; events may not be tracked. Reasoning: • Libraries consulted: PostHog events timestamp, Posthog.com Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing ctx positionally (as shown) will prevent the decorator from capturing context, so events won’t be tracked. Make ctx a keyword-only parameter. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
| # Your endpoint logic | ||||||||||||||
| pass | ||||||||||||||
|
|
||||||||||||||
| @track_search_operation() | ||||||||||||||
| async def search_collection(ctx: ApiContext, query: str, ...): | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make Reasoning: Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decorator expects ctx in kwargs, but the example uses positional ctx; search events may not be tracked. Reasoning: • Libraries consulted: PostHog events timestamp, Posthog.com Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
| # Your search logic | ||||||||||||||
| pass | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ## 📊 Complete Analytics Events Overview | ||||||||||||||
|
|
||||||||||||||
| ### API Events | ||||||||||||||
| - **`api_call`**: Successful API calls with timing and context | ||||||||||||||
| - **`api_call_error`**: Failed API calls with error details and status codes | ||||||||||||||
|
|
||||||||||||||
| **Covered Endpoints:** | ||||||||||||||
| - `create_organization` - Organization creation | ||||||||||||||
| - `list_collections` - Collection listing | ||||||||||||||
| - `create_collection` - Collection creation | ||||||||||||||
| - `create_source_connection` - Source connection setup | ||||||||||||||
| - `run_sync` - Sync execution | ||||||||||||||
| - `search` - Basic search queries | ||||||||||||||
| - `search_advanced` - Advanced search queries | ||||||||||||||
|
|
||||||||||||||
| ### Search Events | ||||||||||||||
| - **`search_query`**: Successful search operations with query analysis | ||||||||||||||
| - **`search_query_error`**: Failed search operations with error details | ||||||||||||||
|
|
||||||||||||||
| ### Business Events | ||||||||||||||
| - **`organization_created`**: New organization signup | ||||||||||||||
| - **`collection_created`**: New collection creation | ||||||||||||||
| - **`source_connection_created`**: New source integration | ||||||||||||||
|
|
||||||||||||||
| ### Sync Events | ||||||||||||||
| - **`sync_completed`**: Successful sync job completion with entity counts | ||||||||||||||
| - **`entities_synced_by_type`**: Granular entity tracking per sync and entity type | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. README lists Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| ## 🎯 Dashboard Strategy | ||||||||||||||
|
|
||||||||||||||
| ### Dashboard 1: Airweave Overview | ||||||||||||||
| **Purpose:** High-level business metrics and system health | ||||||||||||||
| **Key Metrics:** | ||||||||||||||
| - Query volume over time (weekly/monthly) | ||||||||||||||
| - Query response times | ||||||||||||||
| - Popular data sources | ||||||||||||||
| - Error rates by endpoint | ||||||||||||||
| - Total entities in sync | ||||||||||||||
| - Query volume per organization | ||||||||||||||
|
|
||||||||||||||
| ### Dashboard 2: User Journey | ||||||||||||||
| **Purpose:** Track user progression and identify drop-off points | ||||||||||||||
| **Key Metrics:** | ||||||||||||||
| - User funnel: org created → collection created → source added → first search | ||||||||||||||
| - Time to first search ("time to wow") | ||||||||||||||
| - Feature adoption rates | ||||||||||||||
| - User retention metrics | ||||||||||||||
|
|
||||||||||||||
| ### Dashboard 3: Syncing & Storage | ||||||||||||||
| **Purpose:** Monitor sync performance and storage usage | ||||||||||||||
| **Key Metrics:** | ||||||||||||||
| - Sync success/error rates | ||||||||||||||
| - Entities synced per sync configuration | ||||||||||||||
| - Storage usage by organization | ||||||||||||||
| - Sync performance trends | ||||||||||||||
| - Entity type distribution | ||||||||||||||
|
|
||||||||||||||
| ### Dashboard 4: Performance & Errors | ||||||||||||||
| **Purpose:** System reliability and performance monitoring | ||||||||||||||
| **Key Metrics:** | ||||||||||||||
| - API error rates by endpoint | ||||||||||||||
| - Search error rates | ||||||||||||||
| - Sync error rates | ||||||||||||||
| - Performance trends | ||||||||||||||
| - Error patterns and troubleshooting | ||||||||||||||
|
|
||||||||||||||
| ### Dashboard 5: Advanced Analytics | ||||||||||||||
| **Purpose:** Deep insights and custom analysis | ||||||||||||||
| **Key Metrics:** | ||||||||||||||
| - Query patterns and complexity | ||||||||||||||
| - User behavior analysis | ||||||||||||||
| - Integration health scores | ||||||||||||||
| - Custom business metrics | ||||||||||||||
|
|
||||||||||||||
| ## 📈 PostHog Widget Configurations | ||||||||||||||
|
|
||||||||||||||
| ### Overview Dashboard Widgets | ||||||||||||||
| 1. **Query Volume Over Time** | ||||||||||||||
| - Event: `search_query` | ||||||||||||||
| - Type: Line Chart | ||||||||||||||
| - Property: Count | ||||||||||||||
| - Time Range: Last 30 days | ||||||||||||||
|
|
||||||||||||||
| 2. **Query Response Times** | ||||||||||||||
| - Event: `search_query` | ||||||||||||||
| - Type: Line Chart | ||||||||||||||
| - Property: `duration_ms` (Average) | ||||||||||||||
| - Time Range: Last 7 days | ||||||||||||||
|
|
||||||||||||||
| 3. **Error Rate by Endpoint** | ||||||||||||||
| - Event: `api_call_error` | ||||||||||||||
| - Type: Bar Chart | ||||||||||||||
| - Property: Count | ||||||||||||||
| - Breakdown: `endpoint` | ||||||||||||||
| - Time Range: Last 7 days | ||||||||||||||
|
|
||||||||||||||
| ### User Journey Dashboard Widgets | ||||||||||||||
| 1. **User Funnel** | ||||||||||||||
| - Events: `organization_created` → `collection_created` → `source_connection_created` → `search_query` | ||||||||||||||
| - Type: Funnel | ||||||||||||||
| - Time Range: Last 30 days | ||||||||||||||
|
|
||||||||||||||
| 2. **Time to First Search** | ||||||||||||||
| - Event: `search_query` | ||||||||||||||
| - Type: Histogram (if supported) or Line Chart | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unverified feature support: "Histogram (if supported)" is ambiguous. Specify supported chart types per PostHog docs or remove the uncertain claim. Reasoning: • Libraries consulted: PostHog histogram chart support, Posthog.com Prompt for AI agents[internal] Confidence score: 7/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
| - Property: `searched_at` | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Widget references Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The widget suggests using a Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inaccurate property reference: Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. README references Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Widget config references a Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Property Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Widget configuration references a non-existent Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Widget configuration references Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
| - Time Range: Last 30 days | ||||||||||||||
|
|
||||||||||||||
| ### Syncing Dashboard Widgets | ||||||||||||||
| 1. **Sync Success Rate** | ||||||||||||||
| - Event: `sync_completed` | ||||||||||||||
| - Type: Line Chart | ||||||||||||||
| - Property: Count | ||||||||||||||
| - Time Range: Last 30 days | ||||||||||||||
|
|
||||||||||||||
| 2. **Entities Synced per Sync** | ||||||||||||||
| - Event: `sync_completed` | ||||||||||||||
| - Type: Bar Chart | ||||||||||||||
| - Property: `total_entities` (Sum) | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Widget uses property Reasoning: Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
| - Breakdown: `sync_id` | ||||||||||||||
| - Time Range: Last 7 days | ||||||||||||||
|
|
||||||||||||||
| 3. **Storage Usage by Organization** | ||||||||||||||
| - Event: `entities_synced_by_type` | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Widget recommends using Reasoning: Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
| - Type: Bar Chart | ||||||||||||||
| - Property: `entity_count` (Sum) | ||||||||||||||
| - Breakdown: `organization_name` | ||||||||||||||
| - Time Range: Last 7 days | ||||||||||||||
|
|
||||||||||||||
| ## 🔧 Configuration | ||||||||||||||
|
|
||||||||||||||
| The analytics module respects these configuration options: | ||||||||||||||
|
|
||||||||||||||
| - `POSTHOG_API_KEY`: Your PostHog API key (required) | ||||||||||||||
| - `POSTHOG_HOST`: PostHog host URL (default: https://app.posthog.com) | ||||||||||||||
| - `ANALYTICS_ENABLED`: Enable/disable analytics (default: true) | ||||||||||||||
| - `ENVIRONMENT`: Deployment environment - added as property to all events | ||||||||||||||
|
|
||||||||||||||
| **Important**: Analytics events are emitted when `ANALYTICS_ENABLED=true`. Each event includes an `environment` property allowing you to filter by environment in PostHog dashboards. Control which environments emit events via their respective environment files. | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Events are emitted only when both ANALYTICS_ENABLED is true and POSTHOG_API_KEY is set; current statement is misleading. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| ### Environment Configuration Examples | ||||||||||||||
|
|
||||||||||||||
| ```bash | ||||||||||||||
| # Production environment (.env.prod) | ||||||||||||||
| ANALYTICS_ENABLED=true | ||||||||||||||
| ENVIRONMENT=prd | ||||||||||||||
|
|
||||||||||||||
| # Development environment (.env.dev) | ||||||||||||||
| ANALYTICS_ENABLED=true | ||||||||||||||
| ENVIRONMENT=dev | ||||||||||||||
|
|
||||||||||||||
| # Local development (.env.local) | ||||||||||||||
| ANALYTICS_ENABLED=false | ||||||||||||||
| ENVIRONMENT=local | ||||||||||||||
|
|
||||||||||||||
| # Testing (.env.test) | ||||||||||||||
| ANALYTICS_ENABLED=false | ||||||||||||||
| ENVIRONMENT=test | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ### PostHog Dashboard Filtering | ||||||||||||||
|
|
||||||||||||||
| - **Production Only**: `environment = "prd"` | ||||||||||||||
| - **All Environments**: No filter | ||||||||||||||
| - **Exclude Local**: `environment != "local"` | ||||||||||||||
| - **Development Only**: `environment = "dev"` | ||||||||||||||
|
|
||||||||||||||
| ## 💡 Best Practices | ||||||||||||||
|
|
||||||||||||||
| ### 1. Use Decorators for Automatic Tracking | ||||||||||||||
| ```python | ||||||||||||||
| @track_api_endpoint("endpoint_name") | ||||||||||||||
| async def my_endpoint(ctx: ApiContext, ...): | ||||||||||||||
| # Automatically tracks timing, errors, and context | ||||||||||||||
| pass | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ### 2. Track Business Events at Key Milestones | ||||||||||||||
| ```python | ||||||||||||||
| # Track when user completes onboarding | ||||||||||||||
| business_events.track_first_sync_completed(ctx, sync_id, entities_count) | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ### 3. Include Rich Context | ||||||||||||||
| ```python | ||||||||||||||
| analytics.track_event( | ||||||||||||||
| event_name="custom_event", | ||||||||||||||
| distinct_id=user_id, | ||||||||||||||
| properties={ | ||||||||||||||
| "organization_name": ctx.organization.name, | ||||||||||||||
| "plan": ctx.organization.plan, | ||||||||||||||
| "feature": "advanced_search" | ||||||||||||||
| }, | ||||||||||||||
| groups={"organization": str(ctx.organization.id)} | ||||||||||||||
| ) | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ### 4. Handle Errors Gracefully | ||||||||||||||
| The analytics service automatically handles PostHog errors and logs them without affecting your application. | ||||||||||||||
|
|
||||||||||||||
| ## 🔒 Privacy & Compliance | ||||||||||||||
|
|
||||||||||||||
| - All user data is sent to PostHog (ensure compliance with your privacy policy) | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overbroad privacy statement: "All user data is sent to PostHog" is inaccurate; only event-specific properties are sent. Clarify scope to avoid misleading compliance guidance. Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation claims user IDs are hashed/obfuscated, but the implementation sends raw IDs via Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
| - User IDs are hashed/obfuscated as needed | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation states user IDs are hashed/obfuscated, but code sends raw IDs; clarify that IDs are un-hashed by default or implement hashing. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation inaccurately states user IDs are hashed/obfuscated; code sends raw IDs. Clarify that IDs are not hashed by default and advise hashing only if required. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation states user IDs are hashed, but code sends raw IDs to PostHog. Update docs or implement hashing to avoid misleading privacy claims. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. README claims user IDs are hashed/obfuscated, but the implementation sends raw IDs as Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User IDs are not hashed by default; documentation should not claim obfuscation. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. README claims user IDs are hashed/obfuscated, but code sends raw IDs via Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation states user IDs are hashed/obfuscated, but code sends raw user/organization IDs to PostHog. Update wording or implement hashing to avoid misleading guidance. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation claims user IDs are hashed/obfuscated, but code sends raw IDs; this is inaccurate and may mislead compliance expectations. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent
Suggested change
|
||||||||||||||
| - Sensitive data should not be included in event properties | ||||||||||||||
| - Consider data retention policies in PostHog | ||||||||||||||
|
|
||||||||||||||
| ## 🚨 Troubleshooting | ||||||||||||||
|
|
||||||||||||||
| ### Common Issues | ||||||||||||||
|
|
||||||||||||||
| 1. **Events not appearing in PostHog** | ||||||||||||||
| - Check `POSTHOG_API_KEY` is set correctly | ||||||||||||||
| - Verify `ANALYTICS_ENABLED=true` | ||||||||||||||
| - Check logs for PostHog errors | ||||||||||||||
|
|
||||||||||||||
| 2. **High event volume** | ||||||||||||||
| - PostHog free tier: 1M events/month | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid hard-coding PostHog pricing limits in docs; the “1M events/month” free tier may change and isn’t enforced by code. Link to pricing/docs instead. DEV MODE: This violation would have been filtered out by screening filters. Failing filters: futureIssue. Reasoning: Prompt for AI agents[internal] Confidence score: 7/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
| - Consider sampling for high-volume events | ||||||||||||||
| - Use `ANALYTICS_ENABLED=false` to disable | ||||||||||||||
|
|
||||||||||||||
| 3. **Performance impact** | ||||||||||||||
| - Analytics calls are async and non-blocking | ||||||||||||||
| - Errors are logged but don't affect application flow | ||||||||||||||
| - Consider batching for high-frequency events | ||||||||||||||
|
|
||||||||||||||
| ## 📚 Additional Resources | ||||||||||||||
|
|
||||||||||||||
| - [PostHog Documentation](https://posthog.com/docs) | ||||||||||||||
| - [PostHog Python SDK](https://posthog.com/docs/libraries/python) | ||||||||||||||
| - [Airweave Analytics Examples](analytics_integration_example.py) | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. README links to analytics_integration_example.py which is not present; broken link. Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Broken documentation link to analytics_integration_example.py; the file does not exist. Replace with a valid path to existing examples. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Broken documentation link to analytics_integration_example.py; the file does not exist in the analytics module. Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Broken link to Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Broken documentation link: Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional resource link points to a non-existent file Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Broken reference: Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linked example file does not exist in the repository; update the link or remove it to avoid broken documentation. Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent |
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| """Analytics module for PostHog integration.""" | ||
|
|
||
| from .decorators.api import track_api_endpoint | ||
| from .decorators.search import track_search_operation | ||
| from .events.business_events import business_events | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Importing business_events here eagerly instantiates BusinessEventTracker on package import. Consider lazy-loading or exporting the class/module to avoid import-time side effects. Reasoning: Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent |
||
| from .service import analytics | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Importing analytics here triggers AnalyticsService instantiation at import time, causing side effects (configuration/logging) on package import. Prefer lazy initialization or exporting the class/module instead. Reasoning: Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: General AI Review Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import-time optional dependency: init re-exports analytics, forcing immediate import of service.py which imports posthog; missing posthog causes ImportError on package import. Reasoning: Prompt for AI agents[internal] Confidence score: 9/10 [internal] Posted by: Functional Bugs Agent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re-exporting a symbol named "analytics" from within the airweave.analytics package creates a name collision with the package itself, leading to confusing and error-prone imports. Consider aliasing to a distinct name like analytics_service for clarity. Reasoning: Prompt for AI agents[internal] Confidence score: 8/10 [internal] Posted by: General AI Review Agent |
||
|
|
||
| __all__ = [ | ||
| "analytics", | ||
| "business_events", | ||
| "track_api_endpoint", | ||
| "track_search_operation", | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| """Decorators for analytics tracking.""" | ||
|
|
||
| from .api import track_api_endpoint | ||
| from .search import track_search_operation | ||
|
|
||
| __all__ = [ | ||
| "track_api_endpoint", | ||
| "track_search_operation", | ||
| ] |
Uh oh!
There was an error while loading. Please reload this page.
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.
Inconsistent brand casing; use "PostHog" capitalization to match docs and env var names.
DEV MODE: This violation would have been filtered out by screening filters. Failing filters: functionalImpact.
Prompt for AI agents
[internal] Confidence score: 9/10
[internal] Posted by: General AI Review Agent