Skip to content

Instantly share code, notes, and snippets.

@Almenon
Last active May 6, 2018 22:55
Show Gist options
  • Save Almenon/19ffa90df3b0569f98a10c65587e2928 to your computer and use it in GitHub Desktop.
Save Almenon/19ffa90df3b0569f98a10c65587e2928 to your computer and use it in GitHub Desktop.
telemetry
const vscode = require('vscode');
const TelemetryReporter = require('vscode-extension-telemetry');
// events are in format username/extensionId/action
const extensionId = '<your extension unique name>';
const extension = extensions.getExtension(extensionId)!;
const extensionVersion = extension.packageJSON.version
// the application insights key
// its not a password, just a identifier (you can hardcode it into your extension without worry)
// but you might want to obfuscate it so bots that scan github dont pick up on it
const key = '<your key>';
// telemetry reporter
let reporter;
function activate(context: vscode.ExtensionContext) {
...
// create telemetry reporter on extension activation
reporter = new TelemetryReporter(extensionId, extensionVersion, key);
// ensure it gets property disposed
context.subscriptions.push(reporter);
...
}
function deactivate() {
// This will ensure all pending events get flushed
reporter.dispose();
}
...
// send event any time after activation
reporter.sendTelemetryEvent('sampleEvent', { 'stringProp': 'some string' }, { 'numericMeasure': 123});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment