@microsoft/applicationinsights-dependencies-js 3.0.0-beta.2212-14 → 3.0.0-beta.2301-01
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 +144 -131
- 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.d.ts +1 -1
- package/dist/applicationinsights-dependencies-js.js +144 -131
- 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 -1
- 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 +7 -6
- package/dist-esm/__DynamicConstants.js.map +1 -1
- package/dist-esm/ajax.js +156 -144
- 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/__DynamicConstants.ts +6 -5
- package/src/ajax.ts +162 -148
- package/types/__DynamicConstants.d.ts +5 -4
package/src/ajax.ts
CHANGED
|
@@ -271,7 +271,6 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
271
271
|
public static identifier: string = "AjaxDependencyPlugin";
|
|
272
272
|
|
|
273
273
|
public identifier: string = AjaxMonitor.identifier;
|
|
274
|
-
|
|
275
274
|
priority: number = 120;
|
|
276
275
|
|
|
277
276
|
constructor() {
|
|
@@ -304,6 +303,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
304
303
|
let _ajaxPerfLookupDelay: number;
|
|
305
304
|
let _distributedTracingMode: eDistributedTracingModes;
|
|
306
305
|
let _appId: string;
|
|
306
|
+
let _polyfillInitialized: boolean;
|
|
307
307
|
|
|
308
308
|
dynamicProto(AjaxMonitor, this, (_self, _base) => {
|
|
309
309
|
let _addHook = _base._addHook;
|
|
@@ -460,6 +460,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
460
460
|
let location = getLocation();
|
|
461
461
|
_fetchInitialized = false; // fetch monitoring initialized
|
|
462
462
|
_xhrInitialized = false; // XHR monitoring initialized
|
|
463
|
+
_polyfillInitialized = false; // polyfill monitoring initialized
|
|
463
464
|
_currentWindowHost = location && location.host && location.host.toLowerCase();
|
|
464
465
|
_extensionConfig = null;
|
|
465
466
|
_enableRequestHeaderTracking = false;
|
|
@@ -500,7 +501,6 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
500
501
|
_enableAjaxErrorStatusText = _extensionConfig.enableAjaxErrorStatusText;
|
|
501
502
|
_enableAjaxPerfTracking = _extensionConfig.enableAjaxPerfTracking;
|
|
502
503
|
_maxAjaxCallsPerView = _extensionConfig.maxAjaxCallsPerView;
|
|
503
|
-
_enableResponseHeaderTracking = _extensionConfig.enableResponseHeaderTracking;
|
|
504
504
|
_excludeRequestFromAutoTrackingPatterns = [].concat(_extensionConfig.excludeRequestFromAutoTrackingPatterns || [], _extensionConfig.addIntEndpoints !== false ? _internalExcludeEndpoints : []);
|
|
505
505
|
_addRequestContext = _extensionConfig.addRequestContext;
|
|
506
506
|
|
|
@@ -517,7 +517,6 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
517
517
|
}
|
|
518
518
|
|
|
519
519
|
_disableAjaxTracking = !!_extensionConfig.disableAjaxTracking;
|
|
520
|
-
_disableFetchTracking = !!_extensionConfig.disableFetchTracking;
|
|
521
520
|
_maxAjaxPerfLookupAttempts = _extensionConfig.maxAjaxPerfLookupAttempts;
|
|
522
521
|
_ajaxPerfLookupDelay = _extensionConfig.ajaxPerfLookupDelay;
|
|
523
522
|
_ignoreHeaders = _extensionConfig.ignoreHeaders;
|
|
@@ -555,83 +554,89 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
555
554
|
|
|
556
555
|
let global = getGlobal();
|
|
557
556
|
let isPolyfill = (fetch as any).polyfill;
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
callDetails.
|
|
557
|
+
_self._addHook(onConfigChange(_extensionConfig, () => {
|
|
558
|
+
_disableFetchTracking = !!_extensionConfig.disableFetchTracking;
|
|
559
|
+
_enableResponseHeaderTracking = _extensionConfig.enableResponseHeaderTracking;
|
|
560
|
+
|
|
561
|
+
if (!_disableFetchTracking && !_fetchInitialized) {
|
|
562
|
+
_addHook(InstrumentFunc(global, strFetch, {
|
|
563
|
+
ns: _evtNamespace,
|
|
564
|
+
// Add request hook
|
|
565
|
+
req: (callDetails: IInstrumentCallDetails, input, init) => {
|
|
566
|
+
let fetchData: ajaxRecord;
|
|
567
|
+
if (!_disableFetchTracking && _fetchInitialized &&
|
|
568
|
+
!_isDisabledRequest(null, input, init) &&
|
|
569
|
+
// If we have a polyfil and XHR instrumented then let XHR report otherwise we get duplicates
|
|
570
|
+
!(isPolyfill && _xhrInitialized)) {
|
|
571
|
+
let ctx = callDetails.ctx();
|
|
572
|
+
fetchData = _createFetchRecord(input, init);
|
|
573
|
+
let newInit = _self.includeCorrelationHeaders(fetchData, input, init);
|
|
574
|
+
if (newInit !== init) {
|
|
575
|
+
callDetails.set(1, newInit);
|
|
576
|
+
}
|
|
577
|
+
ctx.data = fetchData;
|
|
573
578
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
});
|
|
579
|
+
},
|
|
580
|
+
rsp: (callDetails: IInstrumentCallDetails, input) => {
|
|
581
|
+
if (!_disableFetchTracking) {
|
|
582
|
+
let fetchData = callDetails.ctx().data;
|
|
583
|
+
if (fetchData) {
|
|
584
|
+
// Replace the result with the new promise from this code
|
|
585
|
+
callDetails.rslt = callDetails.rslt.then((response: any) => {
|
|
586
|
+
_reportFetchMetrics(callDetails, (response||{}).status, input, response, fetchData, () => {
|
|
587
|
+
let ajaxResponse:IAjaxRecordResponse = {
|
|
588
|
+
statusText: response.statusText,
|
|
589
|
+
headerMap: null,
|
|
590
|
+
correlationContext: _getFetchCorrelationContext(response)
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
if (_enableResponseHeaderTracking) {
|
|
594
|
+
const responseHeaderMap = {};
|
|
595
|
+
response.headers.forEach((value: string, name: string) => { // @skip-minify
|
|
596
|
+
if (_canIncludeHeaders(name)) {
|
|
597
|
+
responseHeaderMap[name] = value;
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
ajaxResponse.headerMap = responseHeaderMap;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
return ajaxResponse;
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
return response;
|
|
608
|
+
})
|
|
609
|
+
.catch((reason: any) => {
|
|
610
|
+
_reportFetchMetrics(callDetails, 0, input, null, fetchData, null, { error: reason.message });
|
|
611
|
+
throw reason;
|
|
612
|
+
});
|
|
613
|
+
}
|
|
610
614
|
}
|
|
615
|
+
},
|
|
616
|
+
// Create an error callback to report any hook errors
|
|
617
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxOpen,
|
|
618
|
+
"Failed to monitor Window.fetch" + ERROR_POSTFIX)
|
|
619
|
+
}));
|
|
620
|
+
|
|
621
|
+
_fetchInitialized = true;
|
|
622
|
+
} else if (isPolyfill && !_polyfillInitialized) {
|
|
623
|
+
// If fetch is a polyfill we need to capture the request to ensure that we correctly track
|
|
624
|
+
// disabled request URLS (i.e. internal urls) to ensure we don't end up in a constant loop
|
|
625
|
+
// of reporting ourselves, for example React Native uses a polyfill for fetch
|
|
626
|
+
// Note: Polyfill implementations that don't support the "polyfill" tag are not supported
|
|
627
|
+
// the workaround is to add a polyfill property to your fetch implementation before initializing
|
|
628
|
+
// App Insights
|
|
629
|
+
_addHook(InstrumentFunc(global, strFetch, {
|
|
630
|
+
ns: _evtNamespace,
|
|
631
|
+
req: (callDetails: IInstrumentCallDetails, input, init) => {
|
|
632
|
+
// Just call so that we record any disabled URL
|
|
633
|
+
_isDisabledRequest(null, input, init);
|
|
611
634
|
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
_fetchInitialized = true;
|
|
619
|
-
} else if (isPolyfill) {
|
|
620
|
-
// If fetch is a polyfill we need to capture the request to ensure that we correctly track
|
|
621
|
-
// disabled request URLS (i.e. internal urls) to ensure we don't end up in a constant loop
|
|
622
|
-
// of reporting ourselves, for example React Native uses a polyfill for fetch
|
|
623
|
-
// Note: Polyfill implementations that don't support the "poyyfill" tag are not supported
|
|
624
|
-
// the workaround is to add a polyfill property to your fetch implementation before initializing
|
|
625
|
-
// App Insights
|
|
626
|
-
_addHook(InstrumentFunc(global, strFetch, {
|
|
627
|
-
ns: _evtNamespace,
|
|
628
|
-
req: (callDetails: IInstrumentCallDetails, input, init) => {
|
|
629
|
-
// Just call so that we record any disabled URL
|
|
630
|
-
_isDisabledRequest(null, input, init);
|
|
631
|
-
}
|
|
632
|
-
}));
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
+
}));
|
|
636
|
+
_polyfillInitialized = true;
|
|
637
|
+
}
|
|
638
|
+
}));
|
|
639
|
+
|
|
635
640
|
if (isPolyfill) {
|
|
636
641
|
// retag the instrumented fetch with the same polyfill settings this is mostly for testing
|
|
637
642
|
// But also supports multiple App Insights usages
|
|
@@ -644,82 +649,91 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
644
649
|
}
|
|
645
650
|
|
|
646
651
|
function _instrumentXhr():void {
|
|
647
|
-
if (_supportsAjaxMonitoring(_self)
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
652
|
+
if (!_supportsAjaxMonitoring(_self)) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
_self._addHook(onConfigChange(_extensionConfig, () => {
|
|
656
|
+
_disableAjaxTracking = !!_extensionConfig.disableAjaxTracking;
|
|
657
|
+
_enableRequestHeaderTracking = _extensionConfig.enableRequestHeaderTracking;
|
|
658
|
+
|
|
659
|
+
if (!_disableAjaxTracking && !_xhrInitialized) {
|
|
660
|
+
// Instrument open
|
|
661
|
+
_hookProto(XMLHttpRequest, "open", {
|
|
662
|
+
ns: _evtNamespace,
|
|
663
|
+
req: (args:IInstrumentCallDetails, method:string, url:string, async?:boolean) => {
|
|
664
|
+
if (!_disableAjaxTracking) {
|
|
665
|
+
let xhr = args.inst as XMLHttpRequestInstrumented;
|
|
666
|
+
let ajaxData = xhr[strAjaxData];
|
|
667
|
+
if (!_isDisabledRequest(xhr, url) && _isMonitoredXhrInstance(xhr, true)) {
|
|
668
|
+
if (!ajaxData || !ajaxData.xhrMonitoringState.openDone) {
|
|
669
|
+
// Only create a single ajaxData (even when multiple AI instances are running)
|
|
670
|
+
_openHandler(xhr, method, url, async);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// always attach to the on ready state change (required for handling multiple instances)
|
|
674
|
+
_attachToOnReadyStateChange(xhr);
|
|
659
675
|
}
|
|
660
|
-
|
|
661
|
-
// always attach to the on ready state change (required for handling multiple instances)
|
|
662
|
-
_attachToOnReadyStateChange(xhr);
|
|
663
676
|
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
677
|
+
},
|
|
678
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxOpen,
|
|
679
|
+
ERROR_HEADER + ".open" + ERROR_POSTFIX)
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
// Instrument send
|
|
683
|
+
_hookProto(XMLHttpRequest, "send", {
|
|
684
|
+
ns: _evtNamespace,
|
|
685
|
+
req: (args:IInstrumentCallDetails, context?: Document | BodyInit | null) => {
|
|
686
|
+
if (!_disableAjaxTracking) {
|
|
687
|
+
let xhr = args.inst as XMLHttpRequestInstrumented;
|
|
688
|
+
let ajaxData = xhr[strAjaxData];
|
|
689
|
+
if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.sendDone) {
|
|
690
|
+
_createMarkId("xhr", ajaxData);
|
|
691
|
+
ajaxData.requestSentTime = dateTimeUtilsNow();
|
|
692
|
+
_self.includeCorrelationHeaders(ajaxData, undefined, undefined, xhr);
|
|
693
|
+
ajaxData.xhrMonitoringState.sendDone = true;
|
|
694
|
+
}
|
|
682
695
|
}
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
696
|
+
},
|
|
697
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxSend,
|
|
698
|
+
ERROR_HEADER + ERROR_POSTFIX)
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
// Instrument abort
|
|
702
|
+
_hookProto(XMLHttpRequest, "abort", {
|
|
703
|
+
ns: _evtNamespace,
|
|
704
|
+
req: (args:IInstrumentCallDetails) => {
|
|
705
|
+
if (!_disableAjaxTracking) {
|
|
706
|
+
let xhr = args.inst as XMLHttpRequestInstrumented;
|
|
707
|
+
let ajaxData = xhr[strAjaxData];
|
|
708
|
+
if (_isMonitoredXhrInstance(xhr) && !ajaxData.xhrMonitoringState.abortDone) {
|
|
709
|
+
ajaxData.aborted = 1;
|
|
710
|
+
ajaxData.xhrMonitoringState.abortDone = true;
|
|
711
|
+
}
|
|
699
712
|
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
713
|
+
},
|
|
714
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxAbort,
|
|
715
|
+
ERROR_HEADER + ".abort" + ERROR_POSTFIX)
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
// Instrument setRequestHeader
|
|
719
|
+
_hookProto(XMLHttpRequest, "setRequestHeader", {
|
|
720
|
+
ns: _evtNamespace,
|
|
721
|
+
req: (args: IInstrumentCallDetails, header: string, value: string) => {
|
|
722
|
+
if (!_disableAjaxTracking && _enableRequestHeaderTracking) {
|
|
723
|
+
let xhr = args.inst as XMLHttpRequestInstrumented;
|
|
724
|
+
if (_isMonitoredXhrInstance(xhr) && _canIncludeHeaders(header)) {
|
|
725
|
+
xhr[strAjaxData].requestHeaders[header] = value;
|
|
726
|
+
}
|
|
714
727
|
}
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
}
|
|
728
|
+
},
|
|
729
|
+
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxSetRequestHeader,
|
|
730
|
+
ERROR_HEADER + ".setRequestHeader" + ERROR_POSTFIX)
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
_xhrInitialized = true;
|
|
734
|
+
}
|
|
735
|
+
}));
|
|
736
|
+
|
|
723
737
|
}
|
|
724
738
|
|
|
725
739
|
function _isDisabledRequest(xhr?: XMLHttpRequestInstrumented, request?: Request | string, init?: RequestInit) {
|
|
@@ -7,6 +7,7 @@ export declare const _DYN_TRACE_FLAGS = "traceFlags";
|
|
|
7
7
|
export declare const _DYN_CONTEXT = "context";
|
|
8
8
|
export declare const _DYN_TRACE_ID0 = "traceId";
|
|
9
9
|
export declare const _DYN_SPAN_ID1 = "spanId";
|
|
10
|
+
export declare const _DYN__ADD_HOOK = "_addHook";
|
|
10
11
|
export declare const _DYN_CORE = "core";
|
|
11
12
|
export declare const _DYN_INCLUDE_CORRELATION_2 = "includeCorrelationHeaders";
|
|
12
13
|
export declare const _DYN_GET_ABSOLUTE_URL = "getAbsoluteUrl";
|
|
@@ -20,12 +21,12 @@ export declare const _DYN_ENABLE_REQUEST_HEADE4 = "enableRequestHeaderTracking";
|
|
|
20
21
|
export declare const _DYN_ENABLE_AJAX_ERROR_ST5 = "enableAjaxErrorStatusText";
|
|
21
22
|
export declare const _DYN_ENABLE_AJAX_PERF_TRA6 = "enableAjaxPerfTracking";
|
|
22
23
|
export declare const _DYN_MAX_AJAX_CALLS_PER_V7 = "maxAjaxCallsPerView";
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const _DYN_EXCLUDE_REQUEST_FROM9 = "excludeRequestFromAutoTrackingPatterns";
|
|
24
|
+
export declare const _DYN_EXCLUDE_REQUEST_FROM8 = "excludeRequestFromAutoTrackingPatterns";
|
|
25
25
|
export declare const _DYN_ADD_REQUEST_CONTEXT = "addRequestContext";
|
|
26
|
-
export declare const
|
|
26
|
+
export declare const _DYN_DISABLE_AJAX_TRACKIN9 = "disableAjaxTracking";
|
|
27
|
+
export declare const _DYN_AJAX_PERF_LOOKUP_DEL10 = "ajaxPerfLookupDelay";
|
|
27
28
|
export declare const _DYN_DISABLE_FETCH_TRACKI11 = "disableFetchTracking";
|
|
28
|
-
export declare const
|
|
29
|
+
export declare const _DYN_ENABLE_RESPONSE_HEAD12 = "enableResponseHeaderTracking";
|
|
29
30
|
export declare const _DYN_STATUS = "status";
|
|
30
31
|
export declare const _DYN_STATUS_TEXT = "statusText";
|
|
31
32
|
export declare const _DYN_HEADER_MAP = "headerMap";
|