@microsoft/applicationinsights-dependencies-js 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-06
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/applicationinsights-dependencies-js.integrity.json +9 -9
- package/browser/applicationinsights-dependencies-js.js +1329 -843
- package/browser/applicationinsights-dependencies-js.js.map +1 -1
- package/browser/applicationinsights-dependencies-js.min.js +2 -2
- package/browser/applicationinsights-dependencies-js.min.js.map +1 -1
- package/dist/applicationinsights-dependencies-js.api.json +46 -53
- package/dist/applicationinsights-dependencies-js.api.md +0 -2
- package/dist/applicationinsights-dependencies-js.d.ts +1 -2
- package/dist/applicationinsights-dependencies-js.js +1329 -843
- package/dist/applicationinsights-dependencies-js.js.map +1 -1
- package/dist/applicationinsights-dependencies-js.min.js +2 -2
- package/dist/applicationinsights-dependencies-js.min.js.map +1 -1
- package/dist/applicationinsights-dependencies-js.rollup.d.ts +1 -2
- package/dist-esm/TraceParent.js +1 -1
- package/dist-esm/ajax.js +181 -148
- package/dist-esm/ajax.js.map +1 -1
- package/dist-esm/ajaxRecord.js +1 -1
- package/dist-esm/ajaxUtils.js +1 -1
- package/dist-esm/applicationinsights-dependencies-js.js +1 -1
- package/package.json +4 -4
- package/src/ajax.ts +214 -170
- package/src/ajaxRecord.ts +1 -1
- package/types/ajax.d.ts +0 -1
- package/types/tsdoc-metadata.json +1 -1
package/src/ajax.ts
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
import {
|
|
5
5
|
RequestHeaders, CorrelationIdHelper, TelemetryItemCreator, ICorrelationConfig,
|
|
6
6
|
RemoteDependencyData, dateTimeUtilsNow, DisabledPropertyName, IDependencyTelemetry,
|
|
7
|
-
IConfig, ITelemetryContext, PropertiesPluginIdentifier,
|
|
7
|
+
IConfig, ITelemetryContext, PropertiesPluginIdentifier, eDistributedTracingModes, IRequestContext, isInternalApplicationInsightsEndpoint
|
|
8
8
|
} from "@microsoft/applicationinsights-common";
|
|
9
9
|
import {
|
|
10
|
-
isNullOrUndefined, arrForEach, isString, strTrim, isFunction,
|
|
10
|
+
isNullOrUndefined, arrForEach, isString, strTrim, isFunction, eLoggingSeverity, _eInternalMessageId,
|
|
11
11
|
IAppInsightsCore, BaseTelemetryPlugin, ITelemetryPluginChain, IConfiguration, IPlugin, ITelemetryItem, IProcessTelemetryContext,
|
|
12
12
|
getLocation, getGlobal, strPrototype, IInstrumentCallDetails, InstrumentFunc, InstrumentProto, getPerformance,
|
|
13
|
-
IInstrumentHooksCallbacks,
|
|
13
|
+
IInstrumentHooksCallbacks, objForEachKey, generateW3CId, getIEVersion, dumpObj, ICustomProperties, isXhrSupported, eventOn,
|
|
14
|
+
mergeEvtNamespace, createUniqueNamespace, createProcessTelemetryContext
|
|
14
15
|
} from "@microsoft/applicationinsights-core-js";
|
|
15
16
|
import { ajaxRecord, IAjaxRecordResponse } from "./ajaxRecord";
|
|
16
17
|
import { Traceparent } from "./TraceParent";
|
|
@@ -21,6 +22,7 @@ const strDiagLog = "diagLog";
|
|
|
21
22
|
const strAjaxData = "ajaxData";
|
|
22
23
|
const strThrowInternal = "throwInternal";
|
|
23
24
|
const strFetch = "fetch";
|
|
25
|
+
const strTrackDependencyDataInternal = "trackDependencyDataInternal"; // Using string to help with minification
|
|
24
26
|
|
|
25
27
|
// Using a global value so that to handle same iKey with multiple app insights instances (mostly for testing)
|
|
26
28
|
let _markCount: number = 0;
|
|
@@ -72,7 +74,7 @@ function _supportsAjaxMonitoring(ajaxMonitorInstance:AjaxMonitor): boolean {
|
|
|
72
74
|
// We can't decorate the xhr object so disable monitoring
|
|
73
75
|
result = false;
|
|
74
76
|
_throwInternalCritical(ajaxMonitorInstance,
|
|
75
|
-
|
|
77
|
+
_eInternalMessageId.FailedMonitorAjaxOpen,
|
|
76
78
|
"Failed to enable XMLHttpRequest monitoring, extension is not supported",
|
|
77
79
|
{
|
|
78
80
|
exception: dumpObj(e)
|
|
@@ -100,17 +102,17 @@ function _getFailedAjaxDiagnosticsMessage(xhr: XMLHttpRequestInstrumented): stri
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
/** @ignore */
|
|
103
|
-
function _throwInternalCritical(ajaxMonitorInstance:AjaxMonitor, msgId:
|
|
104
|
-
ajaxMonitorInstance[strDiagLog]()[strThrowInternal](
|
|
105
|
+
function _throwInternalCritical(ajaxMonitorInstance:AjaxMonitor, msgId: _eInternalMessageId, message: string, properties?: Object, isUserAct?: boolean): void {
|
|
106
|
+
ajaxMonitorInstance[strDiagLog]()[strThrowInternal](eLoggingSeverity.CRITICAL, msgId, message, properties, isUserAct);
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
/** @ignore */
|
|
108
|
-
function _throwInternalWarning(ajaxMonitorInstance:AjaxMonitor, msgId:
|
|
109
|
-
ajaxMonitorInstance[strDiagLog]()[strThrowInternal](
|
|
110
|
+
function _throwInternalWarning(ajaxMonitorInstance:AjaxMonitor, msgId: _eInternalMessageId, message: string, properties?: Object, isUserAct?: boolean): void {
|
|
111
|
+
ajaxMonitorInstance[strDiagLog]()[strThrowInternal](eLoggingSeverity.WARNING, msgId, message, properties, isUserAct);
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
/** @Ignore */
|
|
113
|
-
function _createErrorCallbackFunc(ajaxMonitorInstance:AjaxMonitor, internalMessage:
|
|
115
|
+
function _createErrorCallbackFunc(ajaxMonitorInstance:AjaxMonitor, internalMessage: _eInternalMessageId, message:string) {
|
|
114
116
|
// tslint:disable-next-line
|
|
115
117
|
return function (args:IInstrumentCallDetails) {
|
|
116
118
|
_throwInternalCritical(ajaxMonitorInstance,
|
|
@@ -158,7 +160,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
158
160
|
disableFetchTracking: true,
|
|
159
161
|
excludeRequestFromAutoTrackingPatterns: undefined,
|
|
160
162
|
disableCorrelationHeaders: false,
|
|
161
|
-
distributedTracingMode:
|
|
163
|
+
distributedTracingMode: eDistributedTracingModes.AI_AND_W3C,
|
|
162
164
|
correlationHeaderExcludedDomains: [
|
|
163
165
|
"*.blob.core.windows.net",
|
|
164
166
|
"*.blob.core.chinacloudapi.cn",
|
|
@@ -198,90 +200,49 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
198
200
|
|
|
199
201
|
constructor() {
|
|
200
202
|
super();
|
|
201
|
-
let
|
|
202
|
-
let
|
|
203
|
-
let
|
|
204
|
-
let
|
|
205
|
-
let
|
|
206
|
-
let
|
|
207
|
-
let
|
|
208
|
-
let _enableAjaxErrorStatusText = false;
|
|
209
|
-
let _trackAjaxAttempts: number = 0;
|
|
203
|
+
let _fetchInitialized: boolean; // fetch monitoring initialized
|
|
204
|
+
let _xhrInitialized: boolean; // XHR monitoring initialized
|
|
205
|
+
let _currentWindowHost: string;
|
|
206
|
+
let _config: ICorrelationConfig;
|
|
207
|
+
let _enableRequestHeaderTracking: boolean;
|
|
208
|
+
let _enableAjaxErrorStatusText: boolean;
|
|
209
|
+
let _trackAjaxAttempts: number;
|
|
210
210
|
let _context: ITelemetryContext;
|
|
211
211
|
let _isUsingW3CHeaders: boolean;
|
|
212
212
|
let _isUsingAIHeaders: boolean;
|
|
213
213
|
let _markPrefix: string;
|
|
214
|
-
let _enableAjaxPerfTracking:boolean
|
|
215
|
-
let _maxAjaxCallsPerView:number
|
|
216
|
-
let _enableResponseHeaderTracking:boolean
|
|
217
|
-
let
|
|
218
|
-
let
|
|
214
|
+
let _enableAjaxPerfTracking: boolean;
|
|
215
|
+
let _maxAjaxCallsPerView: number;
|
|
216
|
+
let _enableResponseHeaderTracking: boolean;
|
|
217
|
+
let _disabledUrls: any;
|
|
218
|
+
let _disableAjaxTracking: boolean;
|
|
219
|
+
let _disableFetchTracking: boolean;
|
|
219
220
|
let _excludeRequestFromAutoTrackingPatterns: string[] | RegExp[];
|
|
220
221
|
let _addRequestContext: (requestContext?: IRequestContext) => ICustomProperties;
|
|
222
|
+
let _evtNamespace: string | string[];
|
|
223
|
+
|
|
224
|
+
dynamicProto(AjaxMonitor, this, (_self, _base) => {
|
|
225
|
+
let _addHook = _base._addHook;
|
|
226
|
+
|
|
227
|
+
_initDefaults();
|
|
221
228
|
|
|
222
|
-
dynamicProto(AjaxMonitor, this, (_self, base) => {
|
|
223
229
|
_self.initialize = (config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) => {
|
|
224
230
|
if (!_self.isInitialized()) {
|
|
225
|
-
|
|
226
|
-
let ctx = _self._getTelCtx();
|
|
227
|
-
const defaultConfig = AjaxMonitor.getDefaultConfig();
|
|
228
|
-
objForEachKey(defaultConfig, (field, value) => {
|
|
229
|
-
_config[field] = ctx.getConfig(AjaxMonitor.identifier, field, value);
|
|
230
|
-
});
|
|
231
|
+
_base.initialize(config, core, extensions, pluginChain);
|
|
231
232
|
|
|
232
|
-
|
|
233
|
-
_enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
|
|
234
|
-
_enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
|
|
235
|
-
_enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
|
|
236
|
-
_maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
|
|
237
|
-
_enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
|
|
238
|
-
_excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
|
|
239
|
-
_addRequestContext = _config.addRequestContext;
|
|
240
|
-
|
|
241
|
-
_isUsingAIHeaders = distributedTracingMode === DistributedTracingModes.AI || distributedTracingMode === DistributedTracingModes.AI_AND_W3C;
|
|
242
|
-
_isUsingW3CHeaders = distributedTracingMode === DistributedTracingModes.AI_AND_W3C || distributedTracingMode === DistributedTracingModes.W3C;
|
|
243
|
-
if (_enableAjaxPerfTracking) {
|
|
244
|
-
let iKey = config.instrumentationKey || "unkwn";
|
|
245
|
-
if (iKey.length > 5) {
|
|
246
|
-
_markPrefix = AJAX_MONITOR_PREFIX + iKey.substring(iKey.length - 5) + ".";
|
|
247
|
-
} else {
|
|
248
|
-
_markPrefix = AJAX_MONITOR_PREFIX + iKey + ".";
|
|
249
|
-
}
|
|
250
|
-
}
|
|
233
|
+
_evtNamespace = mergeEvtNamespace(createUniqueNamespace("ajax"), core && core.evtNamespace && core.evtNamespace());
|
|
251
234
|
|
|
252
|
-
|
|
253
|
-
_instrumentXhr();
|
|
254
|
-
}
|
|
235
|
+
_populateDefaults(config);
|
|
255
236
|
|
|
237
|
+
_instrumentXhr();
|
|
256
238
|
_instrumentFetch();
|
|
257
|
-
|
|
258
|
-
if (extensions.length > 0 && extensions) {
|
|
259
|
-
let propExt: any, extIx = 0;
|
|
260
|
-
while (!propExt && extIx < extensions.length) {
|
|
261
|
-
if (extensions[extIx] && extensions[extIx].identifier === PropertiesPluginIdentifier) {
|
|
262
|
-
propExt = extensions[extIx];
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
extIx++;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (propExt) {
|
|
269
|
-
_context = propExt.context; // we could move IPropertiesPlugin to common as well
|
|
270
|
-
}
|
|
271
|
-
}
|
|
239
|
+
_populateContext();
|
|
272
240
|
}
|
|
273
241
|
};
|
|
274
242
|
|
|
275
|
-
_self.
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
fn.rm();
|
|
279
|
-
});
|
|
280
|
-
_hooks = [];
|
|
281
|
-
_fetchInitialized = false;
|
|
282
|
-
_xhrInitialized = false;
|
|
283
|
-
_self.setInitialized(false);
|
|
284
|
-
}
|
|
243
|
+
_self._doTeardown = () => {
|
|
244
|
+
_initDefaults();
|
|
245
|
+
};
|
|
285
246
|
|
|
286
247
|
_self.trackDependencyData = (dependency: IDependencyTelemetry, properties?: { [key: string]: any }) => {
|
|
287
248
|
_self[strTrackDependencyDataInternal](dependency, properties);
|
|
@@ -359,8 +320,8 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
359
320
|
// Hack since expected format in w3c mode is |abc.def.
|
|
360
321
|
// Non-w3c format is |abc.def
|
|
361
322
|
// @todo Remove if better solution is available, e.g. handle in portal
|
|
362
|
-
if ((_config.distributedTracingMode ===
|
|
363
|
-
|| _config.distributedTracingMode ===
|
|
323
|
+
if ((_config.distributedTracingMode === eDistributedTracingModes.W3C
|
|
324
|
+
|| _config.distributedTracingMode === eDistributedTracingModes.AI_AND_W3C)
|
|
364
325
|
&& typeof dependency.id === "string" && dependency.id[dependency.id.length - 1] !== "."
|
|
365
326
|
) {
|
|
366
327
|
dependency.id += ".";
|
|
@@ -379,7 +340,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
379
340
|
_self.core.track(item);
|
|
380
341
|
} else if (_trackAjaxAttempts === _maxAjaxCallsPerView) {
|
|
381
342
|
_throwInternalCritical(_self,
|
|
382
|
-
|
|
343
|
+
_eInternalMessageId.MaxAjaxPerPVExceeded,
|
|
383
344
|
"Maximum ajax per page view limit reached, ajax monitoring is paused until the next trackPageView(). In order to increase the limit set the maxAjaxCallsPerView configuration parameter.",
|
|
384
345
|
true);
|
|
385
346
|
}
|
|
@@ -387,6 +348,73 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
387
348
|
++_trackAjaxAttempts;
|
|
388
349
|
}
|
|
389
350
|
|
|
351
|
+
function _initDefaults() {
|
|
352
|
+
let location = getLocation();
|
|
353
|
+
_fetchInitialized = false; // fetch monitoring initialized
|
|
354
|
+
_xhrInitialized = false; // XHR monitoring initialized
|
|
355
|
+
_currentWindowHost = location && location.host && location.host.toLowerCase();
|
|
356
|
+
_config = AjaxMonitor.getEmptyConfig();
|
|
357
|
+
_enableRequestHeaderTracking = false;
|
|
358
|
+
_enableAjaxErrorStatusText = false;
|
|
359
|
+
_trackAjaxAttempts = 0;
|
|
360
|
+
_context = null;
|
|
361
|
+
_isUsingW3CHeaders = false;
|
|
362
|
+
_isUsingAIHeaders = false;
|
|
363
|
+
_markPrefix = null;
|
|
364
|
+
_enableAjaxPerfTracking = false;
|
|
365
|
+
_maxAjaxCallsPerView = 0;
|
|
366
|
+
_enableResponseHeaderTracking = false;
|
|
367
|
+
_disabledUrls = {};
|
|
368
|
+
_disableAjaxTracking = false;
|
|
369
|
+
_disableFetchTracking = true;
|
|
370
|
+
|
|
371
|
+
_excludeRequestFromAutoTrackingPatterns = null
|
|
372
|
+
_addRequestContext = null;
|
|
373
|
+
_evtNamespace = null;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function _populateDefaults(config: IConfiguration) {
|
|
377
|
+
let ctx = createProcessTelemetryContext(null, config, _self.core);
|
|
378
|
+
|
|
379
|
+
// Reset to the empty config
|
|
380
|
+
_config = AjaxMonitor.getEmptyConfig();
|
|
381
|
+
const defaultConfig = AjaxMonitor.getDefaultConfig();
|
|
382
|
+
objForEachKey(defaultConfig, (field, value) => {
|
|
383
|
+
_config[field] = ctx.getConfig(AjaxMonitor.identifier, field, value);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
let distributedTracingMode = _config.distributedTracingMode;
|
|
387
|
+
_enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
|
|
388
|
+
_enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
|
|
389
|
+
_enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
|
|
390
|
+
_maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
|
|
391
|
+
_enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
|
|
392
|
+
_excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
|
|
393
|
+
_addRequestContext = _config.addRequestContext;
|
|
394
|
+
|
|
395
|
+
_isUsingAIHeaders = distributedTracingMode === eDistributedTracingModes.AI || distributedTracingMode === eDistributedTracingModes.AI_AND_W3C;
|
|
396
|
+
_isUsingW3CHeaders = distributedTracingMode === eDistributedTracingModes.AI_AND_W3C || distributedTracingMode === eDistributedTracingModes.W3C;
|
|
397
|
+
|
|
398
|
+
if (_enableAjaxPerfTracking) {
|
|
399
|
+
let iKey = config.instrumentationKey || "unkwn";
|
|
400
|
+
if (iKey.length > 5) {
|
|
401
|
+
_markPrefix = AJAX_MONITOR_PREFIX + iKey.substring(iKey.length - 5) + ".";
|
|
402
|
+
} else {
|
|
403
|
+
_markPrefix = AJAX_MONITOR_PREFIX + iKey + ".";
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
_disableAjaxTracking = !!_config.disableAjaxTracking;
|
|
408
|
+
_disableFetchTracking = !!_config.disableFetchTracking;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function _populateContext() {
|
|
412
|
+
let propExt = _self.core.getPlugin<any>(PropertiesPluginIdentifier);
|
|
413
|
+
if (propExt) {
|
|
414
|
+
_context = propExt.plugin.context; // we could move IPropertiesPlugin to common as well
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
390
418
|
// discard the header if it's defined as ignoreHeaders in ICorrelationConfig
|
|
391
419
|
function _canIncludeHeaders(header: string) {
|
|
392
420
|
let rlt = true;
|
|
@@ -410,12 +438,13 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
410
438
|
|
|
411
439
|
let global = getGlobal();
|
|
412
440
|
let isPolyfill = (fetch as any).polyfill;
|
|
413
|
-
if (
|
|
414
|
-
|
|
441
|
+
if (!_disableFetchTracking && !_fetchInitialized) {
|
|
442
|
+
_addHook(InstrumentFunc(global, strFetch, {
|
|
443
|
+
ns: _evtNamespace,
|
|
415
444
|
// Add request hook
|
|
416
445
|
req: (callDetails: IInstrumentCallDetails, input, init) => {
|
|
417
446
|
let fetchData: ajaxRecord;
|
|
418
|
-
if (_fetchInitialized &&
|
|
447
|
+
if (!_disableFetchTracking && _fetchInitialized &&
|
|
419
448
|
!_isDisabledRequest(null, input, init) &&
|
|
420
449
|
// If we have a polyfil and XHR instrumented then let XHR report otherwise we get duplicates
|
|
421
450
|
!(isPolyfill && _xhrInitialized)) {
|
|
@@ -429,39 +458,43 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
429
458
|
}
|
|
430
459
|
},
|
|
431
460
|
rsp: (callDetails: IInstrumentCallDetails, input) => {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
+
if (!_disableFetchTracking) {
|
|
462
|
+
let fetchData = callDetails.ctx().data;
|
|
463
|
+
if (fetchData) {
|
|
464
|
+
// Replace the result with the new promise from this code
|
|
465
|
+
callDetails.rslt = callDetails.rslt.then((response: any) => {
|
|
466
|
+
_reportFetchMetrics(callDetails, (response||{}).status, input, response, fetchData, () => {
|
|
467
|
+
let ajaxResponse:IAjaxRecordResponse = {
|
|
468
|
+
statusText: response.statusText,
|
|
469
|
+
headerMap: null,
|
|
470
|
+
correlationContext: _getFetchCorrelationContext(response)
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
if (_enableResponseHeaderTracking) {
|
|
474
|
+
const responseHeaderMap = {};
|
|
475
|
+
response.headers.forEach((value: string, name: string) => {
|
|
476
|
+
if (_canIncludeHeaders(name)) {
|
|
477
|
+
responseHeaderMap[name] = value;
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
ajaxResponse.headerMap = responseHeaderMap;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
return ajaxResponse;
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
return response;
|
|
488
|
+
})
|
|
489
|
+
.catch((reason: any) => {
|
|
490
|
+
_reportFetchMetrics(callDetails, 0, input, null, fetchData, null, { error: reason.message });
|
|
491
|
+
throw reason;
|
|
492
|
+
});
|
|
493
|
+
}
|
|
461
494
|
}
|
|
462
495
|
},
|
|
463
496
|
// Create an error callback to report any hook errors
|
|
464
|
-
hkErr: _createErrorCallbackFunc(_self,
|
|
497
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxOpen,
|
|
465
498
|
"Failed to monitor Window.fetch, monitoring data for this fetch call may be incorrect.")
|
|
466
499
|
}));
|
|
467
500
|
|
|
@@ -473,7 +506,8 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
473
506
|
// Note: Polyfill implementations that don't support the "poyyfill" tag are not supported
|
|
474
507
|
// the workaround is to add a polyfill property to your fetch implementation before initializing
|
|
475
508
|
// App Insights
|
|
476
|
-
|
|
509
|
+
_addHook(InstrumentFunc(global, strFetch, {
|
|
510
|
+
ns: _evtNamespace,
|
|
477
511
|
req: (callDetails: IInstrumentCallDetails, input, init) => {
|
|
478
512
|
// Just call so that we record any disabled URL
|
|
479
513
|
_isDisabledRequest(null, input, init);
|
|
@@ -489,73 +523,83 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
489
523
|
}
|
|
490
524
|
|
|
491
525
|
function _hookProto(target: any, funcName: string, callbacks: IInstrumentHooksCallbacks) {
|
|
492
|
-
|
|
526
|
+
_addHook(InstrumentProto(target, funcName, callbacks));
|
|
493
527
|
}
|
|
494
528
|
|
|
495
529
|
function _instrumentXhr():void {
|
|
496
|
-
if (_supportsAjaxMonitoring(_self) && !_xhrInitialized) {
|
|
530
|
+
if (_supportsAjaxMonitoring(_self) && !_disableAjaxTracking && !_xhrInitialized) {
|
|
497
531
|
// Instrument open
|
|
498
532
|
_hookProto(XMLHttpRequest, "open", {
|
|
533
|
+
ns: _evtNamespace,
|
|
499
534
|
req: (args:IInstrumentCallDetails, method:string, url:string, async?:boolean) => {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if (!
|
|
504
|
-
|
|
505
|
-
|
|
535
|
+
if (!_disableAjaxTracking) {
|
|
536
|
+
let xhr = args.inst as XMLHttpRequestInstrumented;
|
|
537
|
+
let ajaxData = xhr[strAjaxData];
|
|
538
|
+
if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
|
|
539
|
+
if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
|
|
540
|
+
// Only create a single ajaxData (even when multiple AI instances are running)
|
|
541
|
+
_openHandler(xhr, method, url, async);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// always attach to the on ready state change (required for handling multiple instances)
|
|
545
|
+
_attachToOnReadyStateChange(xhr);
|
|
506
546
|
}
|
|
507
|
-
|
|
508
|
-
// always attach to the on ready state change (required for handling multiple instances)
|
|
509
|
-
_attachToOnReadyStateChange(xhr);
|
|
510
547
|
}
|
|
511
548
|
},
|
|
512
|
-
hkErr: _createErrorCallbackFunc(_self,
|
|
549
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxOpen,
|
|
513
550
|
"Failed to monitor XMLHttpRequest.open, monitoring data for this ajax call may be incorrect.")
|
|
514
551
|
});
|
|
515
552
|
|
|
516
553
|
// Instrument send
|
|
517
554
|
_hookProto(XMLHttpRequest, "send", {
|
|
555
|
+
ns: _evtNamespace,
|
|
518
556
|
req: (args:IInstrumentCallDetails, context?: Document | BodyInit | null) => {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
557
|
+
if (!_disableAjaxTracking) {
|
|
558
|
+
let xhr = args.inst as XMLHttpRequestInstrumented;
|
|
559
|
+
let ajaxData = xhr[strAjaxData];
|
|
560
|
+
if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
|
|
561
|
+
_createMarkId("xhr", ajaxData);
|
|
562
|
+
ajaxData.requestSentTime = dateTimeUtilsNow();
|
|
563
|
+
_self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
|
|
564
|
+
ajaxData.xhrMonitoringState.sendDone = true;
|
|
565
|
+
}
|
|
526
566
|
}
|
|
527
567
|
},
|
|
528
|
-
hkErr: _createErrorCallbackFunc(_self,
|
|
568
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxSend,
|
|
529
569
|
"Failed to monitor XMLHttpRequest, monitoring data for this ajax call may be incorrect.")
|
|
530
570
|
});
|
|
531
571
|
|
|
532
572
|
// Instrument abort
|
|
533
573
|
_hookProto(XMLHttpRequest, "abort", {
|
|
574
|
+
ns: _evtNamespace,
|
|
534
575
|
req: (args:IInstrumentCallDetails) => {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
ajaxData.
|
|
539
|
-
|
|
576
|
+
if (!_disableAjaxTracking) {
|
|
577
|
+
let xhr = args.inst as XMLHttpRequestInstrumented;
|
|
578
|
+
let ajaxData = xhr[strAjaxData];
|
|
579
|
+
if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
|
|
580
|
+
ajaxData.aborted = 1;
|
|
581
|
+
ajaxData.xhrMonitoringState.abortDone = true;
|
|
582
|
+
}
|
|
540
583
|
}
|
|
541
584
|
},
|
|
542
|
-
hkErr: _createErrorCallbackFunc(_self,
|
|
585
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxAbort,
|
|
543
586
|
"Failed to monitor XMLHttpRequest.abort, monitoring data for this ajax call may be incorrect.")
|
|
544
587
|
});
|
|
545
588
|
|
|
546
589
|
// Instrument setRequestHeader
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
590
|
+
_hookProto(XMLHttpRequest, "setRequestHeader", {
|
|
591
|
+
ns: _evtNamespace,
|
|
592
|
+
req: (args: IInstrumentCallDetails, header: string, value: string) => {
|
|
593
|
+
if (!_disableAjaxTracking && _enableRequestHeaderTracking) {
|
|
550
594
|
let xhr = args.inst as XMLHttpRequestInstrumented;
|
|
551
595
|
if (_isMonitoredXhrInstance(xhr) && _canIncludeHeaders(header)) {
|
|
552
596
|
xhr[strAjaxData].requestHeaders[header] = value;
|
|
553
597
|
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxSetRequestHeader,
|
|
601
|
+
"Failed to monitor XMLHttpRequest.setRequestHeader, monitoring data for this ajax call may be incorrect.")
|
|
602
|
+
});
|
|
559
603
|
|
|
560
604
|
_xhrInitialized = true;
|
|
561
605
|
}
|
|
@@ -653,7 +697,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
653
697
|
}
|
|
654
698
|
|
|
655
699
|
function _attachToOnReadyStateChange(xhr: XMLHttpRequestInstrumented) {
|
|
656
|
-
xhr[strAjaxData].xhrMonitoringState.stateChangeAttached =
|
|
700
|
+
xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = eventOn(xhr, "readystatechange", () => {
|
|
657
701
|
try {
|
|
658
702
|
if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr)) {
|
|
659
703
|
_onAjaxComplete(xhr);
|
|
@@ -664,7 +708,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
664
708
|
// ignore messages with c00c023f, as this a known IE9 XHR abort issue
|
|
665
709
|
if (!exceptionText || _indexOf(exceptionText.toLowerCase(), "c00c023f") === -1) {
|
|
666
710
|
_throwInternalCritical(_self,
|
|
667
|
-
|
|
711
|
+
_eInternalMessageId.FailedMonitorAjaxRSC,
|
|
668
712
|
"Failed to monitor XMLHttpRequest 'readystatechange' event handler, monitoring data for this ajax call may be incorrect.",
|
|
669
713
|
{
|
|
670
714
|
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(xhr),
|
|
@@ -672,7 +716,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
672
716
|
});
|
|
673
717
|
}
|
|
674
718
|
}
|
|
675
|
-
});
|
|
719
|
+
}, _evtNamespace);
|
|
676
720
|
}
|
|
677
721
|
|
|
678
722
|
function _getResponseText(xhr: XMLHttpRequestInstrumented) {
|
|
@@ -702,7 +746,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
702
746
|
}
|
|
703
747
|
|
|
704
748
|
_throwInternalWarning(_self,
|
|
705
|
-
|
|
749
|
+
_eInternalMessageId.FailedMonitorAjaxDur,
|
|
706
750
|
"Failed to calculate the duration of the ajax call, monitoring data for this ajax call won't be sent.",
|
|
707
751
|
errorProps
|
|
708
752
|
);
|
|
@@ -731,7 +775,9 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
731
775
|
const parts = line.split(": ");
|
|
732
776
|
const header = parts.shift();
|
|
733
777
|
const value = parts.join(": ");
|
|
734
|
-
if(_canIncludeHeaders(header)) {
|
|
778
|
+
if(_canIncludeHeaders(header)) {
|
|
779
|
+
responseHeaderMap[header] = value;
|
|
780
|
+
}
|
|
735
781
|
});
|
|
736
782
|
|
|
737
783
|
ajaxResponse.headerMap = responseHeaderMap;
|
|
@@ -748,7 +794,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
748
794
|
}
|
|
749
795
|
} catch (e) {
|
|
750
796
|
_throwInternalWarning(_self,
|
|
751
|
-
|
|
797
|
+
_eInternalMessageId.FailedAddingCustomDefinedRequestContext,
|
|
752
798
|
"Failed to add custom defined request context as configured call back may missing a null check.")
|
|
753
799
|
}
|
|
754
800
|
|
|
@@ -759,9 +805,9 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
759
805
|
_self[strTrackDependencyDataInternal](dependency);
|
|
760
806
|
} else {
|
|
761
807
|
_reportXhrError(null, {
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
808
|
+
requestSentTime: ajaxData.requestSentTime,
|
|
809
|
+
responseFinishedTime: ajaxData.responseFinishedTime
|
|
810
|
+
});
|
|
765
811
|
}
|
|
766
812
|
} finally {
|
|
767
813
|
// cleanup telemetry data
|
|
@@ -788,7 +834,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
788
834
|
}
|
|
789
835
|
} catch (e) {
|
|
790
836
|
_throwInternalWarning(_self,
|
|
791
|
-
|
|
837
|
+
_eInternalMessageId.FailedMonitorAjaxGetCorrelationHeader,
|
|
792
838
|
"Failed to get Request-Context correlation header as it may be not included in the response or not accessible.",
|
|
793
839
|
{
|
|
794
840
|
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(xhr),
|
|
@@ -901,7 +947,9 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
901
947
|
if (_enableRequestHeaderTracking) {
|
|
902
948
|
let headers = new Headers((init ? init.headers : 0) || (input instanceof Request ? (input.headers || {}) : {}));
|
|
903
949
|
headers.forEach((value, key) => {
|
|
904
|
-
if (_canIncludeHeaders(key)) {
|
|
950
|
+
if (_canIncludeHeaders(key)) {
|
|
951
|
+
requestHeaders[key] = value;
|
|
952
|
+
}
|
|
905
953
|
});
|
|
906
954
|
}
|
|
907
955
|
|
|
@@ -924,7 +972,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
924
972
|
}
|
|
925
973
|
} catch (e) {
|
|
926
974
|
_throwInternalCritical(_self,
|
|
927
|
-
|
|
975
|
+
_eInternalMessageId.FailedMonitorAjaxOpen,
|
|
928
976
|
"Failed to grab failed fetch diagnostics message",
|
|
929
977
|
{ exception: dumpObj(e) }
|
|
930
978
|
);
|
|
@@ -937,7 +985,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
937
985
|
return;
|
|
938
986
|
}
|
|
939
987
|
|
|
940
|
-
function _reportFetchError(msgId:
|
|
988
|
+
function _reportFetchError(msgId: _eInternalMessageId, e: any, failedProps?:Object) {
|
|
941
989
|
let errorProps = failedProps||{};
|
|
942
990
|
errorProps["fetchDiagnosticsMessage"] = _getFailedFetchDiagnosticsMessage(input);
|
|
943
991
|
if (e) {
|
|
@@ -963,7 +1011,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
963
1011
|
}
|
|
964
1012
|
} catch (e) {
|
|
965
1013
|
_throwInternalWarning(_self,
|
|
966
|
-
|
|
1014
|
+
_eInternalMessageId.FailedAddingCustomDefinedRequestContext,
|
|
967
1015
|
"Failed to add custom defined request context as configured call back may missing a null check.")
|
|
968
1016
|
}
|
|
969
1017
|
|
|
@@ -973,14 +1021,14 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
973
1021
|
}
|
|
974
1022
|
_self[strTrackDependencyDataInternal](dependency);
|
|
975
1023
|
} else {
|
|
976
|
-
_reportFetchError(
|
|
1024
|
+
_reportFetchError(_eInternalMessageId.FailedMonitorAjaxDur, null,
|
|
977
1025
|
{
|
|
978
1026
|
requestSentTime: ajaxData.requestSentTime,
|
|
979
1027
|
responseFinishedTime: ajaxData.responseFinishedTime
|
|
980
1028
|
});
|
|
981
1029
|
}
|
|
982
1030
|
}, (e) => {
|
|
983
|
-
_reportFetchError(
|
|
1031
|
+
_reportFetchError(_eInternalMessageId.FailedMonitorAjaxGetCorrelationHeader, e, null);
|
|
984
1032
|
});
|
|
985
1033
|
}
|
|
986
1034
|
|
|
@@ -991,7 +1039,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
991
1039
|
return CorrelationIdHelper.getCorrelationContext(responseHeader);
|
|
992
1040
|
} catch (e) {
|
|
993
1041
|
_throwInternalWarning(_self,
|
|
994
|
-
|
|
1042
|
+
_eInternalMessageId.FailedMonitorAjaxGetCorrelationHeader,
|
|
995
1043
|
"Failed to get Request-Context correlation header as it may be not included in the response or not accessible.",
|
|
996
1044
|
{
|
|
997
1045
|
fetchDiagnosticsMessage: _getFailedFetchDiagnosticsMessage(response),
|
|
@@ -1007,10 +1055,6 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
1007
1055
|
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1008
1056
|
}
|
|
1009
1057
|
|
|
1010
|
-
public teardown():void {
|
|
1011
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
1058
|
public processTelemetry(item: ITelemetryItem, itemCtx?: IProcessTelemetryContext) {
|
|
1015
1059
|
this.processNext(item, itemCtx);
|
|
1016
1060
|
}
|