Node module to help VS Code extensions send telemetry using application insights
Перейти к файлу
Logan Ramos 3f927c1dbc
Fix empty props and measurements in pipeline
2022-06-23 10:55:39 -04:00
.github/workflows Add PR Chat 2022-05-19 14:21:31 -04:00
.vscode Initial scaffolding for a web version of the module 2021-07-16 16:00:34 -04:00
build/azure-pipelines Add azure pipeline ci 2021-09-15 12:56:43 -04:00
lib Added comment for error props 2022-06-15 13:48:28 -04:00
src Fix empty props and measurements in pipeline 2022-06-23 10:55:39 -04:00
test Add forgotten microsoft copyright 2022-05-06 09:51:36 -04:00
.editorconfig Initial scaffolding for a web version of the module 2021-07-16 16:00:34 -04:00
.esbuild.config.js Lower target to support more legacy codebases 2022-01-11 14:00:39 -05:00
.eslintignore Initial scaffolding for a web version of the module 2021-07-16 16:00:34 -04:00
.eslintrc.json Initial scaffolding for a web version of the module 2021-07-16 16:00:34 -04:00
.gitignore Fix broken package 2021-07-20 09:51:57 -04:00
.npmignore Try to shim out the VS code api to make it testable 2022-04-29 15:46:50 -04:00
LICENSE initial commit 2016-02-05 15:46:35 -08:00
README.md Merge pull request #107 from EstebanDalelR/patch-2 2022-05-25 17:46:37 -07:00
SECURITY.md Microsoft mandatory file 2022-05-16 22:00:48 +00:00
package-lock.json Bump version 2022-06-15 13:48:44 -04:00
package.json Bump version 2022-06-15 13:48:44 -04:00
thirdpartynotices.txt Create thirdpartynotices.txt 2016-02-08 10:08:03 -08:00
tsconfig.json Use dynamic imports 2021-09-23 10:17:15 -04:00
tsfmt.json upgrade appinsights; respect config setting 2017-02-20 18:02:34 -08:00
vscode.proposed.telemetry.d.ts Adopt proposed telemetry API 2022-01-20 14:45:06 -05:00

README.md

@vscode/extension-telemetry

This module provides a consistent way for extensions to report telemetry over Application Insights. The module respects the user's decision about whether or not to send telemetry data. See telemetry extension guidelines for more information on using telemetry in your extension.

Follow guide to set up Application Insights in Azure and get your key. Don't worry about hardcoding it, it is not sensitive.

Install

With npm: npm install @vscode/extension-telemetry With yarn: yarn add @vscode/extension-telemetry

Usage

Setup

import * as vscode from 'vscode';
import TelemetryReporter from '@vscode/extension-telemetry';

// all events will be prefixed with this event name
const extensionId = '<your extension unique name>';

// extension version will be reported as a property with each event
const extensionVersion = '<your extension version>';

// the application insights key (also known as instrumentation key)
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 properly disposed. Upon disposal the events will be flushed
   context.subscriptions.push(reporter);
}

First-Party

By default, we use the AppInsights key to detect whether or not the telemetry is first-party. The constructor now takes an optional parameter that will force the reporter to treat telemetry as first-party. This parameter will not override in the false direction.

Sending Events

Use this method for sending general events to App Insights.

// send event any time after activation
reporter.sendTelemetryEvent('sampleEvent', { 'stringProp': 'some string' }, { 'numericMeasure': 123 });

Sending Exceptions

Use this method for diagnostics in App Insights. This method will automatically drop events in certain environments for first party extensions.

// send an error any time after activation
try { ... } catch (error) {
   reporter.sendTelemetryException(error, { 'stringProp': 'some string' }, { 'numericMeasure': 123 });
}

Sending Errors as Events

Use this method for sending error telemetry as traditional events to App Insights. This method will automatically drop error properties in certain environments for first party extensions. The last parameter is an optional list of case-sensitive properties that should be dropped. If no array is passed, we will drop all properties but still send the event.

// send an error event any time after activation
reporter.sendTelemetryErrorEvent('sampleErrorEvent', { 'stringProp': 'some string', 'stackProp': 'some user stack trace' }, { 'numericMeasure': 123 }, [ 'stackProp' ]);

Common Properties

  • Extension Name common.extname - The extension name
  • Extension Version common.extversion - The extension version
  • Machine Identifier common.vscodemachineid - A common machine identifier generated by VS Code
  • Session Identifier common.vscodesessionid - A session identifier generated by VS Code
  • VS Code Version common.vscodeversion - The version of VS Code running the extension
  • OS common.os - The OS running VS Code
  • Platform Version common.platformversion - The version of the OS/Platform
  • Product common.product - What Vs code is hosted in, i.e. desktop, github.dev, codespaces.
  • UI Kind common.uikind - Web or Desktop indicating where VS Code is running
  • Remote Name common.remotename - A name to identify the type of remote connection. other indicates a remote connection not from the 3 main extensions (ssh, docker, wsl).
  • Architecture common.nodeArch - What architecture of node is running. i.e. arm or x86. On the web it will just say web.

License

MIT