Telemetry and Data Collection
Relevant source files
The following files were used as context for generating this wiki page:
Visual Studio Code collects telemetry data to understand how the product is being used and to identify areas for improvement. This system is configurable at the product level and provides APIs for individual extensions to report their own usage and error data. The collection mechanism is designed with user privacy in mind, providing opt-out options and clear warnings about potentially sensitive data.
Extensions are a major part of the VS Code ecosystem, and they can participate in telemetry by using the @vscode/extension-telemetry package. Each extension can be configured with its own Application Insights key, allowing for separate data streams. The system also includes proposed APIs for more structured and robust telemetry logging from extensions.
Core Telemetry Configuration
The primary configuration for telemetry across the entire product is defined in product.json. This file contains settings for enabling telemetry, configuring the data collection endpoint (Application Insights), and providing users with information on how to opt-out.
Sources: product.json
Key Configuration Properties
| Property | Description | Example Value |
|---|---|---|
enableTelemetry | A boolean flag to enable or disable telemetry collection globally. | true |
telemetryOptOutUrl | The URL that points users to documentation on how to opt-out of telemetry. | https://code.visualstudio.com/docs/getstarted/telemetry |
aiConfig | An object containing configuration for Application Insights, the backend service for telemetry. | { "ariaKey": "...", "instrumentationKey": "..." } |
crashReporter | An object containing information used for crash reporting. | { "productName": "VSCode", "companyName": "Microsoft" } |
Sources: product.json:10-18
Extension-Level Telemetry
Individual extensions can be configured to send their own telemetry data. This is typically managed through the extension's package.json file, which specifies a unique Application Insights key (aiKey) and lists the necessary telemetry libraries as dependencies.
Configuration in package.json
Extensions such as markdown-language-features and github-authentication define an aiKey in their package.json. This key links the telemetry events from that specific extension to a dedicated Application Insights resource.
// extensions/markdown-language-features/package.json:6
{
"aiKey": "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255"
}
Sources: extensions/markdown-language-features/package.json:6, extensions/github-authentication/package.json:54
The github-authentication extension also declares a dependency on the @vscode/extension-telemetry package, which provides the client-side implementation for sending telemetry data.
// extensions/github-authentication/package.json:62-65
"dependencies": {
"node-fetch": "2.6.7",
"@vscode/extension-telemetry": "^0.9.8",
"vscode-tas-client": "^0.1.84"
}
Sources: extensions/github-authentication/package.json:62-65
Proposed Telemetry API for Extensions
A proposed API, defined in vscode.proposed.telemetry.d.ts, aims to provide a standardized way for extensions to log telemetry. It introduces the TelemetryLogger and TelemetryAppender interfaces, abstracting the details of how data is sent.
Sources: src/vscode-dts/vscode.proposed.telemetry.d.ts
API Interfaces
The following diagram shows the key interfaces in the proposed telemetry API.
This diagram illustrates the relationship between the high-level TelemetryLogger and the lower-level TelemetryAppender for processing telemetry events.
Sources: src/vscode-dts/vscode.proposed.telemetry.d.ts:25-78
- TelemetryLogger: A high-level logger with methods to log usage events (
logUsage) and errors (logError). This is the primary interface intended for extension developers. - TelemetryAppender: A lower-level interface that handles the logic of appending events to a buffer and flushing them to the telemetry service.
Data Flow
The sequence diagram below illustrates how an extension would use the proposed API to send a telemetry event.
This diagram shows an extension calling logUsage, which is then processed by the TelemetryLogger and TelemetryAppender.
Sources: src/vscode-dts/vscode.proposed.telemetry.d.ts:30-58
Implementation Example: TypeScript Language Features
The typescript-language-features extension provides a concrete implementation of a telemetry reporter. The VsCodeTelemetryReporter class acts as a wrapper around the TelemetryReporter from the @vscode/extension-telemetry library.
Sources: extensions/typescript-language-features/src/logging/telemetry.ts
VsCodeTelemetryReporter Class
This class is responsible for normalizing and sending telemetry data for the TypeScript extension.
// extensions/typescript-language-features/src/logging/telemetry.ts:13-39
export class VsCodeTelemetryReporter implements ITelemetryReporter {
private _reporter: TelemetryReporter | null = null;
constructor(
private readonly _getReporter: () => TelemetryReporter
) { }
public logTelemetry(eventName: string, properties?: { [key: string]: string }): void {
this.reporter.sendTelemetryEvent(eventName, properties);
}
public logErr(eventName: string, properties?: { [key: string]: string }): void {
this.reporter.sendTelemetryErrorEvent(eventName, properties);
}
private get reporter(): TelemetryReporter {
if (!this._reporter) {
this._reporter = this._getReporter();
}
return this._reporter;
}
}
Sources: extensions/typescript-language-features/src/logging/telemetry.ts:13-39
The class lazily initializes the TelemetryReporter and provides two main methods:
logTelemetry: Sends a standard telemetry event.logErr: Sends an error event.
User-Facing Configuration and Data Sensitivity
VS Code is transparent about the data it collects, especially when it might be sensitive. The package.nls.json file for the TypeScript extension contains user-facing descriptions for configuration settings that enable logging and tracing. These descriptions explicitly warn the user about the nature of the data being collected.
| Setting | Description |
|---|---|
typescript.tsserver.log | "Enables logging of the TS server to a file. This log can be used to diagnose TS Server issues. The log may contain file paths, source code, and other potentially sensitive information from your project." |
typescript.tsserver.enableTracing | "Enables tracing TS server performance to a directory. These trace files can be used to diagnose TS Server performance issues. The log may contain file paths, source code, and other potentially sensitive information from your project." |
Sources: extensions/typescript-language-features/package.nls.json:16-19
These warnings ensure that users are aware of what data they are sharing when they enable diagnostic features.