Verified Solution

[microsoft/vscode] Copilot chat OTel: consider making JSON truncation configurable

Sponsored Content
### ROOT CAUSE The current implementation of the Copilot chat OTel truncates large JSON payloads to a fixed size of 64KB, which is hardcoded. This approach can cause issues because: 1. Some telemetry systems have strict size limits for attributes, requiring strict truncation. 2. Other systems without such limits would benefit from receiving the full JSON payload for complete message rendering. 3. Arbitrary truncation (e.g., cutting the JSON in the middle) can result in invalid JSON, breaking the structure and preventing proper UI rendering. The root cause is the lack of configurability in the truncation logic, which forces a one-size-fits-all approach that doesn’t adapt to different systems’ requirements. --- ### CODE FIX To address this, introduce a configurable truncation limit via a VS Code setting. Here’s how to implement it: 1. **Add a Configuration Setting** Define a new setting in `package.json` under `contribution`: ```json { "contribution": { "configuration": { "editor": { "settings": { "[telemetry]": { "settings": { "jsonPayloadTruncationLimit": { "type": "number", "default": 65536, // Default to 64KB "description": "Maximum JSON payload size for telemetry (in bytes). Set to 0 to disable truncation." } } } } } } } } ``` 2. **Modify the Truncation Logic** Replace the hardcoded truncation with dynamic limit retrieval from the setting. Use `vscode.workspace.getConfiguration()` to fetch the value. Add error handling for invalid values (e.g., negative numbers or non-numeric strings). ```typescript import * as vscode from 'vscode'; // ... existing code ... // Fetch the configuration value const config = vscode.workspace.getConfiguration('telemetry'); const truncationLimit = config.get('jsonPayloadTruncationLimit') || 65536; // Apply truncation if needed if (jsonDataString.length > truncationLimit && truncationLimit > 0) { const truncated = jsonDataString.substring(0, truncationLimit); // Validate truncated JSON before sending try { JSON.parse(truncated); // Ensure the truncated string is valid JSON } catch (error) { console.error('Invalid JSON after truncation:', error); // Fallback to partial data or skip logging if necessary } jsonDataString = truncated; } // Send the telemetry data (possibly with a flag indicating truncation) telemetryData.jsonPayload = jsonDataString; telemetryData.attributes = { ... }; // Include a flag if truncated ``` 3. **Graceful Degradation** - If the setting is `0`, disable truncation entirely. - Add validation to ensure the truncated JSON remains valid (e.g., truncate only at the end of the string, not mid-structure). 4. **Documentation** Update the VS Code documentation to explain the new setting and its impact on telemetry. This fix ensures: - Systems with strict limits can enforce their requirements. - Systems without limits can receive full payloads. - Truncation occurs safely without breaking JSON structure.
Deploy on DigitalOcean ($200 Credit)

Related Fixes

[StackOverflow/docker] exec: \"mysql\": executable file not found in $PATH": unknown
[StackOverflow/go] Why does my WSL in vscode terminate with exit code "4294967295"
[golang/go] crypto/rsa:gofips140-v1.0.0: TestEverything/241 failures