diff --git a/README.md b/README.md index ca9585b..0c19d8b 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,12 @@ 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](https://code.visualstudio.com/api/extension-guides/telemetry) for more information on using telemetry in your extension. -Follow [guide to set up Application Insights](https://docs.microsoft.com/en-us/azure/azure-monitor/app/create-new-resource) in Azure and get your key. Don't worry about hardcoding it, it is not sensitive. +Follow [guide to set up Application Insights](https://learn.microsoft.com/en-us/azure/azure-monitor/app/create-workspace-resource) in Azure and get your connection string. 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` @@ -18,15 +19,15 @@ With yarn: import * as vscode from 'vscode'; import TelemetryReporter from '@vscode/extension-telemetry'; -// the application insights key (also known as instrumentation key) -const key = ''; +// the connection string +const connectionString = ''; // telemetry reporter let reporter; function activate(context: vscode.ExtensionContext) { // create telemetry reporter on extension activation - reporter = new TelemetryReporter(key); + reporter = new TelemetryReporter(connectionString); // ensure it gets properly disposed. Upon disposal the events will be flushed context.subscriptions.push(reporter); } diff --git a/dist/telemetryReporter.d.ts b/dist/telemetryReporter.d.ts index 9c628d7..7a0409b 100644 --- a/dist/telemetryReporter.d.ts +++ b/dist/telemetryReporter.d.ts @@ -28,10 +28,10 @@ export interface ReplacementOption { export default class TelemetryReporter { /** - * @param key The app insights key + * @param connectionString The app insights connection string * @param replacementOptions A list of replacement options for the app insights client. This allows the sender to filter out any sensitive or unnecessary information from the telemetry server. */ - constructor(key: string, replacementOptions?: ReplacementOption[]); + constructor(connectionString: string, replacementOptions?: ReplacementOption[]); /** * A string representation of the current level of telemetry being collected diff --git a/src/browser/telemetryReporter.ts b/src/browser/telemetryReporter.ts index 955ae31..5832435 100644 --- a/src/browser/telemetryReporter.ts +++ b/src/browser/telemetryReporter.ts @@ -21,10 +21,10 @@ function getBrowserRelease(navigator: Navigator): string { } export default class TelemetryReporter extends BaseTelemetryReporter { - constructor(key: string, replacementOptions?: ReplacementOption[]) { - let clientFactory = (key: string) => appInsightsClientFactory(key, vscode.env.machineId, undefined, replacementOptions); + constructor(connectionString: string, replacementOptions?: ReplacementOption[]) { + let clientFactory = (connectionString: string) => appInsightsClientFactory(connectionString, vscode.env.machineId, undefined, replacementOptions); // If key is usable by 1DS use the 1DS SDk - if (TelemetryUtil.shouldUseOneDataSystemSDK(key)) { + if (TelemetryUtil.shouldUseOneDataSystemSDK(connectionString)) { clientFactory = (key: string) => oneDataSystemClientFactory(key, vscode); } @@ -34,9 +34,9 @@ export default class TelemetryReporter extends BaseTelemetryReporter { architecture: "web", }; - const sender = new BaseTelemetrySender(key, clientFactory); + const sender = new BaseTelemetrySender(connectionString, clientFactory); // AIF is no longer supported - if (key && (key.indexOf("AIF") === 0)) { + if (connectionString && (connectionString.indexOf("AIF") === 0)) { throw new Error("AIF keys are no longer supported. Please switch to 1DS keys for 1st party extensions"); } super(sender, vscode, { additionalCommonProperties: TelemetryUtil.getAdditionalCommonProperties(osShim) }); diff --git a/src/common/appInsightsClientFactory.ts b/src/common/appInsightsClientFactory.ts index 989b9fd..0be2280 100644 --- a/src/common/appInsightsClientFactory.ts +++ b/src/common/appInsightsClientFactory.ts @@ -11,7 +11,7 @@ import { ReplacementOption, SenderData } from "./baseTelemetryReporter"; import { BaseTelemetryClient } from "./baseTelemetrySender"; import { TelemetryUtil } from "./util"; -export const appInsightsClientFactory = async (key: string, machineId: string, xhrOverride?: IXHROverride, replacementOptions?: ReplacementOption[]): Promise => { +export const appInsightsClientFactory = async (connectionString: string, machineId: string, xhrOverride?: IXHROverride, replacementOptions?: ReplacementOption[]): Promise => { let appInsightsClient: ApplicationInsights | undefined; try { const basicAISDK = await import/* webpackMode: "eager" */("@microsoft/applicationinsights-web-basic"); @@ -26,7 +26,7 @@ export const appInsightsClientFactory = async (key: string, machineId: string, x } appInsightsClient = new basicAISDK.ApplicationInsights({ - instrumentationKey: key, + connectionString: connectionString, disableAjaxTracking: true, disableExceptionTracking: true, disableFetchTracking: true, diff --git a/src/common/util.ts b/src/common/util.ts index 1850f8f..08a56c5 100644 --- a/src/common/util.ts +++ b/src/common/util.ts @@ -28,7 +28,7 @@ export class TelemetryUtil { } /** - * Given a key checks if it is a valid 1DS key + * Given a key / connection string checks if it is a valid 1DS key * @param key The key to check if it's a valid 1DS key */ public static shouldUseOneDataSystemSDK(key: string): boolean { diff --git a/src/node/telemetryReporter.ts b/src/node/telemetryReporter.ts index a148b2b..ae2bee0 100644 --- a/src/node/telemetryReporter.ts +++ b/src/node/telemetryReporter.ts @@ -54,10 +54,10 @@ function getXHROverride() { } export default class TelemetryReporter extends BaseTelemetryReporter { - constructor(key: string, replacementOptions?: ReplacementOption[]) { - let clientFactory = (key: string) => appInsightsClientFactory(key, vscode.env.machineId, getXHROverride(), replacementOptions); - // If key is usable by 1DS use the 1DS SDk - if (TelemetryUtil.shouldUseOneDataSystemSDK(key)) { + constructor(connectionString: string, replacementOptions?: ReplacementOption[]) { + let clientFactory = (connectionString: string) => appInsightsClientFactory(connectionString, vscode.env.machineId, getXHROverride(), replacementOptions); + // If connection string is usable by 1DS use the 1DS SDk + if (TelemetryUtil.shouldUseOneDataSystemSDK(connectionString)) { clientFactory = (key: string) => oneDataSystemClientFactory(key, vscode, getXHROverride()); } @@ -67,8 +67,8 @@ export default class TelemetryReporter extends BaseTelemetryReporter { architecture: os.arch(), }; - const sender = new BaseTelemetrySender(key, clientFactory,); - if (key && key.indexOf("AIF-") === 0) { + const sender = new BaseTelemetrySender(connectionString, clientFactory,); + if (connectionString && connectionString.indexOf("AIF-") === 0) { throw new Error("AIF keys are no longer supported. Please switch to 1DS keys for 1st party extensions"); } super(sender, vscode, { additionalCommonProperties: TelemetryUtil.getAdditionalCommonProperties(osShim) });