Skip to content

Commit ae52629

Browse files
authored
Upgrade appinsights (microsoft#58999)
* Upgrade appinsights * Env, global updates before starting shared process * Disable console logging from appinsights Fixes microsoft#55417 * Move workaround to helper
1 parent d5d8d98 commit ae52629

File tree

10 files changed

+322
-124
lines changed

10 files changed

+322
-124
lines changed

build/lib/stats.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,27 @@ function submitAllStats(productJson, commit) {
105105
.setAutoCollectExceptions(false)
106106
.setAutoCollectPerformance(false)
107107
.setAutoCollectRequests(false)
108+
.setAutoCollectDependencies(false)
109+
.setAutoDependencyCorrelation(false)
108110
.start();
109-
var client = appInsights.getClient(productJson.aiConfig.asimovKey);
110-
client.config.endpointUrl = 'https://vortex.data.microsoft.com/collect/v1';
111+
appInsights.defaultClient.config.endpointUrl = 'https://vortex.data.microsoft.com/collect/v1';
111112
/* __GDPR__
112113
"monacoworkbench/packagemetrics" : {
113114
"commit" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
114-
"size" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true },
115-
"count" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true }
115+
"size" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
116+
"count" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
116117
}
117118
*/
118-
client.trackEvent("monacoworkbench/packagemetrics", { commit: commit, size: JSON.stringify(sizes), count: JSON.stringify(counts) });
119-
client.sendPendingData(function () { return resolve(); });
119+
appInsights.defaultClient.trackEvent({
120+
name: 'monacoworkbench/packagemetrics',
121+
properties: { commit: commit, size: JSON.stringify(sizes), count: JSON.stringify(counts) }
122+
});
123+
appInsights.defaultClient.flush({
124+
callback: function () {
125+
appInsights.dispose();
126+
resolve();
127+
}
128+
});
120129
});
121130
}
122131
exports.submitAllStats = submitAllStats;

build/lib/stats.ts

+30-19
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,36 @@ export function submitAllStats(productJson: any, commit: string): Promise<void>
105105
counts[entry.name] = entry.totalCount;
106106
}
107107

108-
appInsights.setup(productJson.aiConfig.asimovKey)
109-
.setAutoCollectConsole(false)
110-
.setAutoCollectExceptions(false)
111-
.setAutoCollectPerformance(false)
112-
.setAutoCollectRequests(false)
113-
.start();
114-
115-
const client = appInsights.getClient(productJson.aiConfig.asimovKey);
116-
client.config.endpointUrl = 'https://vortex.data.microsoft.com/collect/v1';
117-
118-
/* __GDPR__
119-
"monacoworkbench/packagemetrics" : {
120-
"commit" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
121-
"size" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true },
122-
"count" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true }
123-
}
124-
*/
125-
client.trackEvent(`monacoworkbench/packagemetrics`, { commit, size: JSON.stringify(sizes), count: JSON.stringify(counts) });
126-
client.sendPendingData(() => resolve());
108+
appInsights.setup(productJson.aiConfig.asimovKey)
109+
.setAutoCollectConsole(false)
110+
.setAutoCollectExceptions(false)
111+
.setAutoCollectPerformance(false)
112+
.setAutoCollectRequests(false)
113+
.setAutoCollectDependencies(false)
114+
.setAutoDependencyCorrelation(false)
115+
.start();
116+
117+
appInsights.defaultClient.config.endpointUrl = 'https://vortex.data.microsoft.com/collect/v1';
118+
119+
/* __GDPR__
120+
"monacoworkbench/packagemetrics" : {
121+
"commit" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
122+
"size" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" },
123+
"count" : {"classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }
124+
}
125+
*/
126+
appInsights.defaultClient.trackEvent({
127+
name: 'monacoworkbench/packagemetrics',
128+
properties: { commit, size: JSON.stringify(sizes), count: JSON.stringify(counts) }
129+
});
130+
131+
132+
appInsights.defaultClient.flush({
133+
callback: () => {
134+
appInsights.dispose();
135+
resolve();
136+
}
137+
});
127138
});
128139

129140
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"download-builtin-extensions": "node build/lib/builtInExtensions.js"
2626
},
2727
"dependencies": {
28-
"applicationinsights": "0.18.0",
28+
"applicationinsights": "1.0.3",
2929
"fast-plist": "0.1.2",
3030
"gc-signals": "^0.0.1",
3131
"getmac": "1.4.1",

src/bootstrap.js

+11
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,15 @@ exports.configurePortable = function () {
217217
isPortable
218218
};
219219
};
220+
//#endregion
221+
222+
//#region ApplicationInsights
223+
/**
224+
* Prevents appinsights from monkey patching modules.
225+
* This should be called before importing the applicationinsights module
226+
*/
227+
exports.avoidMonkeyPatchFromAppInsights = function () {
228+
process.env['APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL'] = true; // Skip monkey patching of 3rd party modules by appinsights
229+
global['diagnosticsSource'] = {}; // Prevents diagnostic channel (which patches "require") from initializing entirely
230+
};
220231
//#endregion

src/cli.js

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
const bootstrap = require('./bootstrap');
1010

11+
// Avoid Monkey Patches from Application Insights
12+
bootstrap.avoidMonkeyPatchFromAppInsights();
13+
1114
// Enable portable support
1215
bootstrap.configurePortable();
1316

src/typings/applicationInsights.d.ts

+195-43
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,216 @@
33
* the auto-collection behavior of the application insights module.
44
*/
55
declare module ApplicationInsights {
6-
var client: any;
6+
77
/**
8-
* Initializes a client with the given instrumentation key, if this is not specified, the value will be
9-
* read from the environment variable APPINSIGHTS_INSTRUMENTATIONKEY
10-
* @returns {ApplicationInsights/Client} a new client
11-
*/
12-
function getClient(instrumentationKey?: string): any /*Client*/;
8+
* The default client, initialized when setup was called. To initialize a different client
9+
* with its own configuration, use `new TelemetryClient(instrumentationKey?)`.
10+
*/
11+
var defaultClient: TelemetryClient;
1312
/**
14-
* Initializes the default client of the client and sets the default configuration
15-
* @param instrumentationKey the instrumentation key to use. Optional, if this is not specified, the value will be
16-
* read from the environment variable APPINSIGHTS_INSTRUMENTATIONKEY
17-
* @returns {ApplicationInsights} this class
13+
* Initializes the default client. Should be called after setting
14+
* configuration options.
15+
*
16+
* @param instrumentationKey the instrumentation key to use. Optional, if
17+
* this is not specified, the value will be read from the environment
18+
* variable APPINSIGHTS_INSTRUMENTATIONKEY.
19+
* @returns {Configuration} the configuration class to initialize
20+
* and start the SDK.
1821
*/
19-
function setup(instrumentationKey?: string): typeof ApplicationInsights;
22+
function setup(instrumentationKey?: string): typeof Configuration;
2023
/**
21-
* Starts automatic collection of telemetry. Prior to calling start no telemetry will be collected
24+
* Starts automatic collection of telemetry. Prior to calling start no
25+
* telemetry will be *automatically* collected, though manual collection
26+
* is enabled.
2227
* @returns {ApplicationInsights} this class
2328
*/
24-
function start(): typeof ApplicationInsights;
29+
function start(): typeof Configuration;
2530
/**
26-
* Sets the state of console tracking (enabled by default)
27-
* @param value if true console activity will be sent to Application Insights
28-
* @returns {ApplicationInsights} this class
31+
* The active configuration for global SDK behaviors, such as autocollection.
2932
*/
30-
function setAutoCollectConsole(value: boolean): typeof ApplicationInsights;
33+
class Configuration {
34+
static start: typeof start;
35+
/**
36+
* Sets the state of console and logger tracking (enabled by default for third-party loggers only)
37+
* @param value if true logger activity will be sent to Application Insights
38+
* @param collectConsoleLog if true, logger autocollection will include console.log calls (default false)
39+
* @returns {Configuration} this class
40+
*/
41+
static setAutoCollectConsole(value: boolean, collectConsoleLog?: boolean): typeof Configuration;
42+
/**
43+
* Sets the state of exception tracking (enabled by default)
44+
* @param value if true uncaught exceptions will be sent to Application Insights
45+
* @returns {Configuration} this class
46+
*/
47+
static setAutoCollectExceptions(value: boolean): typeof Configuration;
48+
/**
49+
* Sets the state of performance tracking (enabled by default)
50+
* @param value if true performance counters will be collected every second and sent to Application Insights
51+
* @returns {Configuration} this class
52+
*/
53+
static setAutoCollectPerformance(value: boolean): typeof Configuration;
54+
/**
55+
* Sets the state of request tracking (enabled by default)
56+
* @param value if true requests will be sent to Application Insights
57+
* @returns {Configuration} this class
58+
*/
59+
static setAutoCollectRequests(value: boolean): typeof Configuration;
60+
/**
61+
* Sets the state of dependency tracking (enabled by default)
62+
* @param value if true dependencies will be sent to Application Insights
63+
* @returns {Configuration} this class
64+
*/
65+
static setAutoCollectDependencies(value: boolean): typeof Configuration;
66+
/**
67+
* Sets the state of automatic dependency correlation (enabled by default)
68+
* @param value if true dependencies will be correlated with requests
69+
* @returns {Configuration} this class
70+
*/
71+
static setAutoDependencyCorrelation(value: boolean): typeof Configuration;
72+
/**
73+
* Enable or disable disk-backed retry caching to cache events when client is offline (enabled by default)
74+
* Note that this method only applies to the default client. Disk-backed retry caching is disabled by default for additional clients.
75+
* For enable for additional clients, use client.channel.setUseDiskRetryCaching(true).
76+
* These cached events are stored in your system or user's temporary directory and access restricted to your user when possible.
77+
* @param value if true events that occured while client is offline will be cached on disk
78+
* @param resendInterval The wait interval for resending cached events.
79+
* @param maxBytesOnDisk The maximum size (in bytes) that the created temporary directory for cache events can grow to, before caching is disabled.
80+
* @returns {Configuration} this class
81+
*/
82+
static setUseDiskRetryCaching(value: boolean, resendInterval?: number, maxBytesOnDisk?: number): typeof Configuration;
83+
/**
84+
* Enables debug and warning logging for AppInsights itself.
85+
* @param enableDebugLogging if true, enables debug logging
86+
* @param enableWarningLogging if true, enables warning logging
87+
* @returns {Configuration} this class
88+
*/
89+
static setInternalLogging(enableDebugLogging?: boolean, enableWarningLogging?: boolean): typeof Configuration;
90+
}
3191
/**
32-
* Sets the state of exception tracking (enabled by default)
33-
* @param value if true uncaught exceptions will be sent to Application Insights
34-
* @returns {ApplicationInsights} this class
35-
*/
36-
function setAutoCollectExceptions(value: boolean): typeof ApplicationInsights;
37-
/**
38-
* Sets the state of performance tracking (enabled by default)
39-
* @param value if true performance counters will be collected every second and sent to Application Insights
40-
* @returns {ApplicationInsights} this class
41-
*/
42-
function setAutoCollectPerformance(value: boolean): typeof ApplicationInsights;
92+
* Disposes the default client and all the auto collectors so they can be reinitialized with different configuration
93+
*/
94+
function dispose(): void;
95+
96+
interface ITelemetryClient {
97+
config: Config;
98+
channel: Channel;
99+
/**
100+
* Log a user action or other occurrence.
101+
* @param telemetry Object encapsulating tracking options
102+
*/
103+
trackEvent(telemetry: EventTelemetry): void;
104+
/**
105+
* Immediately send all queued telemetry.
106+
* @param options Flush options, including indicator whether app is crashing and callback
107+
*/
108+
flush(options?: FlushOptions): void;
109+
110+
}
111+
112+
class TelemetryClient implements ITelemetryClient {
113+
config: Config;
114+
channel: Channel;
115+
/**
116+
* Constructs a new client of the client
117+
* @param iKey the instrumentation key to use (read from environment variable if not specified)
118+
*/
119+
constructor(iKey?: string);
120+
/**
121+
* Log a user action or other occurrence.
122+
* @param telemetry Object encapsulating tracking options
123+
*/
124+
trackEvent(telemetry: EventTelemetry): void;
125+
/**
126+
* Immediately send all queued telemetry.
127+
* @param options Flush options, including indicator whether app is crashing and callback
128+
*/
129+
flush(options?: FlushOptions): void;
130+
131+
}
132+
133+
class Config {
134+
static ENV_azurePrefix: string;
135+
static ENV_iKey: string;
136+
static legacy_ENV_iKey: string;
137+
static ENV_profileQueryEndpoint: string;
138+
static ENV_http_proxy: string;
139+
static ENV_https_proxy: string;
140+
/** An identifier for your Application Insights resource */
141+
instrumentationKey: string;
142+
/** The id for cross-component correlation. READ ONLY. */
143+
correlationId: string;
144+
/** The ingestion endpoint to send telemetry payloads to */
145+
endpointUrl: string;
146+
/** The maximum number of telemetry items to include in a payload to the ingestion endpoint (Default 250) */
147+
maxBatchSize: number;
148+
/** The maximum amount of time to wait for a payload to reach maxBatchSize (Default 15000) */
149+
maxBatchIntervalMs: number;
150+
/** A flag indicating if telemetry transmission is disabled (Default false) */
151+
disableAppInsights: boolean;
152+
/** The percentage of telemetry items tracked that should be transmitted (Default 100) */
153+
samplingPercentage: number;
154+
/** The time to wait before retrying to retrieve the id for cross-component correlation (Default 30000) */
155+
correlationIdRetryIntervalMs: number;
156+
/** A list of domains to exclude from cross-component header injection */
157+
correlationHeaderExcludedDomains: string[];
158+
/** A proxy server for SDK HTTP traffic (Optional, Default pulled from `http_proxy` environment variable) */
159+
proxyHttpUrl: string;
160+
/** A proxy server for SDK HTTPS traffic (Optional, Default pulled from `https_proxy` environment variable) */
161+
proxyHttpsUrl: string;
162+
}
163+
164+
interface Channel {
165+
/**
166+
* Enable or disable disk-backed retry caching to cache events when client is offline (enabled by default)
167+
* These cached events are stored in your system or user's temporary directory and access restricted to your user when possible.
168+
* @param value if true events that occured while client is offline will be cached on disk
169+
* @param resendInterval The wait interval for resending cached events.
170+
* @param maxBytesOnDisk The maximum size (in bytes) that the created temporary directory for cache events can grow to, before caching is disabled.
171+
* @returns {Configuration} this class
172+
*/
173+
setUseDiskRetryCaching(value: boolean, resendInterval?: number, maxBytesOnDisk?: number): void;
174+
}
175+
43176
/**
44-
* Sets the state of request tracking (enabled by default)
45-
* @param value if true requests will be sent to Application Insights
46-
* @returns {ApplicationInsights} this class
177+
* Telemetry about the custom event of interest, such application workflow event, business logic event (purchase) and anything that
178+
* you would like to track and aggregate by count. Event can contain measurements such as purchase amount associated with purchase event
47179
*/
48-
function setAutoCollectRequests(value: boolean): typeof ApplicationInsights;
180+
interface EventTelemetry {
181+
/**
182+
* Name of the event
183+
*/
184+
name: string;
185+
/**
186+
* Metrics associated with this event, displayed in Metrics Explorer on the portal.
187+
*/
188+
measurements?: {
189+
[key: string]: number;
190+
};
191+
/**
192+
* Additional data used to filter events and metrics in the portal. Defaults to empty.
193+
*/
194+
properties?: {
195+
[key: string]: string;
196+
};
197+
}
49198

50-
/**
51-
* Sets the state of enabling offline mode to cache event when client is offline (disabled by default)
52-
* @param value if true events that happen while client is offline will be cahced on disk,
53-
* client will retry to send events when back online
54-
* @returns {ApplicationInsights} this class
55-
*/
56-
function setOfflineMode(value: boolean): typeof ApplicationInsights;
57199
/**
58-
* Enables verbose debug logging
59-
* @returns {ApplicationInsights} this class
200+
* Encapsulates options passed into client.flush() function
60201
*/
61-
function enableVerboseLogging(): typeof ApplicationInsights;
202+
interface FlushOptions {
203+
/**
204+
* Flag indicating whether application is crashing. When this flag is set to true
205+
* and storing data locally is enabled, Node.JS SDK will attempt to store data on disk
206+
*/
207+
isAppCrashing?: boolean;
208+
/**
209+
* Callback that will be invoked with the response from server, in case of isAppCrashing set to true,
210+
* with immediate notification that data was stored
211+
*/
212+
callback?: (v: string) => void;
213+
}
62214
}
63215

64216
declare module 'applicationinsights' {
65-
export = ApplicationInsights;
217+
export = ApplicationInsights;
66218
}

src/vs/code/electron-browser/sharedProcess/sharedProcess.js

+4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
//@ts-check
77
'use strict';
88

9+
const bootstrap = require('../../../../bootstrap');
910
const bootstrapWindow = require('../../../../bootstrap-window');
1011

12+
// Avoid Monkey Patches from Application Insights
13+
bootstrap.avoidMonkeyPatchFromAppInsights();
14+
1115
bootstrapWindow.load(['vs/code/electron-browser/sharedProcess/sharedProcessMain'], function (sharedProcess, configuration) {
1216
sharedProcess.startup({
1317
machineId: configuration.machineId

0 commit comments

Comments
 (0)