Skip to content

Commit 81b0792

Browse files
committed
Convert telemetry to a class
Created the TelemetryListener and stuffed most of the functions in telemetry.ts into this class. Tests had to change a significant amount. Also addressed other comments from code review.
1 parent 28bd898 commit 81b0792

8 files changed

Lines changed: 254 additions & 202 deletions

File tree

.github/TELEMETRY.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Telemetry in the CodeQL for VS Code
1+
# Telemetry in the CodeQL extension for VS Code
22

33
## Why do you collect data?
44

5-
GitHub collects usage data and metrics to help us improve Salesforce Extensions for VS Code.
5+
GitHub collects usage data and metrics to help us improve CodeQL for VS Code.
66

77
## What data is collected
88

@@ -16,6 +16,6 @@ GitHub collects anonymous information related to the usage of the extensions. Th
1616

1717
## How do I disable telemetry reporting?
1818

19-
You can disable telemetry reporting by setting `codeQL.telemetry.enableTelemetry` to `false` in your settings.
19+
You can disable telemetry reporting by setting `codeQL.telemetry.enableTelemetry` to `false` in [your settings](https://code.visualstudio.com/docs/getstarted/settings#_settings-editor).
2020

21-
Additionally, telemetry will be disabled if the global `telemetry.enableTelemetry` is set to `false`. For more information see [Microsoft’s documentation](https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting).
21+
Additionally, telemetry will be disabled if the global `telemetry.enableTelemetry` setting is set to `false`. For more information on global telemetry collection, see [Microsoft’s documentation](https://code.visualstudio.com/docs/supporting/faq#_how-to-disable-telemetry-reporting).

extensions/ql-vscode/gulpfile.ts/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import { packageExtension } from './package';
77
import { injectAppInsightsKey } from './appInsights';
88

99
export const buildWithoutPackage =
10-
gulp.series(
11-
gulp.parallel(
12-
compileTypeScript, compileTextMateGrammar, compileView, copyTestData, copyViewCss
13-
),
14-
injectAppInsightsKey
10+
gulp.parallel(
11+
compileTypeScript, compileTextMateGrammar, compileView, copyTestData, copyViewCss
1512
);
13+
1614
export { compileTextMateGrammar, watchTypeScript, compileTypeScript, injectAppInsightsKey };
17-
exports.default = gulp.series(buildWithoutPackage, packageExtension);
15+
exports.default = gulp.series(buildWithoutPackage, injectAppInsightsKey, packageExtension);

extensions/ql-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
"type": "boolean",
180180
"default": false,
181181
"scope": "application",
182-
"markdownDescription": "Specifies whether to enable Code QL telemetry. This setting AND the global `#telemetry.enableTelemetry#` setting must be checked for telemetry to be sent. For more information, see [TELEMETRY.md](https://github.com/github/vscode-codeql/blob/93831e28597bb08567db9844737efd9ff188fc3a/.github/TELEMETRY.md)"
182+
"markdownDescription": "Specifies whether to send CodeQL usage telemetry. This setting AND the global `#telemetry.enableTelemetry#` setting must be checked for telemetry to be sent to GitHub. For more information, see [TELEMETRY.md](https://github.com/github/vscode-codeql/blob/main/.github/TELEMETRY.md)"
183183
},
184184
"codeQL.telemetry.logTelemetry": {
185185
"type": "boolean",

extensions/ql-vscode/src/commandRunner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'vscode';
99
import { showAndLogErrorMessage, showAndLogWarningMessage } from './helpers';
1010
import { logger } from './logging';
11-
import { sendCommandUsage } from './telemetry';
11+
import { telemetryListener } from './telemetry';
1212

1313
export class UserCancellationException extends Error {
1414
/**
@@ -134,7 +134,7 @@ export function commandRunner(
134134
}
135135
} finally {
136136
const executionTime = Date.now() - startTIme;
137-
sendCommandUsage(commandId, executionTime, error);
137+
telemetryListener.sendCommandUsage(commandId, executionTime, error);
138138
}
139139
});
140140
}
@@ -177,7 +177,7 @@ export function commandRunnerWithProgress<R>(
177177
}
178178
} finally {
179179
const executionTime = Date.now() - startTIme;
180-
sendCommandUsage(commandId, executionTime, error);
180+
telemetryListener.sendCommandUsage(commandId, executionTime, error);
181181
}
182182
});
183183
}

extensions/ql-vscode/src/config.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DistributionManager } from './distribution';
44
import { logger } from './logging';
55

66
/** Helper class to look up a labelled (and possibly nested) setting. */
7-
class Setting {
7+
export class Setting {
88
name: string;
99
parent?: Setting;
1010

@@ -39,8 +39,16 @@ class Setting {
3939

4040
const ROOT_SETTING = new Setting('codeQL');
4141

42-
// Distribution configuration
42+
// Global configuration
43+
const TELEMETRY_SETTING = new Setting('telemetry', ROOT_SETTING);
44+
const GLOBAL_TELEMETRY_SETTING = new Setting('telemetry');
45+
46+
export const LOG_TELEMETRY = new Setting('logTelemetry', TELEMETRY_SETTING);
47+
export const ENABLE_TELEMETRY = new Setting('enableTelemetry', TELEMETRY_SETTING);
4348

49+
export const GLOBAL_ENABLE_TELEMETRY = new Setting('enableTelemetry', GLOBAL_TELEMETRY_SETTING);
50+
51+
// Distribution configuration
4452
const DISTRIBUTION_SETTING = new Setting('cli', ROOT_SETTING);
4553
const CUSTOM_CODEQL_PATH_SETTING = new Setting('executablePath', DISTRIBUTION_SETTING);
4654
const INCLUDE_PRERELEASE_SETTING = new Setting('includePrerelease', DISTRIBUTION_SETTING);
@@ -70,8 +78,6 @@ const DEBUG_SETTING = new Setting('debug', RUNNING_QUERIES_SETTING);
7078
const RUNNING_TESTS_SETTING = new Setting('runningTests', ROOT_SETTING);
7179
const RESULTS_DISPLAY_SETTING = new Setting('resultsDisplay', ROOT_SETTING);
7280

73-
export const LOG_TELEMETRY = new Setting('telemetry.logTelemetry', ROOT_SETTING);
74-
export const ENABLE_TELEMETRY = new Setting('telemetry.enableTelemetry', ROOT_SETTING);
7581
export const NUMBER_OF_TEST_THREADS_SETTING = new Setting('numberOfThreads', RUNNING_TESTS_SETTING);
7682
export const MAX_QUERIES = new Setting('maxQueries', RUNNING_QUERIES_SETTING);
7783
export const AUTOSAVE_SETTING = new Setting('autoSave', RUNNING_QUERIES_SETTING);
@@ -105,7 +111,7 @@ export interface CliConfig {
105111
}
106112

107113

108-
abstract class ConfigListener extends DisposableObject {
114+
export abstract class ConfigListener extends DisposableObject {
109115
protected readonly _onDidChangeConfiguration = this.push(new EventEmitter<void>());
110116

111117
constructor() {

extensions/ql-vscode/src/helpers.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ async function internalShowAndLog(message: string, items: string[], outputLogger
7171

7272
/**
7373
* Opens a modal dialog for the user to make a yes/no choice.
74+
*
7475
* @param message The message to show.
76+
* @param modal If true (the default), show a modal dialog box, otherwise dialog is non-modal and can
77+
* be closed even if the user does not make a choice.
7578
*
7679
* @return `true` if the user clicks 'Yes', `false` if the user clicks 'No' or cancels the dialog.
80+
* Return `undefined` if the user avoids a choice on a non-modal dialog.
7781
*/
78-
export async function showBinaryChoiceDialog(message: string, { modal = true } = {}): Promise<boolean | undefined> {
82+
export async function showBinaryChoiceDialog(message: string, modal = true): Promise<boolean | undefined> {
7983
const yesItem = { title: 'Yes', isCloseAffordance: false };
8084
const noItem = { title: 'No', isCloseAffordance: true };
8185
const chosenItem = await Window.showInformationMessage(message, { modal }, yesItem, noItem);

0 commit comments

Comments
 (0)