-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extract commandRunner to its own file * Add an option to log all telemetry commands to the console * Add a popup (text to be determined) that requires users to accept telemetry before using. * Convert telemetry to opt-in instead of opt-out * Add a "canary" setting that users can use to opt-in to unreleased features.
- Loading branch information
1 parent
fd0f0df
commit 497e492
Showing
25 changed files
with
669 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Telemetry in the CodeQL for VS Code | ||
|
||
## Why do you collect data? | ||
|
||
GitHub collects usage data and metrics to help us improve Salesforce Extensions for VS Code. | ||
|
||
## What data is collected | ||
|
||
GitHub collects anonymous information related to the usage of the extensions. The data collected are: | ||
|
||
- Which commands are run. | ||
- The time taken for each command. | ||
- Anonymized stack trace and error message of any errors that are thrown from inside the extension. | ||
- Anonymous GUID to uniquely identify an installation. | ||
- IP address of the client sending the telemetry data. This IP address is not stored. It is discarded immediately after the telemetry data is received. | ||
|
||
## How do I disable telemetry reporting? | ||
|
||
You can disable telemetry reporting by setting `codeQL.telemetry.enableTelemetry` to `false` in your settings. | ||
|
||
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). |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
import { | ||
CancellationToken, | ||
ProgressOptions, | ||
window as Window, | ||
commands, | ||
Disposable, | ||
ProgressLocation | ||
} from 'vscode'; | ||
import { showAndLogErrorMessage, showAndLogWarningMessage } from './helpers'; | ||
import { logger } from './logging'; | ||
import { sendCommandUsage } from './telemetry'; | ||
|
||
export class UserCancellationException extends Error { | ||
/** | ||
* @param message The error message | ||
* @param silent If silent is true, then this exception will avoid showing a warning message to the user. | ||
*/ | ||
constructor(message?: string, public readonly silent = false) { | ||
super(message); | ||
} | ||
} | ||
|
||
export interface ProgressUpdate { | ||
/** | ||
* The current step | ||
*/ | ||
step: number; | ||
/** | ||
* The maximum step. This *should* be constant for a single job. | ||
*/ | ||
maxStep: number; | ||
/** | ||
* The current progress message | ||
*/ | ||
message: string; | ||
} | ||
|
||
export type ProgressCallback = (p: ProgressUpdate) => void; | ||
|
||
/** | ||
* A task that handles command invocations from `commandRunner` | ||
* and includes a progress monitor. | ||
* | ||
* | ||
* Arguments passed to the command handler are passed along, | ||
* untouched to this `ProgressTask` instance. | ||
* | ||
* @param progress a progress handler function. Call this | ||
* function with a `ProgressUpdate` instance in order to | ||
* denote some progress being achieved on this task. | ||
* @param token a cencellation token | ||
* @param args arguments passed to this task passed on from | ||
* `commands.registerCommand`. | ||
*/ | ||
export type ProgressTask<R> = ( | ||
progress: ProgressCallback, | ||
token: CancellationToken, | ||
...args: any[] | ||
) => Thenable<R>; | ||
|
||
/** | ||
* A task that handles command invocations from `commandRunner`. | ||
* Arguments passed to the command handler are passed along, | ||
* untouched to this `NoProgressTask` instance. | ||
* | ||
* @param args arguments passed to this task passed on from | ||
* `commands.registerCommand`. | ||
*/ | ||
type NoProgressTask = ((...args: any[]) => Promise<any>); | ||
|
||
/** | ||
* This mediates between the kind of progress callbacks we want to | ||
* write (where we *set* current progress position and give | ||
* `maxSteps`) and the kind vscode progress api expects us to write | ||
* (which increment progress by a certain amount out of 100%). | ||
* | ||
* Where possible, the `commandRunner` function below should be used | ||
* instead of this function. The commandRunner is meant for wrapping | ||
* top-level commands and provides error handling and other support | ||
* automatically. | ||
* | ||
* Only use this function if you need a progress monitor and the | ||
* control flow does not always come from a command (eg- during | ||
* extension activation, or from an internal language server | ||
* request). | ||
*/ | ||
export function withProgress<R>( | ||
options: ProgressOptions, | ||
task: ProgressTask<R>, | ||
...args: any[] | ||
): Thenable<R> { | ||
let progressAchieved = 0; | ||
return Window.withProgress(options, | ||
(progress, token) => { | ||
return task(p => { | ||
const { message, step, maxStep } = p; | ||
const increment = 100 * (step - progressAchieved) / maxStep; | ||
progressAchieved = step; | ||
progress.report({ message, increment }); | ||
}, token, ...args); | ||
}); | ||
} | ||
|
||
/** | ||
* A generic wrapper for command registration. This wrapper adds uniform error handling for commands. | ||
* | ||
* In this variant of the command runner, no progress monitor is used. | ||
* | ||
* @param commandId The ID of the command to register. | ||
* @param task The task to run. It is passed directly to `commands.registerCommand`. Any | ||
* arguments to the command handler are passed on to the task. | ||
*/ | ||
export function commandRunner( | ||
commandId: string, | ||
task: NoProgressTask, | ||
): Disposable { | ||
return commands.registerCommand(commandId, async (...args: any[]) => { | ||
const startTIme = Date.now(); | ||
let error: Error | undefined; | ||
|
||
try { | ||
await task(...args); | ||
} catch (e) { | ||
error = e; | ||
if (e instanceof UserCancellationException) { | ||
// User has cancelled this action manually | ||
if (e.silent) { | ||
logger.log(e.message); | ||
} else { | ||
showAndLogWarningMessage(e.message); | ||
} | ||
} else { | ||
showAndLogErrorMessage(e.message || e); | ||
} | ||
} finally { | ||
const executionTime = Date.now() - startTIme; | ||
sendCommandUsage(commandId, executionTime, error); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* A generic wrapper for command registration. This wrapper adds uniform error handling, | ||
* progress monitoring, and cancellation for commands. | ||
* | ||
* @param commandId The ID of the command to register. | ||
* @param task The task to run. It is passed directly to `commands.registerCommand`. Any | ||
* arguments to the command handler are passed on to the task after the progress callback | ||
* and cancellation token. | ||
* @param progressOptions Progress options to be sent to the progress monitor. | ||
*/ | ||
export function commandRunnerWithProgress<R>( | ||
commandId: string, | ||
task: ProgressTask<R>, | ||
progressOptions: Partial<ProgressOptions> | ||
): Disposable { | ||
return commands.registerCommand(commandId, async (...args: any[]) => { | ||
const startTIme = Date.now(); | ||
let error: Error | undefined; | ||
const progressOptionsWithDefaults = { | ||
location: ProgressLocation.Notification, | ||
...progressOptions | ||
}; | ||
try { | ||
await withProgress(progressOptionsWithDefaults, task, ...args); | ||
} catch (e) { | ||
error = e; | ||
if (e instanceof UserCancellationException) { | ||
// User has cancelled this action manually | ||
if (e.silent) { | ||
logger.log(e.message); | ||
} else { | ||
showAndLogWarningMessage(e.message); | ||
} | ||
} else { | ||
showAndLogErrorMessage(e.message || e); | ||
} | ||
} finally { | ||
const executionTime = Date.now() - startTIme; | ||
sendCommandUsage(commandId, executionTime, error); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.