@microsoft/applicationinsights-core-js 2.7.4-nightly.2202-09 → 2.8.0-beta.2202-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.
Files changed (108) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +860 -457
  3. package/browser/applicationinsights-core-js.js.map +1 -1
  4. package/browser/applicationinsights-core-js.min.js +2 -2
  5. package/browser/applicationinsights-core-js.min.js.map +1 -1
  6. package/dist/applicationinsights-core-js.api.json +1193 -267
  7. package/dist/applicationinsights-core-js.api.md +54 -14
  8. package/dist/applicationinsights-core-js.d.ts +133 -45
  9. package/dist/applicationinsights-core-js.js +860 -457
  10. package/dist/applicationinsights-core-js.js.map +1 -1
  11. package/dist/applicationinsights-core-js.min.js +2 -2
  12. package/dist/applicationinsights-core-js.min.js.map +1 -1
  13. package/dist/applicationinsights-core-js.rollup.d.ts +133 -45
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +3 -69
  15. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/BaseCore.js +237 -82
  17. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +45 -19
  19. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/ChannelController.js +155 -87
  21. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  24. package/dist-esm/JavaScriptSDK/CoreUtils.js +2 -27
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  26. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  27. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  28. package/dist-esm/JavaScriptSDK/EnvUtils.js +6 -6
  29. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  30. package/dist-esm/JavaScriptSDK/HelperFuncs.js +51 -11
  31. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +3 -1
  33. package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/NotificationManager.js +34 -36
  35. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  36. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  37. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +289 -119
  38. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  39. package/dist-esm/JavaScriptSDK/RandomHelper.js +29 -4
  40. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  41. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +2 -2
  42. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  43. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +82 -0
  44. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -0
  45. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  46. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  47. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
  49. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  50. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
  62. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
  63. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  66. package/dist-esm/applicationinsights-core-js.js +4 -4
  67. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  68. package/package.json +2 -2
  69. package/src/JavaScriptSDK/AppInsightsCore.ts +2 -101
  70. package/src/JavaScriptSDK/BaseCore.ts +330 -100
  71. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +69 -32
  72. package/src/JavaScriptSDK/ChannelController.ts +175 -103
  73. package/src/JavaScriptSDK/CoreUtils.ts +1 -28
  74. package/src/JavaScriptSDK/EnvUtils.ts +5 -5
  75. package/src/JavaScriptSDK/HelperFuncs.ts +57 -14
  76. package/src/JavaScriptSDK/InstrumentHooks.ts +3 -1
  77. package/src/JavaScriptSDK/NotificationManager.ts +32 -31
  78. package/src/JavaScriptSDK/PerfManager.ts +1 -1
  79. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +350 -133
  80. package/src/JavaScriptSDK/RandomHelper.ts +34 -3
  81. package/src/JavaScriptSDK/TelemetryHelpers.ts +4 -6
  82. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +119 -0
  83. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +17 -1
  84. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +7 -3
  85. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +5 -0
  86. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +23 -5
  87. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
  88. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +1 -1
  89. package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
  90. package/types/JavaScriptSDK/BaseCore.d.ts +30 -1
  91. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +13 -11
  92. package/types/JavaScriptSDK/ChannelController.d.ts +12 -17
  93. package/types/JavaScriptSDK/CoreUtils.d.ts +0 -6
  94. package/types/JavaScriptSDK/HelperFuncs.d.ts +14 -5
  95. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +49 -3
  96. package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
  97. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -3
  98. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +23 -0
  99. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +15 -0
  100. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +7 -3
  101. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +4 -0
  102. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +18 -3
  103. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
  104. package/types/applicationinsights-core-js.d.ts +5 -4
  105. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
  106. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
  107. package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
  108. package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +0 -32
@@ -204,7 +204,7 @@ export function normalizeJsName(name: string): string {
204
204
  * @param target The target object to find and process the keys
205
205
  * @param callbackfn The function to call with the details
206
206
  */
207
- export function objForEachKey(target: any, callbackfn: (name: string, value: any) => void) {
207
+ export function objForEachKey<T = any>(target: T, callbackfn: (name: string, value: T[keyof T]) => void) {
208
208
  if (target) {
209
209
  for (let prop in target) {
210
210
  if (ObjHasOwnProperty.call(target, prop)) {
@@ -315,7 +315,8 @@ export function isDate(obj: any): obj is Date {
315
315
  }
316
316
 
317
317
  /**
318
- * Check if an object is of type Array
318
+ * Check if an object is of type Array with optional generic T, the generic type is not validated
319
+ * and exists to help with TypeScript validation only.
319
320
  */
320
321
  export let isArray: <T = any>(obj: any) => obj is Array<T> = _isArray || _isArrayPoly;
321
322
  function _isArrayPoly<T = any>(obj: any): obj is Array<T> {
@@ -438,7 +439,7 @@ export function _toISOStringPoly(date: Date) {
438
439
  * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. It can return -1 to break out of the loop
439
440
  * @param thisArg [Optional] An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
440
441
  */
441
- export function arrForEach<T>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void|number, thisArg?: any): void {
442
+ export function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void|number, thisArg?: any): void {
442
443
  let len = arr.length;
443
444
  try {
444
445
  for (let idx = 0; idx < len; idx++) {
@@ -746,6 +747,28 @@ export function throwError(message: string): never {
746
747
  throw new Error(message);
747
748
  }
748
749
 
750
+ function _createProxyFunction<S>(source: S | (() => S), funcName: (keyof S)) {
751
+ let srcFunc: () => S = null;
752
+ let src: S = null;
753
+ if (isFunction (source)) {
754
+ srcFunc = source;
755
+ } else {
756
+ src = source;
757
+ }
758
+
759
+ return function() {
760
+ // Capture the original arguments passed to the method
761
+ var originalArguments = arguments;
762
+ if (srcFunc) {
763
+ src = srcFunc();
764
+ }
765
+
766
+ if (src) {
767
+ return (src[funcName] as any).apply(src, originalArguments);
768
+ }
769
+ }
770
+ }
771
+
749
772
  /**
750
773
  * Effectively assigns all enumerable properties (not just own properties) and functions (including inherited prototype) from
751
774
  * the source object to the target, it attempts to use proxy getters / setters (if possible) and proxy functions to avoid potential
@@ -760,10 +783,9 @@ export function throwError(message: string): never {
760
783
  * @param target - The target object to be assigned with the source properties and functions
761
784
  * @param source - The source object which will be assigned / called by setting / calling the targets proxies
762
785
  * @param chkSet - An optional callback to determine whether a specific property/function should be proxied
763
- * @memberof Initialization
764
786
  */
765
- export function proxyAssign(target: any, source: any, chkSet?: (name: string, isFunc?: boolean, source?: any, target?: any) => boolean) {
766
- if (target && source && target !== source && isObject(target) && isObject(source)) {
787
+ export function proxyAssign<T, S>(target: T, source: S, chkSet?: (name: string, isFunc?: boolean, source?: S, target?: T) => boolean) {
788
+ if (target && source && isObject(target) && isObject(source)) {
767
789
  // effectively apply/proxy full source to the target instance
768
790
  for (const field in source) {
769
791
  if (isString(field)) {
@@ -771,18 +793,12 @@ export function proxyAssign(target: any, source: any, chkSet?: (name: string, is
771
793
  if (isFunction(value)) {
772
794
  if (!chkSet || chkSet(field, true, source, target)) {
773
795
  // Create a proxy function rather than just copying the (possible) prototype to the new object as an instance function
774
- target[field as string] = (function(funcName: string) {
775
- return function() {
776
- // Capture the original arguments passed to the method
777
- var originalArguments = arguments;
778
- return source[funcName].apply(source, originalArguments);
779
- }
780
- })(field);
796
+ target[field as string] = _createProxyFunction(source, field);
781
797
  }
782
798
  } else if (!chkSet || chkSet(field, false, source, target)) {
783
799
  if (hasOwnProperty(target, field)) {
784
800
  // Remove any previous instance property
785
- delete target[field];
801
+ delete (target as any)[field];
786
802
  }
787
803
 
788
804
  if (!objDefineAccessors(target, field, () => {
@@ -803,6 +819,33 @@ export function proxyAssign(target: any, source: any, chkSet?: (name: string, is
803
819
  return target;
804
820
  }
805
821
 
822
+ export function proxyFunctionAs<T, S>(target: T, name: string, source: S | (() => S), theFunc: (keyof S), overwriteTarget: boolean = true) {
823
+ if (target && name && source) {
824
+ if (overwriteTarget || isUndefined(target[name])) {
825
+ (target as any)[name] = _createProxyFunction(source, theFunc);
826
+ }
827
+ }
828
+ }
829
+
830
+ /**
831
+ * Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.
832
+ *
833
+ * @param target - The target object to be assigned with the source properties and functions
834
+ * @param source - The source object which will be assigned / called by setting / calling the targets proxies
835
+ * @param functionsToProxy - An array of function names that will be proxied on the target
836
+ */
837
+ export function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget: boolean = true) {
838
+ if (target && source && isObject(target) && isArray(functionsToProxy)) {
839
+ arrForEach(functionsToProxy, (theFuncName) => {
840
+ if (isString(theFuncName)) {
841
+ proxyFunctionAs(target, theFuncName, source, theFuncName, overwriteTarget);
842
+ }
843
+ });
844
+ }
845
+
846
+ return target;
847
+ }
848
+
806
849
  /**
807
850
  * Simpler helper to create a dynamic class that implements the interface and populates the values with the defaults.
808
851
  * Only instance properties (hasOwnProperty) values are copied from the defaults to the new instance
@@ -6,6 +6,7 @@ import {
6
6
  } from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
7
7
  import { strShimFunction, strShimPrototype } from "@microsoft/applicationinsights-shims";
8
8
  import { hasOwnProperty, _getObjProto } from "./HelperFuncs";
9
+ import { getGlobalInst } from "./EnvUtils";
9
10
 
10
11
  const aiInstrumentHooks = "_aiHooks";
11
12
 
@@ -78,7 +79,7 @@ function _createFunctionHook(aiHook:IInstrumentHooks) {
78
79
  let orgArgs = arguments as any;
79
80
  let hooks = aiHook.h;
80
81
 
81
- let funcArgs:IInstrumentCallDetails = {
82
+ let funcArgs: IInstrumentCallDetails = {
82
83
  name: aiHook.n,
83
84
  inst: funcThis,
84
85
  ctx: null,
@@ -87,6 +88,7 @@ function _createFunctionHook(aiHook:IInstrumentHooks) {
87
88
 
88
89
  let hookCtx: any[] = [];
89
90
  let cbArgs = _createArgs([funcArgs], orgArgs);
91
+ funcArgs.evt = getGlobalInst("event");
90
92
 
91
93
  function _createArgs(target:any[], theArgs:any[]): any[] {
92
94
  _arrLoop((theArgs as any), (arg) => {
@@ -8,6 +8,27 @@ import { IPerfEvent } from "../JavaScriptSDK.Interfaces/IPerfEvent";
8
8
  import dynamicProto from "@microsoft/dynamicproto-js";
9
9
  import { arrForEach, arrIndexOf } from "./HelperFuncs";
10
10
 
11
+ const strEventsSent = "eventsSent";
12
+ const strEventsDiscarded = "eventsDiscarded";
13
+ const strEventsSendRequest = "eventsSendRequest";
14
+ const strPerfEvent = "perfEvent";
15
+
16
+ function _runListeners(listeners: INotificationListener[], name: string, isAsync: boolean, callback: (listener: INotificationListener) => void) {
17
+ arrForEach(listeners, (listener) => {
18
+ if (listener && listener[name]) {
19
+ if (isAsync) {
20
+ setTimeout(() => callback(listener), 0);
21
+ } else {
22
+ try {
23
+ callback(listener);
24
+ } catch (e) {
25
+ // Catch errors to ensure we don't block sending the requests
26
+ }
27
+ }
28
+ }
29
+ });
30
+ }
31
+
11
32
  /**
12
33
  * Class to manage sending notifications to all the listeners.
13
34
  */
@@ -39,10 +60,8 @@ export class NotificationManager implements INotificationManager {
39
60
  * @param {ITelemetryItem[]} events - The array of events that have been sent.
40
61
  */
41
62
  _self.eventsSent = (events: ITelemetryItem[]): void => {
42
- arrForEach(_self.listeners, (listener) => {
43
- if (listener && listener.eventsSent) {
44
- setTimeout(() => listener.eventsSent(events), 0);
45
- }
63
+ _runListeners(_self.listeners, strEventsSent, true, (listener) => {
64
+ listener[strEventsSent](events);
46
65
  });
47
66
  };
48
67
 
@@ -53,10 +72,8 @@ export class NotificationManager implements INotificationManager {
53
72
  * constant should be used to check the different values.
54
73
  */
55
74
  _self.eventsDiscarded = (events: ITelemetryItem[], reason: number): void => {
56
- arrForEach(_self.listeners, (listener) => {
57
- if (listener && listener.eventsDiscarded) {
58
- setTimeout(() => listener.eventsDiscarded(events, reason), 0);
59
- }
75
+ _runListeners(_self.listeners, strEventsDiscarded, true, (listener) => {
76
+ listener[strEventsDiscarded](events, reason);
60
77
  });
61
78
  };
62
79
 
@@ -66,18 +83,8 @@ export class NotificationManager implements INotificationManager {
66
83
  * @param {boolean} isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
67
84
  */
68
85
  _self.eventsSendRequest = (sendReason: number, isAsync: boolean): void => {
69
- arrForEach(_self.listeners, (listener) => {
70
- if (listener && listener.eventsSendRequest) {
71
- if (isAsync) {
72
- setTimeout(() => listener.eventsSendRequest(sendReason, isAsync), 0);
73
- } else {
74
- try {
75
- listener.eventsSendRequest(sendReason, isAsync);
76
- } catch (e) {
77
- // Catch errors to ensure we don't block sending the requests
78
- }
79
- }
80
- }
86
+ _runListeners(_self.listeners, strEventsSendRequest, isAsync, (listener) => {
87
+ listener[strEventsSendRequest](sendReason, isAsync);
81
88
  });
82
89
  };
83
90
 
@@ -86,17 +93,11 @@ export class NotificationManager implements INotificationManager {
86
93
 
87
94
  // Send all events or only parent events
88
95
  if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
89
- arrForEach(_self.listeners, (listener) => {
90
- if (listener && listener.perfEvent) {
91
- if (perfEvent.isAsync) {
92
- setTimeout(() => listener.perfEvent(perfEvent), 0);
93
- } else {
94
- try {
95
- listener.perfEvent(perfEvent);
96
- } catch (e) {
97
- // Catch errors to ensure we don't block sending the requests
98
- }
99
- }
96
+ _runListeners(_self.listeners, strPerfEvent, false, (listener) => {
97
+ if (perfEvent.isAsync) {
98
+ setTimeout(() => listener[strPerfEvent](perfEvent), 0);
99
+ } else {
100
+ listener[strPerfEvent](perfEvent);
100
101
  }
101
102
  });
102
103
  }
@@ -119,7 +119,7 @@ export class PerfEvent implements IPerfEvent {
119
119
  _self.complete = () => {
120
120
  let childTime = 0;
121
121
  let childEvts = _self.getCtx(PerfEvent.ChildrenContextKey);
122
- if (isArray(childEvts)) {
122
+ if (isArray<IPerfEvent>(childEvts)) {
123
123
  for (let lp = 0; lp < childEvts.length; lp++) {
124
124
  let childEvt: IPerfEvent = childEvts[lp];
125
125
  if (childEvt) {