|
| 1 | +# Analyze Folder Command Telemetry Design |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document outlines the design for improving the telemetry events for the `analyze` command in the syncable-cli application. Currently, the command generates two separate telemetry events when executed, which is incorrect. The goal is to generate only one event per command execution while still capturing the different modes of operation (detailed view, JSON output, etc.). |
| 6 | + |
| 7 | +## Current Issues |
| 8 | + |
| 9 | +1. **Duplicate Events**: When running `sync-ctl analyze .`, two events are generated: |
| 10 | + - A generic "analyze" event |
| 11 | + - A specific "Analyze Folder" event |
| 12 | + |
| 13 | +2. **Lack of Differentiation**: The current implementation doesn't capture how the analysis was performed (JSON output, detailed view, matrix view, etc.) |
| 14 | + |
| 15 | +## Proposed Solution |
| 16 | + |
| 17 | +Replace the two separate events with a single "Analyze Folder" event that includes properties to differentiate the analysis mode. |
| 18 | + |
| 19 | +## Architecture |
| 20 | + |
| 21 | +### Event Structure |
| 22 | + |
| 23 | +The new telemetry event will have the following structure: |
| 24 | + |
| 25 | +Event Name: "Analyze Folder" |
| 26 | +Properties: |
| 27 | +- analysis_mode: string (one of: "json", "detailed", "matrix", "summary") |
| 28 | +- color_scheme: string (one of: "auto", "dark", "light") |
| 29 | +- only_filter: string[] (list of filtered analysis aspects) |
| 30 | + |
| 31 | +### Implementation Plan |
| 32 | + |
| 33 | +1. **Remove duplicate event calls**: Eliminate the separate `track_analyze()` call |
| 34 | +2. **Enhance the `track_analyze_folder()` method**: Add parameters to capture analysis mode |
| 35 | +3. **Modify the main function**: Pass analysis parameters to the telemetry event |
| 36 | +4. **Update the telemetry client**: Modify the `track_analyze_folder()` method to accept and process these parameters |
| 37 | + |
| 38 | +## Detailed Design |
| 39 | + |
| 40 | +### 1. Telemetry Client Modifications |
| 41 | + |
| 42 | +The `TelemetryClient` struct will be updated to accept properties in the `track_analyze_folder` method: |
| 43 | + |
| 44 | +Method signature: |
| 45 | +- Current: `track_analyze_folder(&self)` |
| 46 | +- New: `track_analyze_folder(&self, properties: HashMap<String, serde_json::Value>)` |
| 47 | + |
| 48 | +Implementation: |
| 49 | +- The method will pass the properties to the track_event function |
| 50 | +- Properties will be merged with common properties before sending |
| 51 | + |
| 52 | +### 2. Main Function Updates |
| 53 | + |
| 54 | +In the main function, the analyze command handling will be modified: |
| 55 | + |
| 56 | +Process for determining analysis mode: |
| 57 | +- If json flag is true → "json" |
| 58 | +- Else if detailed flag is true → "detailed" |
| 59 | +- Else based on display option: |
| 60 | + - Matrix or None → "matrix" |
| 61 | + - Detailed → "detailed" |
| 62 | + - Summary → "summary" |
| 63 | + |
| 64 | +Properties to capture: |
| 65 | +- Analysis mode (determined by command flags) |
| 66 | +- Color scheme (if specified) |
| 67 | +- Only filter (if specified) |
| 68 | + |
| 69 | +### 3. Remove Duplicate Event |
| 70 | + |
| 71 | +The separate `telemetry_client.track_analyze()` call will be removed from the analyze command handling. |
| 72 | + |
| 73 | +## Data Flow |
| 74 | + |
| 75 | +``mermaid |
| 76 | +graph TD |
| 77 | + A[User runs analyze command] --> B[CLI Parser] |
| 78 | + B --> C[Main Function] |
| 79 | + C --> D[Create telemetry properties] |
| 80 | + D --> E[Track single Analyze Folder event] |
| 81 | + E --> F[Send to PostHog] |
| 82 | +``` |
| 83 | +
|
| 84 | +## Benefits |
| 85 | +
|
| 86 | +1. **Single Event Per Command**: Only one telemetry event will be generated per analyze command execution |
| 87 | +2. **Mode Differentiation**: The analysis mode (JSON, detailed, matrix, summary) will be captured in event properties |
| 88 | +3. **Enhanced Analytics**: Better data for understanding how users interact with the analyze command |
| 89 | +4. **Consistency**: Aligns with the pattern used for other commands like security scans |
| 90 | +
|
| 91 | +## Implementation Steps |
| 92 | +
|
| 93 | +1. Modify the `track_analyze_folder` method in the telemetry client to accept properties |
| 94 | +2. Update the analyze command handling in main.rs to: |
| 95 | + - Remove the duplicate `track_analyze()` call |
| 96 | + - Create properties map with analysis mode and other relevant information |
| 97 | + - Call `track_analyze_folder` with the properties |
| 98 | +3. Test the implementation to ensure only one event is generated with correct properties |
| 99 | +4. Update any related tests |
| 100 | +
|
| 101 | +## Testing Plan |
| 102 | +
|
| 103 | +1. **Unit Tests**: Update telemetry tests to reflect the new method signature |
| 104 | +2. **Integration Tests**: Verify that only one event is generated when running the analyze command |
| 105 | +3. **Property Validation**: Confirm that the correct analysis mode is captured in event properties |
| 106 | +4. **Edge Cases**: Test with various combinations of command-line options |
| 107 | +
|
| 108 | +## Backward Compatibility |
| 109 | +
|
| 110 | +This change is backward compatible with existing telemetry infrastructure. The event name remains "Analyze Folder", and the core telemetry collection mechanism is unchanged. The only difference is in the data captured with the event. |
| 111 | +
|
| 112 | +## Future Enhancements |
| 113 | +
|
| 114 | +1. **Performance Metrics**: Add analysis duration and file count to the telemetry properties |
| 115 | +2. **Project Type Detection**: Include detected project types in the event properties |
| 116 | +3. **Error Tracking**: Add success/failure status to the events |
0 commit comments