|
| 1 | +--- |
| 2 | +applyTo: '**/*.ts' |
| 3 | +description: Telemetry Implementation Guide |
| 4 | +--- |
| 5 | + |
| 6 | +Patterns for GDPR-compliant telemetry in VS Code with proper type safety and privacy protection. |
| 7 | + |
| 8 | +## Implementation Pattern |
| 9 | + |
| 10 | +### 1. Define Types |
| 11 | +```typescript |
| 12 | +type MyFeatureEvent = { |
| 13 | + action: string; |
| 14 | + duration: number; |
| 15 | + success: boolean; |
| 16 | + errorCode?: string; |
| 17 | +}; |
| 18 | + |
| 19 | +type MyFeatureClassification = { |
| 20 | + action: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The action performed.' }; |
| 21 | + duration: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'Time in milliseconds.' }; |
| 22 | + success: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Whether action succeeded.' }; |
| 23 | + errorCode: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'Error code if action failed.' }; |
| 24 | + owner: 'yourGitHubUsername'; |
| 25 | + comment: 'Tracks MyFeature usage and performance.'; |
| 26 | +}; |
| 27 | +``` |
| 28 | + |
| 29 | +### 2.1. Send Event |
| 30 | +```typescript |
| 31 | +this.telemetryService.publicLog2<MyFeatureEvent, MyFeatureClassification>('myFeatureAction', { |
| 32 | + action: 'buttonClick', |
| 33 | + duration: 150, |
| 34 | + success: true |
| 35 | +}); |
| 36 | +``` |
| 37 | + |
| 38 | +### 2.2. Error Events |
| 39 | +For error-specific telemetry with stack traces or error messages: |
| 40 | +```typescript |
| 41 | +type MyErrorEvent = { |
| 42 | + operation: string; |
| 43 | + errorMessage: string; |
| 44 | + duration?: number; |
| 45 | +}; |
| 46 | + |
| 47 | +type MyErrorClassification = { |
| 48 | + operation: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The operation that failed.' }; |
| 49 | + errorMessage: { classification: 'CallstackOrException'; purpose: 'PerformanceAndHealth'; comment: 'The error message.' }; |
| 50 | + duration: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'Time until failure.' }; |
| 51 | + owner: 'yourGitHubUsername'; |
| 52 | + comment: 'Tracks MyFeature errors for reliability.'; |
| 53 | +}; |
| 54 | + |
| 55 | +this.telemetryService.publicLogError2<MyErrorEvent, MyErrorClassification>('myFeatureError', { |
| 56 | + operation: 'fileRead', |
| 57 | + errorMessage: error.message, |
| 58 | + duration: 1200 |
| 59 | +}); |
| 60 | +``` |
| 61 | + |
| 62 | +### 3. Service Injection |
| 63 | +```typescript |
| 64 | +constructor( |
| 65 | + @ITelemetryService private readonly telemetryService: ITelemetryService, |
| 66 | +) { super(); } |
| 67 | +``` |
| 68 | + |
| 69 | +## GDPR Classifications & Purposes |
| 70 | + |
| 71 | +**Classifications (choose the most restrictive):** |
| 72 | +- `SystemMetaData` - **Most common.** Non-personal system info, user preferences, feature usage, identifiers (extension IDs, language types, counts, durations, success flags) |
| 73 | +- `CallstackOrException` - Error messages, stack traces, exception details. **Only for actual error information.** |
| 74 | +- `PublicNonPersonalData` - Data already publicly available (rare) |
| 75 | + |
| 76 | +**Purposes (combine with different classifications):** |
| 77 | +- `FeatureInsight` - **Default.** Understanding how features are used, user behavior patterns, feature adoption |
| 78 | +- `PerformanceAndHealth` - **For errors & performance.** Metrics, error rates, performance measurements, diagnostics |
| 79 | + |
| 80 | +**Required Properties:** |
| 81 | +- `comment` - Clear explanation of what the field contains and why it's collected |
| 82 | +- `owner` - GitHub username (infer from branch or ask) |
| 83 | +- `isMeasurement: true` - **Required** for all numeric values flags used in calculations |
| 84 | + |
| 85 | +## Error Events |
| 86 | + |
| 87 | +Use `publicLogError2` for errors with `CallstackOrException` classification: |
| 88 | + |
| 89 | +```typescript |
| 90 | +this.telemetryService.publicLogError2<ErrorEvent, ErrorClassification>('myFeatureError', { |
| 91 | + errorMessage: error.message, |
| 92 | + errorCode: 'MYFEATURE_001', |
| 93 | + context: 'initialization' |
| 94 | +}); |
| 95 | +``` |
| 96 | + |
| 97 | +## Naming & Privacy Rules |
| 98 | + |
| 99 | +**Naming Conventions:** |
| 100 | +- Event names: `camelCase` with context (`extensionActivationError`, `chatMessageSent`) |
| 101 | +- Property names: specific and descriptive (`agentId` not `id`, `durationMs` not `duration`) |
| 102 | +- Common patterns: `success/hasError/isEnabled`, `sessionId/extensionId`, `type/kind/source` |
| 103 | + |
| 104 | +**Critical Don'ts:** |
| 105 | +- ❌ No PII (usernames, emails, file paths, content) |
| 106 | +- ❌ Missing `owner` field in classification (infer from branch name or ask user) |
| 107 | +- ❌ Vague comments ("user data" → "selected language identifier") |
| 108 | +- ❌ Wrong classification |
| 109 | +- ❌ Missing `isMeasurement` on numeric metrics |
| 110 | + |
| 111 | +**Privacy Requirements:** |
| 112 | +- Minimize data collection to essential insights only |
| 113 | +- Use hashes/categories instead of raw values when possible |
| 114 | +- Document clear purpose for each data point |
0 commit comments