src/vs/platform/telemetry/common/telemetry.ts
119 LOC · 115 covered · 4 uncovered · 3 ranges · 8711 concepts · 1 introducers · 4470 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
telemetry.ts ×3
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { createDecorator } from '../../instantiation/common/instantiation.js';
import { ClassifiedEvent, IGDPRProperty, OmitMetadata, StrictPropertyCheck } from './gdprTypings.js';
export const ITelemetryService = createDecorator<ITelemetryService>('telemetryService');
export interface ITelemetryData {
from?: string;
target?: string;
[key: string]: string | unknown | undefined;
}
export interface ITelemetryService {
readonly _serviceBrand: undefined;
readonly telemetryLevel: TelemetryLevel;
readonly sessionId: string;
readonly machineId: string;
readonly sqmId: string;
readonly devDeviceId: string;
readonly firstSessionDate: string;
readonly msftInternal?: boolean;
/**
* Whether error telemetry will get sent. If false, `publicLogError` will no-op.
*/
readonly sendErrorTelemetry: boolean;
/**
* @deprecated Use publicLog2 and the typescript GDPR annotation where possible
*/
publicLog(eventName: string, data?: ITelemetryData): void;
/**
* Sends a telemetry event that has been privacy approved.
* Do not call this unless you have been given approval.
*/
publicLog2<E extends ClassifiedEvent<OmitMetadata<T>> = never, T extends IGDPRProperty = never>(eventName: string, data?: StrictPropertyCheck<T, E>): void;
/**
* @deprecated Use publicLogError2 and the typescript GDPR annotation where possible
*/
publicLogError(errorEventName: string, data?: ITelemetryData): void;
publicLogError2<E extends ClassifiedEvent<OmitMetadata<T>> = never, T extends IGDPRProperty = never>(eventName: string, data?: StrictPropertyCheck<T, E>): void;
setExperimentProperty(name: string, value: string): void;
/**
* Sets a common property that will be attached to all telemetry events.
* Common properties are added after PII cleaning and cannot be overridden by event data.
*/
setCommonProperty(name: string, value: string | boolean): void;
}
export function telemetryLevelEnabled(service: ITelemetryService, level: TelemetryLevel): boolean {
return service.telemetryLevel >= level;
}
/**
* Replaces `/` and `\` with `|` in model identifiers to prevent the
* telemetry pipeline from redacting them as file paths.
*/
export function escapeModelIdForTelemetry(modelId: string | undefined): string | undefined {
return modelId?.replace(/[\/\\]/g, '|');
}
export interface ITelemetryEndpoint {
id: string;
aiKey: string;
sendErrorTelemetry: boolean;
}
export const ICustomEndpointTelemetryService = createDecorator<ICustomEndpointTelemetryService>('customEndpointTelemetryService');
export interface ICustomEndpointTelemetryService {
readonly _serviceBrand: undefined;
publicLog(endpoint: ITelemetryEndpoint, eventName: string, data?: ITelemetryData): void;
publicLogError(endpoint: ITelemetryEndpoint, errorEventName: string, data?: ITelemetryData): void;
}
// Keys
export const currentSessionDateStorageKey = 'telemetry.currentSessionDate';
export const firstSessionDateStorageKey = 'telemetry.firstSessionDate';
export const lastSessionDateStorageKey = 'telemetry.lastSessionDate';
export const machineIdKey = 'telemetry.machineId';
export const sqmIdKey = 'telemetry.sqmId';
export const devDeviceIdKey = 'telemetry.devDeviceId';
// Configuration Keys
export const TELEMETRY_SECTION_ID = 'telemetry';
export const TELEMETRY_SETTING_ID = 'telemetry.telemetryLevel';
export const TELEMETRY_CRASH_REPORTER_SETTING_ID = 'telemetry.enableCrashReporter';
export const TELEMETRY_OLD_SETTING_ID = 'telemetry.enableTelemetry';
export const enum TelemetryLevel {
NONE = 0,
CRASH = 1,
ERROR = 2,
USAGE = 3
}
export const enum TelemetryConfiguration {
OFF = 'off',
CRASH = 'crash',
ERROR = 'error',
ON = 'all'
}
export interface ICommonProperties {
[name: string]: string | boolean | undefined;
}