@microsoft/applicationinsights-core-js 2.8.0-beta.2203-01 → 2.8.0-beta.2203-02
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-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +945 -479
- package/browser/applicationinsights-core-js.js.map +1 -1
- package/browser/applicationinsights-core-js.min.js +2 -2
- package/browser/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.api.json +3904 -877
- package/dist/applicationinsights-core-js.api.md +264 -30
- package/dist/applicationinsights-core-js.d.ts +410 -89
- package/dist/applicationinsights-core-js.js +945 -479
- package/dist/applicationinsights-core-js.js.map +1 -1
- package/dist/applicationinsights-core-js.min.js +2 -2
- package/dist/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.rollup.d.ts +410 -89
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +66 -23
- package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +44 -5
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +105 -73
- package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +3 -4
- package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +6 -122
- package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +93 -0
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -0
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +12 -12
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +8 -7
- package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +472 -0
- package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -0
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +32 -59
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +28 -0
- package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -0
- package/dist-esm/JavaScriptSDK/NotificationManager.js +8 -11
- package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +184 -110
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +3 -2
- package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +32 -13
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +4 -6
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
- package/dist-esm/applicationinsights-core-js.js +8 -4
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +1 -1
- package/src/JavaScriptSDK/BaseCore.ts +80 -24
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +76 -5
- package/src/JavaScriptSDK/ChannelController.ts +107 -61
- package/src/JavaScriptSDK/CookieMgr.ts +4 -4
- package/src/JavaScriptSDK/CoreUtils.ts +6 -143
- package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
- package/src/JavaScriptSDK/DiagnosticLogger.ts +12 -11
- package/src/JavaScriptSDK/EnvUtils.ts +7 -6
- package/src/JavaScriptSDK/EventHelpers.ts +542 -0
- package/src/JavaScriptSDK/HelperFuncs.ts +35 -54
- package/src/JavaScriptSDK/InternalConstants.ts +26 -0
- package/src/JavaScriptSDK/NotificationManager.ts +7 -11
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +237 -124
- package/src/JavaScriptSDK/RandomHelper.ts +2 -1
- package/src/JavaScriptSDK/TelemetryHelpers.ts +47 -15
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +5 -15
- package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
- package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +20 -0
- package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +9 -2
- package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +55 -16
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +16 -9
- package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
- package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
- package/types/JavaScriptSDK/BaseCore.d.ts +4 -0
- package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +20 -1
- package/types/JavaScriptSDK/ChannelController.d.ts +4 -0
- package/types/JavaScriptSDK/CoreUtils.d.ts +1 -42
- package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
- package/types/JavaScriptSDK/EventHelpers.d.ts +152 -0
- package/types/JavaScriptSDK/HelperFuncs.d.ts +8 -17
- package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
- package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +10 -3
- package/types/JavaScriptSDK/TelemetryHelpers.d.ts +8 -0
- package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -7
- package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
- package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +9 -0
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +17 -0
- package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +9 -2
- package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +49 -14
- package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +15 -8
- package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
- package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
- package/types/applicationinsights-core-js.d.ts +6 -3
|
@@ -6,158 +6,21 @@ import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
|
|
|
6
6
|
import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
|
|
7
7
|
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
|
|
8
8
|
import { _gblCookieMgr } from "./CookieMgr";
|
|
9
|
-
import {
|
|
9
|
+
import { getPerformance, isIE } from "./EnvUtils";
|
|
10
10
|
import {
|
|
11
|
-
arrForEach, arrIndexOf, arrMap, arrReduce,
|
|
11
|
+
arrForEach, arrIndexOf, arrMap, arrReduce, dateNow, hasOwnProperty,
|
|
12
12
|
isArray, isBoolean, isDate, isError, isFunction, isNullOrUndefined, isNumber, isObject, isString, isTypeof,
|
|
13
13
|
isUndefined, objDefineAccessors, objKeys, strTrim, toISOString
|
|
14
14
|
} from "./HelperFuncs";
|
|
15
|
+
import { addEventHandler, attachEvent, detachEvent } from "./EventHelpers";
|
|
15
16
|
import { randomValue, random32, mwcRandomSeed, mwcRandom32, newId } from "./RandomHelper";
|
|
16
|
-
|
|
17
|
-
const strVisibilityChangeEvt: string = "visibilitychange";
|
|
18
|
-
const strPageHide: string = "pagehide";
|
|
19
|
-
const strPageShow: string = "pageshow";
|
|
17
|
+
import { strEmpty } from "./InternalConstants";
|
|
20
18
|
|
|
21
19
|
let _cookieMgrs: ICookieMgr[] = null;
|
|
22
20
|
let _canUseCookies: boolean; // legacy supported config
|
|
23
21
|
|
|
24
22
|
// Added to help with minfication
|
|
25
23
|
export const Undefined = strShimUndefined;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Trys to add an event handler for the specified event to the window, body and document
|
|
29
|
-
* @param eventName {string} - The name of the event
|
|
30
|
-
* @param callback {any} - The callback function that needs to be executed for the given event
|
|
31
|
-
* @return {boolean} - true if the handler was successfully added
|
|
32
|
-
*/
|
|
33
|
-
export function addEventHandler(eventName: string, callback: any): boolean {
|
|
34
|
-
let result = false;
|
|
35
|
-
let w = getWindow();
|
|
36
|
-
if (w) {
|
|
37
|
-
result = attachEvent(w, eventName, callback);
|
|
38
|
-
result = attachEvent(w["body"], eventName, callback) || result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let doc = getDocument();
|
|
42
|
-
if (doc) {
|
|
43
|
-
result = attachEvent(doc, eventName, callback) || result;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Bind the listener to the array of events
|
|
51
|
-
* @param events An string array of event names to bind the listener to
|
|
52
|
-
* @param listener The event callback to call when the event is triggered
|
|
53
|
-
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
54
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
55
|
-
*/
|
|
56
|
-
export function addEventListeners(events: string[], listener: any, excludeEvents?: string[]): boolean {
|
|
57
|
-
let added = false;
|
|
58
|
-
|
|
59
|
-
if (listener && events && isArray(events)) {
|
|
60
|
-
let excluded: string[] = [];
|
|
61
|
-
arrForEach(events, (name) => {
|
|
62
|
-
if (isString(name)) {
|
|
63
|
-
if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
|
|
64
|
-
added = addEventHandler(name, listener) || added;
|
|
65
|
-
} else {
|
|
66
|
-
excluded.push(name);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
if (!added && excluded.length > 0) {
|
|
72
|
-
// Failed to add any listeners and we excluded some, so just attempt to add the excluded events
|
|
73
|
-
added = addEventListeners(excluded, listener);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return added;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,
|
|
82
|
-
* this does NOT listen to the 'visibilitychange' event as while it does indicate that the page is being hidden
|
|
83
|
-
* it does not *necessarily* mean that the page is being completely unloaded, it can mean that the user is
|
|
84
|
-
* just navigating to a different Tab and may come back (without unloading the page). As such you may also
|
|
85
|
-
* need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.
|
|
86
|
-
* @param listener - The event callback to call when a page unload event is triggered
|
|
87
|
-
* @param excludeEvents - [Optional] An array of events that should not be hooked, unless no other events can be.
|
|
88
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
89
|
-
*/
|
|
90
|
-
export function addPageUnloadEventListener(listener: any, excludeEvents?: string[]): boolean {
|
|
91
|
-
// Hook the unload event for the document, window and body to ensure that the client events are flushed to the server
|
|
92
|
-
// As just hooking the window does not always fire (on chrome) for page navigation's.
|
|
93
|
-
return addEventListeners(["beforeunload", "unload", "pagehide"], listener, excludeEvents);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Listen to the pagehide and visibility changing to 'hidden' events
|
|
98
|
-
* @param listener - The event callback to call when a page hide event is triggered
|
|
99
|
-
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
100
|
-
* Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
|
|
101
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
102
|
-
*/
|
|
103
|
-
export function addPageHideEventListener(listener: any, excludeEvents?: string[]): boolean {
|
|
104
|
-
|
|
105
|
-
function _handlePageVisibility(evt: any) {
|
|
106
|
-
let doc = getDocument();
|
|
107
|
-
if (listener && doc && doc.visibilityState === "hidden") {
|
|
108
|
-
listener(evt);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
let pageUnloadAdded = false;
|
|
113
|
-
if (!excludeEvents || arrIndexOf(excludeEvents, strPageHide) === -1) {
|
|
114
|
-
pageUnloadAdded = addEventHandler(strPageHide, listener);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
|
|
118
|
-
pageUnloadAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageUnloadAdded;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (!pageUnloadAdded && excludeEvents) {
|
|
122
|
-
// Failed to add any listeners and we where requested to exclude some, so just call again without excluding anything
|
|
123
|
-
pageUnloadAdded = addPageHideEventListener(listener);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return pageUnloadAdded;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Listen to the pageshow and visibility changing to 'visible' events
|
|
131
|
-
* @param listener - The event callback to call when a page is show event is triggered
|
|
132
|
-
* @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
|
|
133
|
-
* @returns true - when at least one of the events was registered otherwise false
|
|
134
|
-
*/
|
|
135
|
-
export function addPageShowEventListener(listener: any, excludeEvents?: string[]): boolean {
|
|
136
|
-
|
|
137
|
-
function _handlePageVisibility(evt: any) {
|
|
138
|
-
let doc = getDocument();
|
|
139
|
-
if (listener && doc && doc.visibilityState === "visible") {
|
|
140
|
-
listener(evt);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
let pageShowAdded = false;
|
|
145
|
-
if (!excludeEvents || arrIndexOf(excludeEvents, strPageShow) === -1) {
|
|
146
|
-
pageShowAdded = addEventHandler(strPageShow, listener);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
|
|
150
|
-
pageShowAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageShowAdded;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (!pageShowAdded && excludeEvents) {
|
|
154
|
-
// Failed to add any listeners and we where requested to exclude some, so just call again without excluding anything
|
|
155
|
-
pageShowAdded = addPageShowEventListener(listener);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return pageShowAdded;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
24
|
export function newGuid(): string {
|
|
162
25
|
function randomHexDigit() {
|
|
163
26
|
return randomValue(15); // Get a random value from 0..15
|
|
@@ -205,7 +68,7 @@ export function generateW3CId(): string {
|
|
|
205
68
|
const hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
|
|
206
69
|
|
|
207
70
|
// rfc4122 version 4 UUID without dashes and with lowercase letters
|
|
208
|
-
let oct =
|
|
71
|
+
let oct = strEmpty, tmp;
|
|
209
72
|
for (let a = 0; a < 4; a++) {
|
|
210
73
|
tmp = random32();
|
|
211
74
|
oct +=
|
|
@@ -380,7 +243,7 @@ export interface ICoreUtils {
|
|
|
380
243
|
* @param callback {any} - The callback function that needs to be executed for the given event
|
|
381
244
|
* @return {boolean} - true if the handler was successfully added
|
|
382
245
|
*/
|
|
383
|
-
addEventHandler: (eventName: string, callback: any) => boolean;
|
|
246
|
+
addEventHandler: (eventName: string, callback: any, evtNamespace?: string | string[]) => boolean;
|
|
384
247
|
|
|
385
248
|
/**
|
|
386
249
|
* Return the current time via the Date now() function (if available) and falls back to (new Date()).getTime() if now() is unavailable (IE8 or less)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
import { ObjDefineProperty } from "@microsoft/applicationinsights-shims";
|
|
5
|
+
import { normalizeJsName } from "./HelperFuncs";
|
|
6
|
+
import { newId } from "./RandomHelper";
|
|
7
|
+
|
|
8
|
+
const _objDefineProperty = ObjDefineProperty;
|
|
9
|
+
|
|
10
|
+
const version = "2.7.3";
|
|
11
|
+
let instanceName = "." + newId(6);
|
|
12
|
+
let _dataUid = 0;
|
|
13
|
+
|
|
14
|
+
export interface IDataCache {
|
|
15
|
+
id: string;
|
|
16
|
+
accept: (target: any) => boolean,
|
|
17
|
+
get: <T>(target: any, name: string, defValue?: T, addDefault?: boolean) => T;
|
|
18
|
+
kill: (target: any, name: string) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function _createAccessor<T>(target: any, prop: string, value: T): boolean {
|
|
22
|
+
if (_objDefineProperty) {
|
|
23
|
+
try {
|
|
24
|
+
_objDefineProperty(target, prop, {
|
|
25
|
+
value: value,
|
|
26
|
+
enumerable: false,
|
|
27
|
+
configurable: true
|
|
28
|
+
});
|
|
29
|
+
return true;
|
|
30
|
+
} catch (e) {
|
|
31
|
+
// IE8 Defines a defineProperty on Object but it's only supported for DOM elements so it will throw
|
|
32
|
+
// We will just ignore this here.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Accepts only:
|
|
40
|
+
// - Node
|
|
41
|
+
// - Node.ELEMENT_NODE
|
|
42
|
+
// - Node.DOCUMENT_NODE
|
|
43
|
+
// - Object
|
|
44
|
+
// - Any
|
|
45
|
+
function _canAcceptData(target: any) {
|
|
46
|
+
return target.nodeType === 1 || target.nodeType === 9 || !( +target.nodeType );
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function _getCache(data: IDataCache, target: Node) {
|
|
50
|
+
let theCache = target[data.id];
|
|
51
|
+
if (!theCache) {
|
|
52
|
+
theCache = {};
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
if (_canAcceptData(target)) {
|
|
56
|
+
if (!_createAccessor(target, data.id, theCache)) {
|
|
57
|
+
// Environment doesn't support accessor, so just use direct assignment
|
|
58
|
+
target[data.id] = theCache;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// Not all environments allow extending all objects, so just ignore the cache in those cases
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return theCache;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function createUniqueNamespace(name: string, includeVersion: boolean = false): string {
|
|
70
|
+
return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function createElmNodeData(name?: string) {
|
|
74
|
+
|
|
75
|
+
let data = {
|
|
76
|
+
id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
|
|
77
|
+
accept: function (target: any) {
|
|
78
|
+
return _canAcceptData(target);
|
|
79
|
+
},
|
|
80
|
+
get: function <T>(target: any, name: string, defValue?: T, addDefault?: boolean): T {
|
|
81
|
+
let theCache = target[data.id];
|
|
82
|
+
if (!theCache) {
|
|
83
|
+
if (addDefault) {
|
|
84
|
+
// Side effect is adds the cache
|
|
85
|
+
theCache = _getCache(data, target);
|
|
86
|
+
theCache[normalizeJsName(name)] = defValue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return defValue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return theCache[normalizeJsName(name)];
|
|
93
|
+
},
|
|
94
|
+
kill: function(target: any, name: string) {
|
|
95
|
+
if (target && target[name]) {
|
|
96
|
+
try {
|
|
97
|
+
delete target[name];
|
|
98
|
+
} catch (e) {
|
|
99
|
+
// Just cleaning up, so if this fails -- ignore
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return data;
|
|
106
|
+
}
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
"use strict"
|
|
4
4
|
import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration"
|
|
5
|
-
import { _InternalMessageId, LoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
|
|
5
|
+
import { _InternalMessageId, _eInternalMessageId, LoggingSeverity, eLoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
|
|
6
6
|
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
|
|
7
7
|
import { hasJSON, getJSON, getConsole } from "./EnvUtils";
|
|
8
8
|
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
9
9
|
import { isFunction, isNullOrUndefined, isUndefined } from "./HelperFuncs";
|
|
10
10
|
import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
|
|
11
11
|
import { getDebugExt } from "./DbgExtensionUtils";
|
|
12
|
+
import { strEmpty } from "./InternalConstants";
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* For user non actionable traces use AI Internal prefix.
|
|
@@ -30,10 +31,10 @@ const strWarnToConsole = "warnToConsole";
|
|
|
30
31
|
|
|
31
32
|
function _sanitizeDiagnosticText(text: string) {
|
|
32
33
|
if (text) {
|
|
33
|
-
return "\"" + text.replace(/\"/g,
|
|
34
|
+
return "\"" + text.replace(/\"/g, strEmpty) + "\"";
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
return
|
|
37
|
+
return strEmpty;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
function _logToConsole(func: string, message: string) {
|
|
@@ -64,14 +65,14 @@ export class _InternalLogMessage{
|
|
|
64
65
|
(isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
|
|
65
66
|
msgId;
|
|
66
67
|
|
|
67
|
-
let strProps:string =
|
|
68
|
+
let strProps:string = strEmpty;
|
|
68
69
|
if (hasJSON()) {
|
|
69
70
|
strProps = getJSON().stringify(properties);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
const diagnosticText =
|
|
73
|
-
(msg ? " message:" + _sanitizeDiagnosticText(msg) :
|
|
74
|
-
(properties ? " props:" + _sanitizeDiagnosticText(strProps) :
|
|
74
|
+
(msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
|
|
75
|
+
(properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
|
|
75
76
|
|
|
76
77
|
_self.message += diagnosticText;
|
|
77
78
|
}
|
|
@@ -125,7 +126,7 @@ export class DiagnosticLogger implements IDiagnosticLogger {
|
|
|
125
126
|
throw message;
|
|
126
127
|
} else {
|
|
127
128
|
// Get the logging function and fallback to warnToConsole of for some reason errorToConsole doesn't exist
|
|
128
|
-
let logFunc = severity ===
|
|
129
|
+
let logFunc = severity === eLoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
|
|
129
130
|
|
|
130
131
|
if (!isUndefined(message.message)) {
|
|
131
132
|
const logLevel = _self.consoleLoggingLevel();
|
|
@@ -146,7 +147,7 @@ export class DiagnosticLogger implements IDiagnosticLogger {
|
|
|
146
147
|
|
|
147
148
|
_self.logInternalMessage(severity, message);
|
|
148
149
|
} else {
|
|
149
|
-
_debugExtMsg("throw" + (severity ===
|
|
150
|
+
_debugExtMsg("throw" + (severity === eLoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
153
|
}
|
|
@@ -203,15 +204,15 @@ export class DiagnosticLogger implements IDiagnosticLogger {
|
|
|
203
204
|
if (severity <= _self.telemetryLoggingLevel()) {
|
|
204
205
|
_self.queue.push(message);
|
|
205
206
|
_messageCount++;
|
|
206
|
-
_debugExtMsg((severity ===
|
|
207
|
+
_debugExtMsg((severity === eLoggingSeverity.CRITICAL ? "error" : "warn"), message);
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
// When throttle limit reached, send a special event
|
|
210
211
|
if (_messageCount === _self.maxInternalMessageLimit()) {
|
|
211
212
|
const throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
|
|
212
|
-
const throttleMessage = new _InternalLogMessage(
|
|
213
|
+
const throttleMessage = new _InternalLogMessage(_eInternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
|
|
213
214
|
_self.queue.push(throttleMessage);
|
|
214
|
-
if (severity ===
|
|
215
|
+
if (severity === eLoggingSeverity.CRITICAL) {
|
|
215
216
|
_self.errorToConsole(throttleLimitMessage);
|
|
216
217
|
} else {
|
|
217
218
|
_self.warnToConsole(throttleLimitMessage);
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import {
|
|
6
6
|
getGlobal, strShimUndefined, strShimObject, strShimPrototype
|
|
7
7
|
} from "@microsoft/applicationinsights-shims";
|
|
8
|
+
import { strEmpty } from "./InternalConstants";
|
|
8
9
|
import { isString, isUndefined, strContains } from "./HelperFuncs";
|
|
9
10
|
|
|
10
11
|
// TypeScript removed this interface so we need to declare the global so we can check for it's existence.
|
|
@@ -296,7 +297,7 @@ export function isIE() {
|
|
|
296
297
|
if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
|
|
297
298
|
// Added to support test mocking of the user agent
|
|
298
299
|
_navUserAgentCheck = nav.userAgent;
|
|
299
|
-
let userAgent = (_navUserAgentCheck ||
|
|
300
|
+
let userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
|
|
300
301
|
_isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
|
|
301
302
|
}
|
|
302
303
|
|
|
@@ -309,10 +310,10 @@ export function isIE() {
|
|
|
309
310
|
export function getIEVersion(userAgentStr: string = null): number {
|
|
310
311
|
if (!userAgentStr) {
|
|
311
312
|
let navigator = getNavigator() || ({} as Navigator);
|
|
312
|
-
userAgentStr = navigator ? (navigator.userAgent ||
|
|
313
|
+
userAgentStr = navigator ? (navigator.userAgent || strEmpty).toLowerCase() : strEmpty;
|
|
313
314
|
}
|
|
314
315
|
|
|
315
|
-
var ua = (userAgentStr ||
|
|
316
|
+
var ua = (userAgentStr || strEmpty).toLowerCase();
|
|
316
317
|
// Also check for documentMode in case X-UA-Compatible meta tag was included in HTML.
|
|
317
318
|
if (strContains(ua, strMsie)) {
|
|
318
319
|
let doc = getDocument() || {} as Document;
|
|
@@ -332,7 +333,7 @@ export function getIEVersion(userAgentStr: string = null): number {
|
|
|
332
333
|
*/
|
|
333
334
|
export function dumpObj(object: any): string {
|
|
334
335
|
const objectTypeDump: string = Object[strShimPrototype].toString.call(object);
|
|
335
|
-
let propertyValueDump: string =
|
|
336
|
+
let propertyValueDump: string = strEmpty;
|
|
336
337
|
if (objectTypeDump === "[object Error]") {
|
|
337
338
|
propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
|
|
338
339
|
} else if (hasJSON()) {
|
|
@@ -345,10 +346,10 @@ export function dumpObj(object: any): string {
|
|
|
345
346
|
export function isSafari(userAgentStr ?: string) {
|
|
346
347
|
if (!userAgentStr || !isString(userAgentStr)) {
|
|
347
348
|
let navigator = getNavigator() || ({} as Navigator);
|
|
348
|
-
userAgentStr = navigator ? (navigator.userAgent ||
|
|
349
|
+
userAgentStr = navigator ? (navigator.userAgent || strEmpty).toLowerCase() : strEmpty;
|
|
349
350
|
}
|
|
350
351
|
|
|
351
|
-
var ua = (userAgentStr ||
|
|
352
|
+
var ua = (userAgentStr || strEmpty).toLowerCase();
|
|
352
353
|
return (ua.indexOf("safari") >= 0);
|
|
353
354
|
}
|
|
354
355
|
|