Skip to content

Commit f50a043

Browse files
authored
More strongly typed telemetry (microsoft#77412)
* More strongly typed telemetry * Updated update service to not duplicate typings
1 parent f41d90a commit f50a043

14 files changed

Lines changed: 122 additions & 152 deletions

File tree

src/vs/platform/diagnostics/node/diagnosticsService.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,17 @@ export class DiagnosticsService implements IDiagnosticsService {
520520
if (folderUri.scheme === 'file') {
521521
const folder = folderUri.fsPath;
522522
collectWorkspaceStats(folder, ['node_modules', '.git']).then(stats => {
523-
/* __GDPR__
524-
"workspace.stats" : {
525-
"fileTypes" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
526-
"configTypes" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true },
527-
"launchConfigs" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
528-
}
529-
*/
530-
this.telemetryService.publicLog('workspace.stats', {
523+
type WorkspaceStatsClassification = {
524+
fileTypes: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true };
525+
configTypes: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true };
526+
launchConfigs: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true };
527+
};
528+
type WorkspaceStatsEvent = {
529+
fileTypes: WorkspaceStatItem[];
530+
configTypes: WorkspaceStatItem[];
531+
launchConfigs: WorkspaceStatItem[];
532+
};
533+
this.telemetryService.publicLog2<WorkspaceStatsEvent, WorkspaceStatsClassification>('workspace.stats', {
531534
fileTypes: stats.fileTypes,
532535
configTypes: stats.configFiles,
533536
launchConfigs: stats.launchConfigFiles

src/vs/platform/extensionManagement/common/extensionGalleryService.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,15 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
411411
let text = options.text || '';
412412
const pageSize = getOrDefault(options, o => o.pageSize, 50);
413413

414-
/* __GDPR__
415-
"galleryService:query" : {
416-
"type" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
417-
"text": { "classification": "CustomerContent", "purpose": "FeatureInsight" }
418-
}
419-
*/
420-
this.telemetryService.publicLog('galleryService:query', { type, text });
414+
type GalleryServiceQueryClassification = {
415+
type: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
416+
text: { classification: 'CustomerContent', purpose: 'FeatureInsight' };
417+
};
418+
type GalleryServiceQueryEvent = {
419+
type: string;
420+
text: string;
421+
};
422+
this.telemetryService.publicLog2<GalleryServiceQueryEvent, GalleryServiceQueryClassification>('galleryService:query', { type, text });
421423

422424
let query = new Query()
423425
.withFlags(Flags.IncludeLatestVersionOnly, Flags.IncludeAssetUri, Flags.IncludeStatistics, Flags.IncludeFiles, Flags.IncludeVersionProperties)

src/vs/platform/update/electron-main/abstractUpdateService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export function createUpdateURL(platform: string, quality: string): string {
1818
return `${product.updateUrl}/api/update/${platform}/${quality}/${product.commit}`;
1919
}
2020

21+
export type UpdateNotAvailableClassification = {
22+
explicit: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true };
23+
};
24+
2125
export abstract class AbstractUpdateService implements IUpdateService {
2226

2327
_serviceBrand: any;

src/vs/platform/update/electron-main/updateService.darwin.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { State, IUpdate, StateType, UpdateType } from 'vs/platform/update/common
1313
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1414
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1515
import { ILogService } from 'vs/platform/log/common/log';
16-
import { AbstractUpdateService, createUpdateURL } from 'vs/platform/update/electron-main/abstractUpdateService';
16+
import { AbstractUpdateService, createUpdateURL, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
1717
import { IRequestService } from 'vs/platform/request/common/request';
1818

1919
export class DarwinUpdateService extends AbstractUpdateService {
@@ -81,12 +81,10 @@ export class DarwinUpdateService extends AbstractUpdateService {
8181
return;
8282
}
8383

84-
/* __GDPR__
85-
"update:downloaded" : {
86-
"version" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
87-
}
88-
*/
89-
this.telemetryService.publicLog('update:downloaded', { version: update.version });
84+
type UpdateDownloadedClassification = {
85+
version: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
86+
};
87+
this.telemetryService.publicLog2<{ version: String }, UpdateDownloadedClassification>('update:downloaded', { version: update.version });
9088

9189
this.setState(State.Ready(update));
9290
}
@@ -95,13 +93,7 @@ export class DarwinUpdateService extends AbstractUpdateService {
9593
if (this.state.type !== StateType.CheckingForUpdates) {
9694
return;
9795
}
98-
99-
/* __GDPR__
100-
"update:notAvailable" : {
101-
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
102-
}
103-
*/
104-
this.telemetryService.publicLog('update:notAvailable', { explicit: !!this.state.context });
96+
this.telemetryService.publicLog2<{ explicit: boolean }, UpdateNotAvailableClassification>('update:notAvailable', { explicit: !!this.state.context });
10597

10698
this.setState(State.Idle(UpdateType.Archive));
10799
}

src/vs/platform/update/electron-main/updateService.linux.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { State, IUpdate, AvailableForDownload, UpdateType } from 'vs/platform/up
1010
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1111
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1212
import { ILogService } from 'vs/platform/log/common/log';
13-
import { createUpdateURL, AbstractUpdateService } from 'vs/platform/update/electron-main/abstractUpdateService';
13+
import { createUpdateURL, AbstractUpdateService, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
1414
import { IRequestService, asJson } from 'vs/platform/request/common/request';
1515
import { shell } from 'electron';
1616
import { CancellationToken } from 'vs/base/common/cancellation';
@@ -40,17 +40,11 @@ export class LinuxUpdateService extends AbstractUpdateService {
4040
}
4141

4242
this.setState(State.CheckingForUpdates(context));
43-
4443
this.requestService.request({ url: this.url }, CancellationToken.None)
4544
.then<IUpdate>(asJson)
4645
.then(update => {
4746
if (!update || !update.url || !update.version || !update.productVersion) {
48-
/* __GDPR__
49-
"update:notAvailable" : {
50-
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
51-
}
52-
*/
53-
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
47+
this.telemetryService.publicLog2<{ explicit: boolean }, UpdateNotAvailableClassification>('update:notAvailable', { explicit: !!context });
5448

5549
this.setState(State.Idle(UpdateType.Archive));
5650
} else {
@@ -59,14 +53,7 @@ export class LinuxUpdateService extends AbstractUpdateService {
5953
})
6054
.then(undefined, err => {
6155
this.logService.error(err);
62-
63-
/* __GDPR__
64-
"update:notAvailable" : {
65-
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
66-
}
67-
*/
68-
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
69-
56+
this.telemetryService.publicLog2<{ explicit: boolean }, UpdateNotAvailableClassification>('update:notAvailable', { explicit: !!context });
7057
// only show message when explicitly checking for updates
7158
const message: string | undefined = !!context ? (err.message || err) : undefined;
7259
this.setState(State.Idle(UpdateType.Archive, message));

src/vs/platform/update/electron-main/updateService.snap.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as path from 'vs/base/common/path';
1313
import { realpath, watch } from 'fs';
1414
import { spawn } from 'child_process';
1515
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
16+
import { UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
1617

1718
abstract class AbstractUpdateService2 implements IUpdateService {
1819

@@ -159,29 +160,17 @@ export class SnapUpdateService extends AbstractUpdateService2 {
159160

160161
protected doCheckForUpdates(context: any): void {
161162
this.setState(State.CheckingForUpdates(context));
162-
163163
this.isUpdateAvailable().then(result => {
164164
if (result) {
165165
this.setState(State.Ready({ version: 'something', productVersion: 'something' }));
166166
} else {
167-
/* __GDPR__
168-
"update:notAvailable" : {
169-
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
170-
}
171-
*/
172-
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
167+
this.telemetryService.publicLog2<{ explicit: boolean }, UpdateNotAvailableClassification>('update:notAvailable', { explicit: !!context });
173168

174169
this.setState(State.Idle(UpdateType.Snap));
175170
}
176171
}, err => {
177172
this.logService.error(err);
178-
179-
/* __GDPR__
180-
"update:notAvailable" : {
181-
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
182-
}
183-
*/
184-
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
173+
this.telemetryService.publicLog2<{ explicit: boolean }, UpdateNotAvailableClassification>('update:notAvailable', { explicit: !!context });
185174
this.setState(State.Idle(UpdateType.Snap, err.message || err));
186175
});
187176
}

src/vs/platform/update/electron-main/updateService.win32.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { State, IUpdate, StateType, AvailableForDownload, UpdateType } from 'vs/
1414
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1515
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1616
import { ILogService } from 'vs/platform/log/common/log';
17-
import { createUpdateURL, AbstractUpdateService } from 'vs/platform/update/electron-main/abstractUpdateService';
17+
import { createUpdateURL, AbstractUpdateService, UpdateNotAvailableClassification } from 'vs/platform/update/electron-main/abstractUpdateService';
1818
import { IRequestService, asJson } from 'vs/platform/request/common/request';
1919
import { checksum } from 'vs/base/node/crypto';
2020
import { tmpdir } from 'os';
@@ -168,12 +168,7 @@ export class Win32UpdateService extends AbstractUpdateService {
168168
})
169169
.then(undefined, err => {
170170
this.logService.error(err);
171-
/* __GDPR__
172-
"update:notAvailable" : {
173-
"explicit" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
174-
}
175-
*/
176-
this.telemetryService.publicLog('update:notAvailable', { explicit: !!context });
171+
this.telemetryService.publicLog2<{ explicit: boolean }, UpdateNotAvailableClassification>('update:notAvailable', { explicit: !!context });
177172

178173
// only show message when explicitly checking for updates
179174
const message: string | undefined = !!context ? (err.message || err) : undefined;

src/vs/workbench/api/node/extHostRequireInterceptor.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,19 @@ export class OpenNodeModuleFactory implements INodeModuleFactory {
231231
if (!this._extensionId) {
232232
return;
233233
}
234-
/* __GDPR__
235-
"shimming.open" : {
236-
"extension": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
237-
}
238-
*/
239-
this._mainThreadTelemerty.$publicLog('shimming.open', { extension: this._extensionId });
234+
type ShimmingOpenClassification = {
235+
extension: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
236+
};
237+
this._mainThreadTelemerty.$publicLog2<{ extension: string }, ShimmingOpenClassification>('shimming.open', { extension: this._extensionId });
240238
}
241239

242240
private sendNoForwardTelemetry(): void {
243241
if (!this._extensionId) {
244242
return;
245243
}
246-
/* __GDPR__
247-
"shimming.open.call.noForward" : {
248-
"extension": { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
249-
}
250-
*/
251-
this._mainThreadTelemerty.$publicLog('shimming.open.call.noForward', { extension: this._extensionId });
244+
type ShimmingOpenCallNoForwardClassification = {
245+
extension: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
246+
};
247+
this._mainThreadTelemerty.$publicLog2<{ extension: string }, ShimmingOpenCallNoForwardClassification>('shimming.open.call.noForward', { extension: this._extensionId });
252248
}
253249
}

src/vs/workbench/contrib/experiments/electron-browser/experimentService.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,10 @@ export class ExperimentService extends Disposable implements IExperimentService
220220

221221
});
222222
return Promise.all(promises).then(() => {
223-
/* __GDPR__
224-
"experiments" : {
225-
"experiments" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
226-
}
227-
*/
228-
this.telemetryService.publicLog('experiments', { experiments: this._experiments });
223+
type ExperimentsClassification = {
224+
experiments: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
225+
};
226+
this.telemetryService.publicLog2<{ experiments: IExperiment[] }, ExperimentsClassification>('experiments', { experiments: this._experiments });
229227
});
230228
});
231229
}

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
168168
private static readonly IgnoreTask010DonotShowAgain_key = 'workbench.tasks.ignoreTask010Shown';
169169

170170
private static CustomizationTelemetryEventName: string = 'taskService.customize';
171-
public static TemplateTelemetryEventName: string = 'taskService.template';
172-
173171
public _serviceBrand: any;
174172
public static OutputChannelId: string = 'tasks';
175173
public static OutputChannelLabel: string = nls.localize('tasks', "Tasks");
@@ -2057,14 +2055,16 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
20572055
content = content.replace(/(\n)(\t+)/g, (_, s1, s2) => s1 + strings.repeat(' ', s2.length * editorConfig.editor.tabSize));
20582056
}
20592057
configFileCreated = true;
2060-
/* __GDPR__
2061-
"taskService.template" : {
2062-
"templateId" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" },
2063-
"autoDetect" : { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true }
2064-
}
2065-
*/
2058+
type TaskServiceTemplateClassification = {
2059+
templateId?: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
2060+
autoDetect: { classification: 'SystemMetaData', purpose: 'FeatureInsight', isMeasurement: true };
2061+
};
2062+
type TaskServiceEvent = {
2063+
templateId?: string;
2064+
autoDetect: boolean;
2065+
};
20662066
return this.textFileService.create(resource, content).then((result): URI => {
2067-
this.telemetryService.publicLog(AbstractTaskService.TemplateTelemetryEventName, {
2067+
this.telemetryService.publicLog2<TaskServiceEvent, TaskServiceTemplateClassification>('taskService.template', {
20682068
templateId: selection.id,
20692069
autoDetect: selection.autoDetect
20702070
});

0 commit comments

Comments
 (0)