@vscode/extension-telemetry
Advanced tools
Comparing version
@@ -9,45 +9,3 @@ /*--------------------------------------------------------- | ||
import { TelemetryUtil } from "../common/util"; | ||
const webAppInsightsClientFactory = async (key, replacementOptions) => { | ||
let appInsightsClient; | ||
try { | ||
const web = await import /* webpackMode: "eager" */("@microsoft/applicationinsights-web-basic"); | ||
appInsightsClient = new web.ApplicationInsights({ | ||
instrumentationKey: key, | ||
disableAjaxTracking: true, | ||
disableExceptionTracking: true, | ||
disableFetchTracking: true, | ||
disableCorrelationHeaders: true, | ||
disableCookiesUsage: true, | ||
autoTrackPageVisitTime: false, | ||
emitLineDelimitedJson: false, | ||
disableInstrumentationKeyValidation: true | ||
}); | ||
} | ||
catch (e) { | ||
return Promise.reject(e); | ||
} | ||
// Sets the appinsights client into a standardized form | ||
const telemetryClient = { | ||
logEvent: (eventName, data) => { | ||
const properties = { ...data?.properties, ...data?.measurements }; | ||
if (replacementOptions?.length) { | ||
TelemetryUtil.applyReplacements(properties, replacementOptions); | ||
} | ||
appInsightsClient?.track({ name: eventName, data: properties }); | ||
}, | ||
flush: async () => { | ||
appInsightsClient?.flush(false); | ||
}, | ||
dispose: async () => { | ||
const unloadPromise = new Promise((resolve) => { | ||
appInsightsClient?.unload(true, () => { | ||
resolve(); | ||
appInsightsClient = undefined; | ||
}, 1000); | ||
}); | ||
return unloadPromise; | ||
} | ||
}; | ||
return telemetryClient; | ||
}; | ||
import { appInsightsClientFactory } from "../common/appInsightsClientFactory"; | ||
function getBrowserRelease(navigator) { | ||
@@ -64,3 +22,3 @@ if (navigator.userAgentData) { | ||
constructor(key, replacementOptions) { | ||
let clientFactory = (key) => webAppInsightsClientFactory(key, replacementOptions); | ||
let clientFactory = (key) => appInsightsClientFactory(key, undefined, replacementOptions); | ||
// If key is usable by 1DS use the 1DS SDk | ||
@@ -67,0 +25,0 @@ if (TelemetryUtil.shouldUseOneDataSystemSDK(key)) { |
@@ -83,3 +83,3 @@ /*--------------------------------------------------------- | ||
// Trusted values are not sanitized, which is what we want for raw telemetry | ||
modifiedProperties[propertyKey] = new this.vscodeAPI.TelemetryTrustedValue(typeof propertyValue === 'string' ? propertyValue : propertyValue.value); | ||
modifiedProperties[propertyKey] = new this.vscodeAPI.TelemetryTrustedValue(typeof propertyValue === "string" ? propertyValue : propertyValue.value); | ||
} | ||
@@ -86,0 +86,0 @@ } |
@@ -53,3 +53,3 @@ /*--------------------------------------------------------- | ||
// Do not change this string as it gets found and replaced upon packaging | ||
"common.telemetryclientversion": "0.8.5" | ||
"common.telemetryclientversion": "0.9.0" | ||
}; | ||
@@ -56,0 +56,0 @@ } |
@@ -86,3 +86,3 @@ "use strict"; | ||
// Trusted values are not sanitized, which is what we want for raw telemetry | ||
modifiedProperties[propertyKey] = new this.vscodeAPI.TelemetryTrustedValue(typeof propertyValue === 'string' ? propertyValue : propertyValue.value); | ||
modifiedProperties[propertyKey] = new this.vscodeAPI.TelemetryTrustedValue(typeof propertyValue === "string" ? propertyValue : propertyValue.value); | ||
} | ||
@@ -89,0 +89,0 @@ } |
@@ -56,3 +56,3 @@ "use strict"; | ||
// Do not change this string as it gets found and replaced upon packaging | ||
"common.telemetryclientversion": "0.8.5" | ||
"common.telemetryclientversion": "0.9.0" | ||
}; | ||
@@ -59,0 +59,0 @@ } |
@@ -36,103 +36,4 @@ "use strict"; | ||
const _1dsClientFactory_1 = require("../common/1dsClientFactory"); | ||
const appInsightsClientFactory_1 = require("../common/appInsightsClientFactory"); | ||
/** | ||
* A factory function which creates a telemetry client to be used by an sender to send telemetry in a node application. | ||
* | ||
* @param key The app insights key | ||
* @param replacementOptions Optional list of {@link ReplacementOption replacements} to apply to the telemetry client. This allows | ||
* the sender to filter out any sensitive or unnecessary information from the telemetry server. | ||
* | ||
* @returns A promise which resolves to the telemetry client or rejects upon error | ||
*/ | ||
const appInsightsClientFactory = async (key, replacementOptions) => { | ||
let appInsightsClient; | ||
try { | ||
process.env["APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL"] = "1"; | ||
const appInsights = await Promise.resolve().then(() => __importStar(require(/* webpackMode: "eager" */ "applicationinsights"))); | ||
//check if another instance is already initialized | ||
if (appInsights.defaultClient) { | ||
appInsightsClient = new appInsights.TelemetryClient(key); | ||
// no other way to enable offline mode | ||
appInsightsClient.channel.setUseDiskRetryCaching(true); | ||
} | ||
else { | ||
appInsights.setup(key) | ||
.setAutoCollectRequests(false) | ||
.setAutoCollectPerformance(false) | ||
.setAutoCollectExceptions(false) | ||
.setAutoCollectDependencies(false) | ||
.setAutoDependencyCorrelation(false) | ||
.setAutoCollectConsole(false) | ||
.setAutoCollectHeartbeat(false) | ||
.setAutoCollectIncomingRequestAzureFunctions(false) | ||
.setUseDiskRetryCaching(true) | ||
.start(); | ||
appInsightsClient = appInsights.defaultClient; | ||
} | ||
if (vscode && vscode.env) { | ||
appInsightsClient.context.tags[appInsightsClient.context.keys.userId] = vscode.env.machineId; | ||
appInsightsClient.context.tags[appInsightsClient.context.keys.sessionId] = vscode.env.sessionId; | ||
appInsightsClient.context.tags[appInsightsClient.context.keys.cloudRole] = vscode.env.appName; | ||
appInsightsClient.context.tags[appInsightsClient.context.keys.cloudRoleInstance] = vscode.env.appName; | ||
} | ||
} | ||
catch (e) { | ||
return Promise.reject("Failed to initialize app insights!\n" + e.message); | ||
} | ||
if (replacementOptions?.length) { | ||
addReplacementOptions(appInsightsClient, replacementOptions); | ||
} | ||
// Sets the appinsights client into a standardized form | ||
const telemetryClient = { | ||
logEvent: (eventName, data) => { | ||
try { | ||
appInsightsClient?.trackEvent({ | ||
name: eventName, | ||
properties: data?.properties, | ||
measurements: data?.measurements | ||
}); | ||
} | ||
catch (e) { | ||
throw new Error("Failed to log event to app insights!\n" + e.message); | ||
} | ||
}, | ||
flush: async () => { | ||
try { | ||
appInsightsClient?.flush(); | ||
} | ||
catch (e) { | ||
throw new Error("Failed to flush app insights!\n" + e.message); | ||
} | ||
}, | ||
dispose: async () => { | ||
appInsightsClient?.flush({ isAppCrashing: true }); | ||
appInsightsClient = undefined; | ||
} | ||
}; | ||
return telemetryClient; | ||
}; | ||
/** | ||
* Adds replacement options to this {@link TelemetryClient}. | ||
* | ||
* If any replacement options are specified, this function will search through any event about to be | ||
* sent to the telemetry server and replace any matches with the specified replacement string. Both | ||
* the envelope and the base data will be searched. | ||
* | ||
* @param appInsightsClient The {@link TelemetryClient} to add the filters to. | ||
* @param replacementOptions The replacement options to add. | ||
*/ | ||
function addReplacementOptions(appInsightsClient, replacementOptions) { | ||
appInsightsClient.addTelemetryProcessor((event) => { | ||
if (Array.isArray(event.tags)) { | ||
event.tags.forEach(tag => util_1.TelemetryUtil.applyReplacements(tag, replacementOptions)); | ||
} | ||
else if (event.tags) { | ||
util_1.TelemetryUtil.applyReplacements(event.tags, replacementOptions); | ||
} | ||
if (event.data.baseData) { | ||
util_1.TelemetryUtil.applyReplacements(event.data.baseData, replacementOptions); | ||
} | ||
return true; | ||
}); | ||
} | ||
/** | ||
* Create a replacement for the XHTMLRequest object utilizing nodes HTTP module. | ||
@@ -180,3 +81,3 @@ * @returns A XHR override object used to override the XHTMLRequest object in the 1DS SDK | ||
constructor(key, replacementOptions) { | ||
let clientFactory = (key) => appInsightsClientFactory(key, replacementOptions); | ||
let clientFactory = (key) => (0, appInsightsClientFactory_1.appInsightsClientFactory)(key, getXHROverride(), replacementOptions); | ||
// If key is usable by 1DS use the 1DS SDk | ||
@@ -183,0 +84,0 @@ if (util_1.TelemetryUtil.shouldUseOneDataSystemSDK(key)) { |
{ | ||
"name": "@vscode/extension-telemetry", | ||
"description": "A module for Visual Studio Code extensions to report consistent telemetry.", | ||
"version": "0.8.5", | ||
"version": "0.9.0", | ||
"author": { | ||
@@ -23,19 +23,18 @@ "name": "Microsoft Corporation" | ||
"dependencies": { | ||
"@microsoft/1ds-core-js": "^3.2.13", | ||
"@microsoft/1ds-post-js": "^3.2.13", | ||
"@microsoft/applicationinsights-web-basic": "^3.0.2", | ||
"applicationinsights": "^2.7.1" | ||
"@microsoft/1ds-core-js": "^4.0.3", | ||
"@microsoft/1ds-post-js": "^4.0.3", | ||
"@microsoft/applicationinsights-web-basic": "^3.0.4" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^20.4.9", | ||
"@types/sinon": "^10.0.16", | ||
"@types/mocha": "^10.0.3", | ||
"@types/node": "^20.8.9", | ||
"@types/sinon": "^10.0.20", | ||
"@types/vscode": "^1.75.0", | ||
"@typescript-eslint/eslint-plugin": "^6.3.0", | ||
"@typescript-eslint/parser": "^6.3.0", | ||
"eslint": "^8.46.0", | ||
"@typescript-eslint/eslint-plugin": "^6.9.1", | ||
"@typescript-eslint/parser": "^6.9.1", | ||
"eslint": "^8.52.0", | ||
"mocha": "^10.2.0", | ||
"sinon": "^15.2.0", | ||
"typescript": "^5.1.6", | ||
"user-agent-data-types": "^0.3.1" | ||
"sinon": "^17.0.0", | ||
"typescript": "^5.2.2", | ||
"user-agent-data-types": "^0.4.2" | ||
}, | ||
@@ -42,0 +41,0 @@ "repository": { |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
67971
1.53%3
-25%17
13.33%1248
0.97%1
-50%+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed