@microsoft/applicationinsights-dependencies-js 2.8.16-nightly.2308-04 → 2.8.16-nightly.2308-17
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 +126 -56
- 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 +92 -6
- package/dist/applicationinsights-dependencies-js.api.md +12 -1
- package/dist/applicationinsights-dependencies-js.d.ts +21 -5
- package/dist/applicationinsights-dependencies-js.js +126 -56
- 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 +21 -5
- package/dist-esm/DependencyInitializer.js +1 -1
- package/dist-esm/DependencyListener.js +1 -1
- package/dist-esm/InternalConstants.js +1 -1
- package/dist-esm/__DynamicConstants.js +1 -1
- package/dist-esm/ajax.js +136 -54
- 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 +3 -3
- package/src/ajax.ts +160 -60
- package/src/applicationinsights-dependencies-js.ts +1 -1
- package/types/ajax.d.ts +19 -4
- package/types/applicationinsights-dependencies-js.d.ts +1 -1
- package/types/tsdoc-metadata.json +1 -1
package/src/ajax.ts
CHANGED
|
@@ -25,7 +25,7 @@ declare let self: any;
|
|
|
25
25
|
|
|
26
26
|
const AJAX_MONITOR_PREFIX = "ai.ajxmn.";
|
|
27
27
|
const strDiagLog = "diagLog";
|
|
28
|
-
const
|
|
28
|
+
const AJAX_DATA_CONTAINER = "_ajaxData";
|
|
29
29
|
const STR_FETCH = "fetch";
|
|
30
30
|
|
|
31
31
|
const ERROR_HEADER = "Failed to monitor XMLHttpRequest";
|
|
@@ -76,7 +76,7 @@ function isWebWorker() {
|
|
|
76
76
|
* @returns True if Ajax monitoring is supported on this page, otherwise false
|
|
77
77
|
* @ignore
|
|
78
78
|
*/
|
|
79
|
-
function _supportsAjaxMonitoring(ajaxMonitorInstance:AjaxMonitor): boolean {
|
|
79
|
+
function _supportsAjaxMonitoring(ajaxMonitorInstance: AjaxMonitor, ajaxDataId: string): boolean {
|
|
80
80
|
let result = false;
|
|
81
81
|
|
|
82
82
|
if (isXhrSupported()) {
|
|
@@ -96,7 +96,14 @@ function _supportsAjaxMonitoring(ajaxMonitorInstance:AjaxMonitor): boolean {
|
|
|
96
96
|
// Disable if the XmlHttpRequest can't be extended or hooked
|
|
97
97
|
try {
|
|
98
98
|
let xhr = new XMLHttpRequest();
|
|
99
|
-
|
|
99
|
+
let xhrData: XMLHttpRequestData = {
|
|
100
|
+
xh: [],
|
|
101
|
+
i: {
|
|
102
|
+
[ajaxDataId]: {} as ajaxRecord
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
xhr[AJAX_DATA_CONTAINER] = xhrData;
|
|
100
107
|
|
|
101
108
|
// Check that we can update the prototype
|
|
102
109
|
let theOpen = XMLHttpRequest[strPrototype].open;
|
|
@@ -116,12 +123,62 @@ function _supportsAjaxMonitoring(ajaxMonitorInstance:AjaxMonitor): boolean {
|
|
|
116
123
|
return result;
|
|
117
124
|
}
|
|
118
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Internal helper to fetch the SDK instance tracking data for this XHR request
|
|
128
|
+
* @param xhr
|
|
129
|
+
* @param ajaxDataId
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
const _getAjaxData = (xhr: XMLHttpRequestInstrumented, ajaxDataId: string): ajaxRecord => {
|
|
133
|
+
if (xhr && ajaxDataId && xhr[AJAX_DATA_CONTAINER]) {
|
|
134
|
+
return (xhr[AJAX_DATA_CONTAINER].i || { })[ajaxDataId];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @ignore
|
|
142
|
+
* Internal helper to track the singleton shared tracking headers, so we can attempt to not create headers
|
|
143
|
+
* that might cause an issue if multiple values are populated.
|
|
144
|
+
* @param xhr - The instrumented XHR instance
|
|
145
|
+
*/
|
|
146
|
+
const _addSharedXhrHeaders = (xhr: XMLHttpRequestInstrumented, name: string, value: string) => {
|
|
147
|
+
if (xhr) {
|
|
148
|
+
let headers = (xhr[AJAX_DATA_CONTAINER] || {}).xh;
|
|
149
|
+
if (headers) {
|
|
150
|
+
headers.push({
|
|
151
|
+
n: name,
|
|
152
|
+
v: value
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const _isHeaderSet = (xhr: XMLHttpRequestInstrumented, name: string) => {
|
|
159
|
+
let isPresent = false;
|
|
160
|
+
if (xhr) {
|
|
161
|
+
let headers = (xhr[AJAX_DATA_CONTAINER] || {}).xh;
|
|
162
|
+
if (headers) {
|
|
163
|
+
arrForEach(headers, (header) => {
|
|
164
|
+
if (header.n === name) {
|
|
165
|
+
isPresent = true;
|
|
166
|
+
return -1;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return isPresent;
|
|
173
|
+
}
|
|
174
|
+
|
|
119
175
|
/** @Ignore */
|
|
120
|
-
function _getFailedAjaxDiagnosticsMessage(xhr: XMLHttpRequestInstrumented): string {
|
|
176
|
+
function _getFailedAjaxDiagnosticsMessage(xhr: XMLHttpRequestInstrumented, ajaxDataId: string): string {
|
|
121
177
|
let result = "";
|
|
122
178
|
try {
|
|
123
|
-
|
|
124
|
-
|
|
179
|
+
let ajaxData = _getAjaxData(xhr, ajaxDataId);
|
|
180
|
+
if (ajaxData && ajaxData.requestUrl) {
|
|
181
|
+
result += "(url: '" + ajaxData.requestUrl + "')";
|
|
125
182
|
}
|
|
126
183
|
} catch (e) {
|
|
127
184
|
// eslint-disable-next-line no-empty
|
|
@@ -141,15 +198,15 @@ function _throwInternalWarning(ajaxMonitorInstance:AjaxMonitor, msgId: _eInterna
|
|
|
141
198
|
}
|
|
142
199
|
|
|
143
200
|
/** @Ignore */
|
|
144
|
-
function _createErrorCallbackFunc(ajaxMonitorInstance:AjaxMonitor, internalMessage: _eInternalMessageId, message:string) {
|
|
201
|
+
function _createErrorCallbackFunc(ajaxMonitorInstance: AjaxMonitor, internalMessage: _eInternalMessageId, message:string) {
|
|
145
202
|
// tslint:disable-next-line
|
|
146
|
-
return function (
|
|
203
|
+
return function (callDetails: IInstrumentCallDetails) {
|
|
147
204
|
_throwInternalCritical(ajaxMonitorInstance,
|
|
148
205
|
internalMessage,
|
|
149
206
|
message,
|
|
150
207
|
{
|
|
151
|
-
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(
|
|
152
|
-
exception: dumpObj(
|
|
208
|
+
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(callDetails.inst, (ajaxMonitorInstance as any)._ajaxDataId),
|
|
209
|
+
exception: dumpObj(callDetails.err)
|
|
153
210
|
});
|
|
154
211
|
};
|
|
155
212
|
}
|
|
@@ -226,8 +283,20 @@ function _processDependencyListeners(listeners: _IInternalDependencyHandler<Depe
|
|
|
226
283
|
}
|
|
227
284
|
}
|
|
228
285
|
|
|
286
|
+
export interface XMLHttpRequestData {
|
|
287
|
+
/**
|
|
288
|
+
* The "Shared" XHR headers, avoids causing multiple instances
|
|
289
|
+
*/
|
|
290
|
+
xh?: Array<{ n: string, v: string }>;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* The individual tracking data for each AI instance
|
|
294
|
+
*/
|
|
295
|
+
i: { [key: string]: ajaxRecord };
|
|
296
|
+
}
|
|
297
|
+
|
|
229
298
|
export interface XMLHttpRequestInstrumented extends XMLHttpRequest {
|
|
230
|
-
|
|
299
|
+
_ajaxData: XMLHttpRequestData;
|
|
231
300
|
}
|
|
232
301
|
|
|
233
302
|
const BLOB_CORE = "*.blob.core.";
|
|
@@ -247,7 +316,7 @@ const _internalExcludeEndpoints = [
|
|
|
247
316
|
export interface IDependenciesPlugin extends IDependencyListenerContainer {
|
|
248
317
|
/**
|
|
249
318
|
* Logs dependency call
|
|
250
|
-
* @param dependencyData dependency data object
|
|
319
|
+
* @param dependencyData - dependency data object
|
|
251
320
|
*/
|
|
252
321
|
trackDependencyData(dependency: IDependencyTelemetry): void;
|
|
253
322
|
}
|
|
@@ -328,6 +397,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
328
397
|
let _excludeRequestFromAutoTrackingPatterns: (string | RegExp)[];
|
|
329
398
|
let _addRequestContext: (requestContext?: IRequestContext) => ICustomProperties;
|
|
330
399
|
let _evtNamespace: string | string[];
|
|
400
|
+
let _ajaxDataId: string;
|
|
331
401
|
let _dependencyHandlerId: number;
|
|
332
402
|
let _dependencyListeners: _IInternalDependencyHandler<DependencyListenerFunction>[];
|
|
333
403
|
let _dependencyInitializers: _IInternalDependencyHandler<DependencyInitializerFunction>[];
|
|
@@ -340,7 +410,6 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
340
410
|
_self.initialize = (config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) => {
|
|
341
411
|
if (!_self.isInitialized()) {
|
|
342
412
|
_base.initialize(config, core, extensions, pluginChain);
|
|
343
|
-
|
|
344
413
|
_evtNamespace = mergeEvtNamespace(createUniqueNamespace("ajax"), core && core.evtNamespace && core.evtNamespace());
|
|
345
414
|
|
|
346
415
|
_populateDefaults(config);
|
|
@@ -409,17 +478,27 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
409
478
|
} else if (xhr) { // XHR
|
|
410
479
|
if (CorrelationIdHelper.canIncludeCorrelationHeader(_config, ajaxData.getAbsoluteUrl(), currentWindowHost)) {
|
|
411
480
|
if (_isUsingAIHeaders) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
481
|
+
if (!_isHeaderSet(xhr, RequestHeaders[eRequestHeaders.requestIdHeader])) {
|
|
482
|
+
const id = "|" + ajaxData.traceID + "." + ajaxData.spanID;
|
|
483
|
+
xhr.setRequestHeader(RequestHeaders[eRequestHeaders.requestIdHeader], id);
|
|
484
|
+
if (_enableRequestHeaderTracking) {
|
|
485
|
+
ajaxData.requestHeaders[RequestHeaders[eRequestHeaders.requestIdHeader]] = id;
|
|
486
|
+
}
|
|
487
|
+
} else {
|
|
488
|
+
_throwInternalWarning(_self, _eInternalMessageId.FailedMonitorAjaxSetRequestHeader,
|
|
489
|
+
"Unable to set [" + RequestHeaders[eRequestHeaders.requestIdHeader] + "] as it has already been set by another instance");
|
|
416
490
|
}
|
|
417
491
|
}
|
|
418
492
|
const appId = _config.appId || (_context && _context.appId());
|
|
419
493
|
if (appId) {
|
|
420
|
-
xhr
|
|
421
|
-
|
|
422
|
-
|
|
494
|
+
if (!_isHeaderSet(xhr, RequestHeaders[eRequestHeaders.requestContextHeader])) {
|
|
495
|
+
xhr.setRequestHeader(RequestHeaders[eRequestHeaders.requestContextHeader], RequestHeaders[eRequestHeaders.requestContextAppIdFormat] + appId);
|
|
496
|
+
if (_enableRequestHeaderTracking) {
|
|
497
|
+
ajaxData.requestHeaders[RequestHeaders[eRequestHeaders.requestContextHeader]] = RequestHeaders[eRequestHeaders.requestContextAppIdFormat] + appId;
|
|
498
|
+
}
|
|
499
|
+
} else {
|
|
500
|
+
_throwInternalWarning(_self, _eInternalMessageId.FailedMonitorAjaxSetRequestHeader,
|
|
501
|
+
"Unable to set [" + RequestHeaders[eRequestHeaders.requestContextHeader] + "] as it has already been set by another instance");
|
|
423
502
|
}
|
|
424
503
|
}
|
|
425
504
|
if (_isUsingW3CHeaders) {
|
|
@@ -428,10 +507,15 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
428
507
|
traceFlags = 0x01;
|
|
429
508
|
}
|
|
430
509
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
510
|
+
if (!_isHeaderSet(xhr, RequestHeaders[eRequestHeaders.traceParentHeader])) {
|
|
511
|
+
const traceParent = formatTraceParent(createTraceParent(ajaxData.traceID, ajaxData.spanID, traceFlags));
|
|
512
|
+
xhr.setRequestHeader(RequestHeaders[eRequestHeaders.traceParentHeader], traceParent);
|
|
513
|
+
if (_enableRequestHeaderTracking) {
|
|
514
|
+
ajaxData.requestHeaders[RequestHeaders[eRequestHeaders.traceParentHeader]] = traceParent;
|
|
515
|
+
}
|
|
516
|
+
} else {
|
|
517
|
+
_throwInternalWarning(_self, _eInternalMessageId.FailedMonitorAjaxSetRequestHeader,
|
|
518
|
+
"Unable to set [" + RequestHeaders[eRequestHeaders.traceParentHeader] + "] as it has already been set by another instance");
|
|
435
519
|
}
|
|
436
520
|
}
|
|
437
521
|
}
|
|
@@ -509,6 +593,8 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
509
593
|
_dependencyHandlerId = 0;
|
|
510
594
|
_dependencyListeners = [];
|
|
511
595
|
_dependencyInitializers = [];
|
|
596
|
+
_ajaxDataId = createUniqueNamespace("ajaxData");
|
|
597
|
+
(_self as any)._ajaxDataId = _ajaxDataId;
|
|
512
598
|
}
|
|
513
599
|
|
|
514
600
|
function _populateDefaults(config: IConfiguration) {
|
|
@@ -665,22 +751,22 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
665
751
|
}
|
|
666
752
|
|
|
667
753
|
function _instrumentXhr():void {
|
|
668
|
-
if (_supportsAjaxMonitoring(_self) && !_disableAjaxTracking && !_xhrInitialized) {
|
|
754
|
+
if (_supportsAjaxMonitoring(_self, _ajaxDataId) && !_disableAjaxTracking && !_xhrInitialized) {
|
|
669
755
|
// Instrument open
|
|
670
756
|
_hookProto(XMLHttpRequest, "open", {
|
|
671
757
|
ns: _evtNamespace,
|
|
672
|
-
req: (
|
|
758
|
+
req: (callDetails: IInstrumentCallDetails, method:string, url:string, async?:boolean) => {
|
|
673
759
|
if (!_disableAjaxTracking) {
|
|
674
|
-
let xhr =
|
|
675
|
-
let ajaxData = xhr
|
|
676
|
-
if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
|
|
760
|
+
let xhr = callDetails.inst as XMLHttpRequestInstrumented;
|
|
761
|
+
let ajaxData = _getAjaxData(xhr, _ajaxDataId);
|
|
762
|
+
if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, ajaxData, true)) {
|
|
677
763
|
if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
|
|
678
764
|
// Only create a single ajaxData (even when multiple AI instances are running)
|
|
679
|
-
_openHandler(xhr, method, url, async);
|
|
765
|
+
ajaxData = _openHandler(xhr, method, url, async);
|
|
680
766
|
}
|
|
681
767
|
|
|
682
768
|
// always attach to the on ready state change (required for handling multiple instances)
|
|
683
|
-
_attachToOnReadyStateChange(xhr);
|
|
769
|
+
_attachToOnReadyStateChange(xhr, ajaxData);
|
|
684
770
|
}
|
|
685
771
|
}
|
|
686
772
|
},
|
|
@@ -691,11 +777,11 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
691
777
|
// Instrument send
|
|
692
778
|
_hookProto(XMLHttpRequest, "send", {
|
|
693
779
|
ns: _evtNamespace,
|
|
694
|
-
req: (
|
|
780
|
+
req: (callDetails: IInstrumentCallDetails, context?: Document | BodyInit | null) => {
|
|
695
781
|
if (!_disableAjaxTracking) {
|
|
696
|
-
let xhr =
|
|
697
|
-
let ajaxData = xhr
|
|
698
|
-
if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
|
|
782
|
+
let xhr = callDetails.inst as XMLHttpRequestInstrumented;
|
|
783
|
+
let ajaxData = _getAjaxData(xhr, _ajaxDataId);
|
|
784
|
+
if (_isMonitoredXhrInstance(xhr, ajaxData) && !ajaxData.xhrMonitoringState.sendDone) {
|
|
699
785
|
_createMarkId("xhr", ajaxData);
|
|
700
786
|
ajaxData.requestSentTime = dateTimeUtilsNow();
|
|
701
787
|
_self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
|
|
@@ -710,11 +796,11 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
710
796
|
// Instrument abort
|
|
711
797
|
_hookProto(XMLHttpRequest, "abort", {
|
|
712
798
|
ns: _evtNamespace,
|
|
713
|
-
req: (
|
|
799
|
+
req: (callDetails: IInstrumentCallDetails) => {
|
|
714
800
|
if (!_disableAjaxTracking) {
|
|
715
|
-
let xhr =
|
|
716
|
-
let ajaxData = xhr
|
|
717
|
-
if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
|
|
801
|
+
let xhr = callDetails.inst as XMLHttpRequestInstrumented;
|
|
802
|
+
let ajaxData = _getAjaxData(xhr, _ajaxDataId);
|
|
803
|
+
if (_isMonitoredXhrInstance(xhr, ajaxData) && !ajaxData.xhrMonitoringState.abortDone) {
|
|
718
804
|
ajaxData.aborted = 1;
|
|
719
805
|
ajaxData.xhrMonitoringState.abortDone = true;
|
|
720
806
|
}
|
|
@@ -727,11 +813,17 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
727
813
|
// Instrument setRequestHeader
|
|
728
814
|
_hookProto(XMLHttpRequest, "setRequestHeader", {
|
|
729
815
|
ns: _evtNamespace,
|
|
730
|
-
req: (
|
|
731
|
-
if (!_disableAjaxTracking
|
|
732
|
-
let xhr =
|
|
733
|
-
|
|
734
|
-
|
|
816
|
+
req: (callDetails: IInstrumentCallDetails, header: string, value: string) => {
|
|
817
|
+
if (!_disableAjaxTracking) {
|
|
818
|
+
let xhr = callDetails.inst as XMLHttpRequestInstrumented;
|
|
819
|
+
let ajaxData = _getAjaxData(xhr, _ajaxDataId);
|
|
820
|
+
if (ajaxData && _isMonitoredXhrInstance(xhr, ajaxData)) {
|
|
821
|
+
_addSharedXhrHeaders(xhr, header, value);
|
|
822
|
+
if (_enableRequestHeaderTracking && _canIncludeHeaders(header)) {
|
|
823
|
+
if (ajaxData) {
|
|
824
|
+
ajaxData.requestHeaders[header] = value;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
735
827
|
}
|
|
736
828
|
}
|
|
737
829
|
},
|
|
@@ -804,14 +896,14 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
804
896
|
return isDisabled;
|
|
805
897
|
}
|
|
806
898
|
|
|
807
|
-
/// <summary>Verifies that
|
|
899
|
+
/// <summary>Verifies that particular instance of XMLHttpRequest needs to be monitored</summary>
|
|
808
900
|
/// <param name="excludeAjaxDataValidation">Optional parameter. True if ajaxData must be excluded from verification</param>
|
|
809
901
|
/// <returns type="bool">True if instance needs to be monitored, otherwise false</returns>
|
|
810
|
-
function _isMonitoredXhrInstance(xhr: XMLHttpRequestInstrumented, excludeAjaxDataValidation?: boolean): boolean {
|
|
902
|
+
function _isMonitoredXhrInstance(xhr: XMLHttpRequestInstrumented, ajaxData: ajaxRecord, excludeAjaxDataValidation?: boolean): boolean {
|
|
811
903
|
let ajaxValidation = true;
|
|
812
904
|
let initialized = _xhrInitialized;
|
|
813
905
|
if (!isNullOrUndefined(xhr)) {
|
|
814
|
-
ajaxValidation = excludeAjaxDataValidation === true || !isNullOrUndefined(
|
|
906
|
+
ajaxValidation = excludeAjaxDataValidation === true || !isNullOrUndefined(ajaxData);
|
|
815
907
|
}
|
|
816
908
|
|
|
817
909
|
// checking to see that all interested functions on xhr were instrumented
|
|
@@ -834,13 +926,16 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
834
926
|
return distributedTraceCtx;
|
|
835
927
|
}
|
|
836
928
|
|
|
837
|
-
function _openHandler(xhr: XMLHttpRequestInstrumented, method: string, url: string, async: boolean) {
|
|
929
|
+
function _openHandler(xhr: XMLHttpRequestInstrumented, method: string, url: string, async: boolean): ajaxRecord {
|
|
838
930
|
let distributedTraceCtx: IDistributedTraceContext = _getDistributedTraceCtx();
|
|
839
931
|
|
|
840
932
|
const traceID = (distributedTraceCtx && distributedTraceCtx.getTraceId()) || generateW3CId();
|
|
841
933
|
const spanID = generateW3CId().substr(0, 16);
|
|
842
934
|
|
|
843
|
-
|
|
935
|
+
let xhrRequestData = xhr[AJAX_DATA_CONTAINER] = (xhr[AJAX_DATA_CONTAINER] || { xh:[], i: {}});
|
|
936
|
+
let ajaxDataCntr = xhrRequestData.i = (xhrRequestData.i || { });
|
|
937
|
+
const ajaxData = ajaxDataCntr[_ajaxDataId] = (ajaxDataCntr[_ajaxDataId] || new ajaxRecord(traceID, spanID, _self[strDiagLog](), _self.core?.getTraceCtx()));
|
|
938
|
+
|
|
844
939
|
ajaxData.traceFlags = distributedTraceCtx && distributedTraceCtx.getTraceFlags();
|
|
845
940
|
ajaxData.method = method;
|
|
846
941
|
ajaxData.requestUrl = url;
|
|
@@ -848,13 +943,14 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
848
943
|
ajaxData.requestHeaders = {};
|
|
849
944
|
ajaxData.async = async;
|
|
850
945
|
ajaxData.errorStatusText = _enableAjaxErrorStatusText;
|
|
851
|
-
|
|
946
|
+
|
|
947
|
+
return ajaxData;
|
|
852
948
|
}
|
|
853
949
|
|
|
854
|
-
function _attachToOnReadyStateChange(xhr: XMLHttpRequestInstrumented) {
|
|
855
|
-
|
|
950
|
+
function _attachToOnReadyStateChange(xhr: XMLHttpRequestInstrumented, ajaxData: ajaxRecord) {
|
|
951
|
+
ajaxData.xhrMonitoringState.stateChangeAttached = eventOn(xhr, "readystatechange", () => {
|
|
856
952
|
try {
|
|
857
|
-
if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr)) {
|
|
953
|
+
if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr, ajaxData)) {
|
|
858
954
|
_onAjaxComplete(xhr);
|
|
859
955
|
}
|
|
860
956
|
} catch (e) {
|
|
@@ -866,7 +962,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
866
962
|
_eInternalMessageId.FailedMonitorAjaxRSC,
|
|
867
963
|
ERROR_HEADER + " 'readystatechange' event handler" + ERROR_POSTFIX,
|
|
868
964
|
{
|
|
869
|
-
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(xhr),
|
|
965
|
+
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(xhr, _ajaxDataId),
|
|
870
966
|
exception: exceptionText
|
|
871
967
|
});
|
|
872
968
|
}
|
|
@@ -889,13 +985,13 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
889
985
|
}
|
|
890
986
|
|
|
891
987
|
function _onAjaxComplete(xhr: XMLHttpRequestInstrumented) {
|
|
892
|
-
let ajaxData = xhr
|
|
988
|
+
let ajaxData = _getAjaxData(xhr, _ajaxDataId);
|
|
893
989
|
ajaxData.responseFinishedTime = dateTimeUtilsNow();
|
|
894
990
|
ajaxData.status = xhr.status;
|
|
895
991
|
|
|
896
992
|
function _reportXhrError(e: any, failedProps?:Object) {
|
|
897
993
|
let errorProps = failedProps||{};
|
|
898
|
-
errorProps["ajaxDiagnosticsMessage"] = _getFailedAjaxDiagnosticsMessage(xhr);
|
|
994
|
+
errorProps["ajaxDiagnosticsMessage"] = _getFailedAjaxDiagnosticsMessage(xhr, _ajaxDataId);
|
|
899
995
|
if (e) {
|
|
900
996
|
errorProps["exception"] = dumpObj(e);
|
|
901
997
|
}
|
|
@@ -969,7 +1065,11 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
969
1065
|
} finally {
|
|
970
1066
|
// cleanup telemetry data
|
|
971
1067
|
try {
|
|
972
|
-
xhr[
|
|
1068
|
+
let xhrRequestData = (xhr[AJAX_DATA_CONTAINER] || { i: {}});
|
|
1069
|
+
let ajaxDataCntr = (xhrRequestData.i || { });
|
|
1070
|
+
if (ajaxDataCntr[_ajaxDataId]) {
|
|
1071
|
+
ajaxDataCntr[_ajaxDataId] = null;
|
|
1072
|
+
}
|
|
973
1073
|
} catch (e) {
|
|
974
1074
|
// May throw in environments that prevent extension or freeze xhr
|
|
975
1075
|
}
|
|
@@ -994,7 +1094,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
994
1094
|
_eInternalMessageId.FailedMonitorAjaxGetCorrelationHeader,
|
|
995
1095
|
CORRELATION_HEADER_ERROR,
|
|
996
1096
|
{
|
|
997
|
-
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(xhr),
|
|
1097
|
+
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(xhr, _ajaxDataId),
|
|
998
1098
|
exception: dumpObj(e)
|
|
999
1099
|
});
|
|
1000
1100
|
}
|
|
@@ -1251,7 +1351,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
1251
1351
|
|
|
1252
1352
|
/**
|
|
1253
1353
|
* Logs dependency call
|
|
1254
|
-
* @param dependencyData dependency data object
|
|
1354
|
+
* @param dependencyData - dependency data object
|
|
1255
1355
|
*/
|
|
1256
1356
|
public trackDependencyData(dependency: IDependencyTelemetry, properties?: { [key: string]: any }) {
|
|
1257
1357
|
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
@@ -1288,7 +1388,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
1288
1388
|
* Protected function to allow sub classes the chance to add additional properties to the dependency event
|
|
1289
1389
|
* before it's sent. This function calls track, so sub-classes must call this function after they have
|
|
1290
1390
|
* populated their properties.
|
|
1291
|
-
* @param dependencyData dependency data object
|
|
1391
|
+
* @param dependencyData - dependency data object
|
|
1292
1392
|
*/
|
|
1293
1393
|
protected trackDependencyDataInternal(dependency: IDependencyTelemetry, properties?: { [key: string]: any }, systemProperties?: { [key: string]: any }) {
|
|
1294
1394
|
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
4
|
export {
|
|
5
|
-
AjaxMonitor as AjaxPlugin, IDependenciesPlugin, XMLHttpRequestInstrumented, IInstrumentationRequirements, DfltAjaxCorrelationHeaderExDomains
|
|
5
|
+
AjaxMonitor as AjaxPlugin, IDependenciesPlugin, XMLHttpRequestData, XMLHttpRequestInstrumented, IInstrumentationRequirements, DfltAjaxCorrelationHeaderExDomains
|
|
6
6
|
} from "./ajax";
|
|
7
7
|
export { ajaxRecord } from "./ajaxRecord";
|
|
8
8
|
export { IDependencyHandler, IDependencyListenerHandler, IDependencyListenerDetails, DependencyListenerFunction } from "./DependencyListener";
|
package/types/ajax.d.ts
CHANGED
|
@@ -3,14 +3,29 @@ import { BaseTelemetryPlugin, IAppInsightsCore, IConfiguration, IPlugin, IProces
|
|
|
3
3
|
import { DependencyInitializerFunction, IDependencyInitializerHandler } from "./DependencyInitializer";
|
|
4
4
|
import { DependencyListenerFunction, IDependencyListenerContainer, IDependencyListenerHandler } from "./DependencyListener";
|
|
5
5
|
import { ajaxRecord } from "./ajaxRecord";
|
|
6
|
+
export interface XMLHttpRequestData {
|
|
7
|
+
/**
|
|
8
|
+
* The "Shared" XHR headers, avoids causing multiple instances
|
|
9
|
+
*/
|
|
10
|
+
xh?: Array<{
|
|
11
|
+
n: string;
|
|
12
|
+
v: string;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* The individual tracking data for each AI instance
|
|
16
|
+
*/
|
|
17
|
+
i: {
|
|
18
|
+
[key: string]: ajaxRecord;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
6
21
|
export interface XMLHttpRequestInstrumented extends XMLHttpRequest {
|
|
7
|
-
|
|
22
|
+
_ajaxData: XMLHttpRequestData;
|
|
8
23
|
}
|
|
9
24
|
export declare const DfltAjaxCorrelationHeaderExDomains: string[];
|
|
10
25
|
export interface IDependenciesPlugin extends IDependencyListenerContainer {
|
|
11
26
|
/**
|
|
12
27
|
* Logs dependency call
|
|
13
|
-
* @param dependencyData dependency data object
|
|
28
|
+
* @param dependencyData - dependency data object
|
|
14
29
|
*/
|
|
15
30
|
trackDependencyData(dependency: IDependencyTelemetry): void;
|
|
16
31
|
}
|
|
@@ -30,7 +45,7 @@ export declare class AjaxMonitor extends BaseTelemetryPlugin implements IDepende
|
|
|
30
45
|
processTelemetry(item: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
|
|
31
46
|
/**
|
|
32
47
|
* Logs dependency call
|
|
33
|
-
* @param dependencyData dependency data object
|
|
48
|
+
* @param dependencyData - dependency data object
|
|
34
49
|
*/
|
|
35
50
|
trackDependencyData(dependency: IDependencyTelemetry, properties?: {
|
|
36
51
|
[key: string]: any;
|
|
@@ -56,7 +71,7 @@ export declare class AjaxMonitor extends BaseTelemetryPlugin implements IDepende
|
|
|
56
71
|
* Protected function to allow sub classes the chance to add additional properties to the dependency event
|
|
57
72
|
* before it's sent. This function calls track, so sub-classes must call this function after they have
|
|
58
73
|
* populated their properties.
|
|
59
|
-
* @param dependencyData dependency data object
|
|
74
|
+
* @param dependencyData - dependency data object
|
|
60
75
|
*/
|
|
61
76
|
protected trackDependencyDataInternal(dependency: IDependencyTelemetry, properties?: {
|
|
62
77
|
[key: string]: any;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AjaxMonitor as AjaxPlugin, IDependenciesPlugin, XMLHttpRequestInstrumented, IInstrumentationRequirements, DfltAjaxCorrelationHeaderExDomains } from "./ajax";
|
|
1
|
+
export { AjaxMonitor as AjaxPlugin, IDependenciesPlugin, XMLHttpRequestData, XMLHttpRequestInstrumented, IInstrumentationRequirements, DfltAjaxCorrelationHeaderExDomains } from "./ajax";
|
|
2
2
|
export { ajaxRecord } from "./ajaxRecord";
|
|
3
3
|
export { IDependencyHandler, IDependencyListenerHandler, IDependencyListenerDetails, DependencyListenerFunction } from "./DependencyListener";
|
|
4
4
|
export { IDependencyInitializerHandler, IDependencyInitializerDetails, DependencyInitializerFunction } from "./DependencyInitializer";
|