@microsoft/applicationinsights-core-js 2.7.5-nightly.2203-01 → 2.8.0-beta.2203-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.
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
@@ -0,0 +1,119 @@
1
+ // // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // // Licensed under the MIT License.
3
+
4
+ import dynamicProto from "@microsoft/dynamicproto-js";
5
+ import { LoggingSeverity, _InternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
6
+ import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
+ import { ITelemetryInitializerContainer, ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
8
+ import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
9
+ import { BaseTelemetryPlugin } from "./BaseTelemetryPlugin";
10
+ import { dumpObj } from "./EnvUtils";
11
+ import { arrForEach, getExceptionName } from "./HelperFuncs";
12
+
13
+ interface _IInternalTelemetryInitializerHandler {
14
+ id: number;
15
+ fn: TelemetryInitializerFunction;
16
+ }
17
+
18
+ export class TelemetryInitializerPlugin extends BaseTelemetryPlugin implements ITelemetryInitializerContainer {
19
+
20
+ public identifier: string = "TelemetryInitializerPlugin";
21
+ priority: number = 199;
22
+
23
+ constructor() {
24
+ super();
25
+
26
+ // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
27
+ let _id: number;
28
+ let _initializers: _IInternalTelemetryInitializerHandler[];
29
+
30
+ _initDefaults();
31
+
32
+ dynamicProto(TelemetryInitializerPlugin, this, (_self, _base) => {
33
+
34
+ _self.addTelemetryInitializer = (telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler => {
35
+ let theInitializer = {
36
+ id: _id++,
37
+ fn: telemetryInitializer
38
+ };
39
+
40
+ _initializers.push(theInitializer);
41
+
42
+ let handler: ITelemetryInitializerHandler = {
43
+ remove: () => {
44
+ arrForEach(_initializers, (initializer, idx) => {
45
+ if (initializer.id === theInitializer.id) {
46
+ _initializers.splice(idx, 1);
47
+ return -1;
48
+ }
49
+ });
50
+ }
51
+ }
52
+
53
+ return handler;
54
+ }
55
+
56
+ _self.processTelemetry = (item: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void => {
57
+ var doNotSendItem = false;
58
+ var telemetryInitializersCount = _initializers.length;
59
+ for (var i = 0; i < telemetryInitializersCount; ++i) {
60
+ var telemetryInitializer = _initializers[i];
61
+ if (telemetryInitializer) {
62
+ try {
63
+ if (telemetryInitializer.fn.apply(null, [item]) === false) {
64
+ doNotSendItem = true;
65
+ break;
66
+ }
67
+ } catch (e) {
68
+ // log error but dont stop executing rest of the telemetry initializers
69
+ // doNotSendItem = true;
70
+ itemCtx.diagLog().throwInternal(
71
+ LoggingSeverity.CRITICAL,
72
+ _InternalMessageId.TelemetryInitializerFailed,
73
+ "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e),
74
+ { exception: dumpObj(e) }, true);
75
+ }
76
+ }
77
+ }
78
+
79
+ if (!doNotSendItem) {
80
+ _self.processNext(item, itemCtx);
81
+ }
82
+ };
83
+
84
+ _self.unload = (itemCtx: IProcessTelemetryContext, isAsync: boolean): void => {
85
+ _base.unload(itemCtx, isAsync);
86
+ _initDefaults();
87
+ };
88
+ });
89
+
90
+ function _initDefaults() {
91
+ _id = 0;
92
+ _initializers = [];
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Add a telemetry processor to decorate or drop telemetry events.
98
+ * @param telemetryInitializer - The Telemetry Initializer function
99
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
100
+ */
101
+ public addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler {
102
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
103
+ return null;
104
+ }
105
+
106
+ public processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void {
107
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
108
+ }
109
+
110
+ /**
111
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
112
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
113
+ * @param itemCtx - This is the context that should be used during unloading if required to flush any cached events.
114
+ * @param isAsync - Should the plugin attempt to unload synchronously or can it complete asynchronously
115
+ */
116
+ public unload(itemCtx: IProcessTelemetryContext, isAsync: boolean): void {
117
+ // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
118
+ }
119
+ }
@@ -10,8 +10,11 @@ import { IDiagnosticLogger } from "./IDiagnosticLogger";
10
10
  import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
11
11
  import { IPerfManagerProvider } from "./IPerfManager";
12
12
  import { ICookieMgr } from "./ICookieMgr";
13
+ import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "./ITelemetryInitializers";
13
14
 
14
- "use strict";
15
+ export interface ILoadedPlugin<T extends IPlugin> {
16
+ plugin: T;
17
+ }
15
18
 
16
19
  export interface IAppInsightsCore extends IPerfManagerProvider {
17
20
 
@@ -72,6 +75,13 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
72
75
  */
73
76
  removeNotificationListener?(listener: INotificationListener): void;
74
77
 
78
+ /**
79
+ * Add a telemetry processor to decorate or drop telemetry events.
80
+ * @param telemetryInitializer - The Telemetry Initializer function
81
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
82
+ */
83
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
84
+
75
85
  pollInternalLogs?(eventName?: string): number;
76
86
 
77
87
  stopPollingInternalLogs?(): void;
@@ -80,4 +90,10 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
80
90
  * Return a new instance of the IProcessTelemetryContext for processing events
81
91
  */
82
92
  getProcessTelContext() : IProcessTelemetryContext;
93
+
94
+ /**
95
+ * Find and return the (first) plugin with the specified identifier if present
96
+ * @param pluginIdentifier
97
+ */
98
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
83
99
  }
@@ -1,5 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  // Licensed under the MIT License.
3
+ import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
3
4
  import { ITelemetryPlugin } from "./ITelemetryPlugin";
4
5
 
5
6
  "use strict";
@@ -26,10 +27,13 @@ export interface IChannelControls extends ITelemetryPlugin {
26
27
 
27
28
  /**
28
29
  * Flush to send data immediately; channel should default to sending data asynchronously
29
- * @param async: send data asynchronously when true
30
- * @param callBack: if specified, notify caller when send is complete
30
+ * @param async - send data asynchronously when true
31
+ * @param callBack - if specified, notify caller when send is complete, the channel should return true to indicate to the caller that it will be called.
32
+ * If the caller doesn't return true the caller should assume that it may never be called.
33
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
34
+ * @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
31
35
  */
32
- flush(async: boolean, callBack?: () => void): void;
36
+ flush(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void;
33
37
  }
34
38
 
35
39
  export const MinChannelPriorty: number = 100;
@@ -85,4 +85,9 @@ export interface IInstrumentCallDetails {
85
85
  * The error (exception) which occurred while executing the original method
86
86
  */
87
87
  err?: Error;
88
+
89
+ /**
90
+ * The Event object from (window.event) at the start of the original call
91
+ */
92
+ evt?: Event;
88
93
  }
@@ -6,9 +6,15 @@ import { IAppInsightsCore } from "./IAppInsightsCore";
6
6
  import { IDiagnosticLogger } from "./IDiagnosticLogger";
7
7
  import { IConfiguration } from "./IConfiguration";
8
8
  import { ITelemetryItem } from "./ITelemetryItem";
9
- import { IPlugin } from "./ITelemetryPlugin";
9
+ import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
10
10
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
11
11
 
12
+ export const enum GetExtCfgMergeType {
13
+ None = 0,
14
+ MergeDefaultOnly = 1,
15
+ MergeDefaultFromRootOrDefault = 2,
16
+ }
17
+
12
18
  /**
13
19
  * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
14
20
  * between multiple AppInsights instances
@@ -27,12 +33,12 @@ export interface IProcessTelemetryContext {
27
33
  /**
28
34
  * Gets the current core config instance
29
35
  */
30
- getCfg: ()=> IConfiguration;
36
+ getCfg: () => IConfiguration;
31
37
 
32
38
  /**
33
39
  * Gets the named extension config
34
40
  */
35
- getExtCfg: <T>(identifier: string, defaultValue?:T|any) => T;
41
+ getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
36
42
 
37
43
  /**
38
44
  * Gets the named config from either the named identifier extension or core config if neither exist then the
@@ -41,7 +47,7 @@ export interface IProcessTelemetryContext {
41
47
  * @param field The config field name
42
48
  * @param defaultValue The default value to return if no defined config exists
43
49
  */
44
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
50
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
45
51
 
46
52
  /**
47
53
  * Helper to allow plugins to check and possibly shortcut executing code only
@@ -57,7 +63,7 @@ export interface IProcessTelemetryContext {
57
63
  /**
58
64
  * Helper to set the next plugin proxy
59
65
  */
60
- setNext: (nextCtx:ITelemetryPluginChain) => void;
66
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
61
67
 
62
68
  /**
63
69
  * Call back for telemetry processing before it it is sent
@@ -65,6 +71,13 @@ export interface IProcessTelemetryContext {
65
71
  */
66
72
  processNext: (env: ITelemetryItem) => void;
67
73
 
74
+ /**
75
+ * Synchronously iterate over the context chain running the callback for each plugin, once
76
+ * every plugin has been executed via the callback, any associated onComplete will be called.
77
+ * @param callback - The function call for each plugin in the context chain
78
+ */
79
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
80
+
68
81
  /**
69
82
  * Create a new context using the core and config from the current instance
70
83
  * @param plugins - The execution order to process the plugins, if null or not supplied
@@ -73,4 +86,9 @@ export interface IProcessTelemetryContext {
73
86
  * order then the next plugin will be NOT set.
74
87
  */
75
88
  createNew: (plugins?:IPlugin[]|ITelemetryPluginChain, startAt?:IPlugin) => IProcessTelemetryContext;
89
+
90
+ /**
91
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
92
+ */
93
+ onComplete: (onComplete: () => void) => void;
76
94
  }
@@ -0,0 +1,16 @@
1
+ import { ITelemetryItem } from "./ITelemetryItem";
2
+
3
+ export declare type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
4
+
5
+ export interface ITelemetryInitializerHandler {
6
+ remove(): void;
7
+ }
8
+
9
+ export interface ITelemetryInitializerContainer {
10
+ /**
11
+ * Add a telemetry processor to decorate or drop telemetry events.
12
+ * @param telemetryInitializer - The Telemetry Initializer function
13
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
14
+ */
15
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
16
+ }
@@ -43,7 +43,7 @@ export interface IPlugin {
43
43
  * @param pluginChain - [Optional] specifies the current plugin chain which identifies the
44
44
  * set of plugins and the order they should be executed for the current request.
45
45
  */
46
- initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) => void;
46
+ initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) => void;
47
47
 
48
48
  /**
49
49
  * Returns a value that indicates whether the plugin has already been previously initialized.
@@ -3,31 +3,10 @@ import { BaseCore } from "./BaseCore";
3
3
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
4
4
  import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
5
5
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
- import { INotificationListener } from "../JavaScriptSDK.Interfaces/INotificationListener";
7
6
  import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
8
7
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
9
8
  export declare class AppInsightsCore extends BaseCore implements IAppInsightsCore {
10
9
  constructor();
11
10
  initialize(config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
12
11
  track(telemetryItem: ITelemetryItem): void;
13
- /**
14
- * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
15
- * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
16
- * called.
17
- * @param {INotificationListener} listener - An INotificationListener object.
18
- */
19
- addNotificationListener(listener: INotificationListener): void;
20
- /**
21
- * Removes all instances of the listener.
22
- * @param {INotificationListener} listener - INotificationListener to remove.
23
- */
24
- removeNotificationListener(listener: INotificationListener): void;
25
- /**
26
- * Periodically check logger.queue for
27
- */
28
- pollInternalLogs(eventName?: string): number;
29
- /**
30
- * Periodically check logger.queue for
31
- */
32
- stopPollingInternalLogs(): void;
33
12
  }
@@ -1,13 +1,15 @@
1
- import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
1
+ import { IAppInsightsCore, ILoadedPlugin } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
2
2
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
3
3
  import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
4
4
  import { IChannelControls } from "../JavaScriptSDK.Interfaces/IChannelControls";
5
5
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
6
  import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
7
+ import { INotificationListener } from "../JavaScriptSDK.Interfaces/INotificationListener";
7
8
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
8
9
  import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
9
10
  import { IPerfManager } from "../JavaScriptSDK.Interfaces/IPerfManager";
10
11
  import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
12
+ import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
11
13
  export declare class BaseCore implements IAppInsightsCore {
12
14
  static defaultConfig: IConfiguration;
13
15
  config: IConfiguration;
@@ -20,6 +22,18 @@ export declare class BaseCore implements IAppInsightsCore {
20
22
  track(telemetryItem: ITelemetryItem): void;
21
23
  getProcessTelContext(): IProcessTelemetryContext;
22
24
  getNotifyMgr(): INotificationManager;
25
+ /**
26
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
27
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
28
+ * called.
29
+ * @param {INotificationListener} listener - An INotificationListener object.
30
+ */
31
+ addNotificationListener(listener: INotificationListener): void;
32
+ /**
33
+ * Removes all instances of the listener.
34
+ * @param {INotificationListener} listener - INotificationListener to remove.
35
+ */
36
+ removeNotificationListener(listener: INotificationListener): void;
23
37
  /**
24
38
  * Get the current cookie manager for this instance
25
39
  */
@@ -32,5 +46,20 @@ export declare class BaseCore implements IAppInsightsCore {
32
46
  getPerfMgr(): IPerfManager;
33
47
  setPerfMgr(perfMgr: IPerfManager): void;
34
48
  eventCnt(): number;
49
+ /**
50
+ * Periodically check logger.queue for
51
+ */
52
+ pollInternalLogs(eventName?: string): number;
53
+ /**
54
+ * Periodically check logger.queue for
55
+ */
56
+ stopPollingInternalLogs(): void;
57
+ /**
58
+ * Add a telemetry processor to decorate or drop telemetry events.
59
+ * @param telemetryInitializer - The Telemetry Initializer function
60
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
61
+ */
62
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
63
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
35
64
  protected releaseQueue(): void;
36
65
  }
@@ -5,12 +5,20 @@ import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetr
5
5
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
6
  import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
7
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
8
+ import { IInstrumentHook } from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
8
9
  /**
9
10
  * BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins
10
11
  * can avoid implementation the same set of boiler plate code as well as provide a base
11
12
  * implementation so that new default implementations can be added without breaking all plugins.
12
13
  */
13
14
  export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
15
+ identifier: string;
16
+ version?: string;
17
+ /**
18
+ * Holds the core instance that was used during initialization
19
+ */
20
+ core: IAppInsightsCore;
21
+ priority: number;
14
22
  /**
15
23
  * Call back for telemetry processing before it it is sent
16
24
  * @param env - This is the current event being reported
@@ -32,13 +40,6 @@ export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
32
40
  * Returns whether the plugin has been initialized
33
41
  */
34
42
  isInitialized: () => boolean;
35
- identifier: string;
36
- version?: string;
37
- /**
38
- * Holds the core instance that was used during initialization
39
- */
40
- core: IAppInsightsCore;
41
- priority: number;
42
43
  /**
43
44
  * Helper to return the current IProcessTelemetryContext, if the passed argument exists this just
44
45
  * returns that value (helps with minification for callers), otherwise it will return the configured
@@ -50,11 +51,12 @@ export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
50
51
  * Internal helper to allow setting of the internal initialized setting for inherited instances and unit testing
51
52
  */
52
53
  protected setInitialized: (isInitialized: boolean) => void;
53
- /**
54
- * Internal helper to initialize the instance
55
- */
56
- private _baseTelInit;
57
54
  constructor();
58
55
  initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
59
56
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
57
+ /**
58
+ * Add this hook so that it is automatically removed during unloading
59
+ * @param hooks - The single hook or an array of IInstrumentHook objects
60
+ */
61
+ protected _addHook(hooks: IInstrumentHook | IInstrumentHook[]): void;
60
62
  }
@@ -1,21 +1,16 @@
1
+ import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
1
2
  import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
2
- import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
3
3
  import { IChannelControls } from "../JavaScriptSDK.Interfaces/IChannelControls";
4
- import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
4
+ import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
5
+ import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
5
6
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
6
- import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
7
- import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
8
- import { BaseTelemetryPlugin } from "./BaseTelemetryPlugin";
9
- export declare class ChannelController extends BaseTelemetryPlugin {
10
- identifier: string;
11
- priority: number;
12
- setNextPlugin: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
13
- constructor();
14
- processTelemetry(item: ITelemetryItem, itemCtx: IProcessTelemetryContext): void;
15
- getChannelControls(): IChannelControls[][];
16
- initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[]): void;
17
- /**
18
- * Static constructor, attempt to create accessors
19
- */
20
- private static _staticInit;
7
+ export declare const ChannelControllerPriority = 500;
8
+ export interface IChannelController extends IChannelControls {
9
+ flush(isAsync: boolean, callBack: (flushComplete?: boolean) => void, sendReason: SendRequestReason, cbTimeout?: number): void;
10
+ }
11
+ export interface _IInternalChannels {
12
+ queue: IChannelControls[];
13
+ chain: ITelemetryPluginChain;
21
14
  }
15
+ export declare function createChannelControllerPlugin(channelQueue: _IInternalChannels[], core: IAppInsightsCore): IChannelController;
16
+ export declare function createChannelQueues(channels: IChannelControls[][], extensions: IPlugin[], config: IConfiguration, core: IAppInsightsCore): _IInternalChannels[];
@@ -49,12 +49,6 @@ export declare function newGuid(): string;
49
49
  * https://caniuse.com/#search=performance.now
50
50
  */
51
51
  export declare function perfNow(): number;
52
- /**
53
- * Generate random base64 id string.
54
- * The default length is 22 which is 132-bits so almost the same as a GUID but as base64 (the previous default was 5)
55
- * @param maxLength - Optional value to specify the length of the id to be generated, defaults to 22
56
- */
57
- export declare function newId(maxLength?: number): string;
58
52
  /**
59
53
  * The strEndsWith() method determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
60
54
  * @param value - The value to check whether it ends with the search value.
@@ -43,7 +43,7 @@ export declare function normalizeJsName(name: string): string;
43
43
  * @param target The target object to find and process the keys
44
44
  * @param callbackfn The function to call with the details
45
45
  */
46
- export declare function objForEachKey(target: any, callbackfn: (name: string, value: any) => void): void;
46
+ export declare function objForEachKey<T = any>(target: T, callbackfn: (name: string, value: T[keyof T]) => void): void;
47
47
  /**
48
48
  * The strEndsWith() method determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
49
49
  * @param value - The value to check whether it ends with the search value.
@@ -83,7 +83,8 @@ export declare function strContains(value: string, search: string): boolean;
83
83
  */
84
84
  export declare function isDate(obj: any): obj is Date;
85
85
  /**
86
- * Check if an object is of type Array
86
+ * Check if an object is of type Array with optional generic T, the generic type is not validated
87
+ * and exists to help with TypeScript validation only.
87
88
  */
88
89
  export declare let isArray: <T = any>(obj: any) => obj is Array<T>;
89
90
  /**
@@ -136,7 +137,7 @@ export declare function _toISOStringPoly(date: Date): string;
136
137
  * @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
137
138
  * @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.
138
139
  */
139
- export declare function arrForEach<T>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void | number, thisArg?: any): void;
140
+ export declare function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void | number, thisArg?: any): void;
140
141
  /**
141
142
  * Returns the index of the first occurrence of a value in an array. This helper exists to avoid adding a polyfil for older browsers
142
143
  * that do not define Array.prototype.xxxx (eg. ES3 only, IE8) just in case any page checks for presence/absence of the prototype
@@ -232,9 +233,17 @@ export declare function throwError(message: string): never;
232
233
  * @param target - The target object to be assigned with the source properties and functions
233
234
  * @param source - The source object which will be assigned / called by setting / calling the targets proxies
234
235
  * @param chkSet - An optional callback to determine whether a specific property/function should be proxied
235
- * @memberof Initialization
236
236
  */
237
- export declare function proxyAssign(target: any, source: any, chkSet?: (name: string, isFunc?: boolean, source?: any, target?: any) => boolean): any;
237
+ export declare function proxyAssign<T, S>(target: T, source: S, chkSet?: (name: string, isFunc?: boolean, source?: S, target?: T) => boolean): T;
238
+ export declare function proxyFunctionAs<T, S>(target: T, name: string, source: S | (() => S), theFunc: (keyof S), overwriteTarget?: boolean): void;
239
+ /**
240
+ * Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.
241
+ *
242
+ * @param target - The target object to be assigned with the source properties and functions
243
+ * @param source - The source object which will be assigned / called by setting / calling the targets proxies
244
+ * @param functionsToProxy - An array of function names that will be proxied on the target
245
+ */
246
+ export declare function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget?: boolean): T;
238
247
  /**
239
248
  * Simpler helper to create a dynamic class that implements the interface and populates the values with the defaults.
240
249
  * Only instance properties (hasOwnProperty) values are copied from the defaults to the new instance
@@ -1,10 +1,41 @@
1
1
  import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
2
- import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
3
2
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
4
3
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
5
- import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
4
+ import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
6
5
  import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
6
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
7
+ import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
8
+ /**
9
+ * Creates a new Telemetry Item context with the current config, core and plugin execution chain
10
+ * @param plugins - The plugin instances that will be executed
11
+ * @param config - The current config
12
+ * @param core - The current core instance
13
+ */
14
+ export declare function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext;
15
+ /**
16
+ * Creates an execution chain from the array of plugins
17
+ * @param plugins - The array of plugins that will be executed in this order
18
+ * @param defItemCtx - The default execution context to use when no telemetry context is passed to processTelemetry(), this
19
+ * should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error
20
+ * reporting (hasRun) when errors occur.
21
+ */
22
+ export declare function createTelemetryProxyChain(plugins: IPlugin[], config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): ITelemetryPluginChain;
23
+ /**
24
+ * Create the processing telemetry proxy instance, the proxy is used to abstract the current plugin to allow monitoring and
25
+ * execution plugins while passing around the dynamic execution state (IProcessTelemetryContext), the proxy instance no longer
26
+ * contains any execution state and can be reused between requests (this was not the case for 2.7.2 and earlier with the
27
+ * TelemetryPluginChain class).
28
+ * @param plugin - The plugin instance to proxy
29
+ * @param config - The default execution context to use when no telemetry context is passed to processTelemetry(), this
30
+ * should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error
31
+ * reporting (hasRun) when errors occur.
32
+ * @returns
33
+ */
34
+ export declare function createTelemetryPluginProxy(plugin: ITelemetryPlugin, config: IConfiguration, core: IAppInsightsCore): ITelemetryPluginChain;
35
+ /**
36
+ * This class will be removed!
37
+ * @deprecated use createProcessTelemetryContext() instead
38
+ */
8
39
  export declare class ProcessTelemetryContext implements IProcessTelemetryContext {
9
40
  /**
10
41
  * Gets the current core config instance
@@ -41,15 +72,30 @@ export declare class ProcessTelemetryContext implements IProcessTelemetryContext
41
72
  * to later plugins (vs appending items to the telemetry item)
42
73
  */
43
74
  processNext: (env: ITelemetryItem) => void;
75
+ /**
76
+ * Synchronously iterate over the context chain running the callback for each plugin, once
77
+ * every plugin has been executed via the callback, any associated onComplete will be called.
78
+ * @param callback - The function call for each plugin in the context chain
79
+ */
80
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
81
+ /**
44
82
  /**
45
83
  * Create a new context using the core and config from the current instance
84
+ * @param plugins - The execution order to process the plugins, if null or not supplied
85
+ * then the current execution order will be copied.
86
+ * @param startAt - The plugin to start processing from, if missing from the execution
87
+ * order then the next plugin will be NOT set.
46
88
  */
47
89
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
90
+ /**
91
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
92
+ */
93
+ onComplete: (onComplete: () => void) => void;
48
94
  /**
49
95
  * Creates a new Telemetry Item context with the current config, core and plugin execution chain
50
96
  * @param plugins - The plugin instances that will be executed
51
97
  * @param config - The current config
52
98
  * @param core - The current core instance
53
99
  */
54
- constructor(plugins: IPlugin[] | ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin);
100
+ constructor(pluginChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin);
55
101
  }
@@ -21,3 +21,9 @@ export declare function mwcRandomSeed(value?: number): void;
21
21
  * @param signed - True to return a signed 32-bit number (-0x80000000..0x7FFFFFFF) otherwise an unsigned one (0x000000..0xFFFFFFFF)
22
22
  */
23
23
  export declare function mwcRandom32(signed?: boolean): number;
24
+ /**
25
+ * Generate random base64 id string.
26
+ * The default length is 22 which is 132-bits so almost the same as a GUID but as base64 (the previous default was 5)
27
+ * @param maxLength - Optional value to specify the length of the id to be generated, defaults to 22
28
+ */
29
+ export declare function newId(maxLength?: number): string;
@@ -1,5 +1,5 @@
1
1
  import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
2
- import { ProcessTelemetryContext } from "./ProcessTelemetryContext";
2
+ import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
3
3
  /**
4
4
  * Initialize the queue of plugins
5
5
  * @param plugins - The array of plugins to initialize and setting of the next plugin
@@ -7,5 +7,5 @@ import { ProcessTelemetryContext } from "./ProcessTelemetryContext";
7
7
  * @param core THe current core instance
8
8
  * @param extensions The extensions
9
9
  */
10
- export declare function initializePlugins(processContext: ProcessTelemetryContext, extensions: IPlugin[]): void;
11
- export declare function sortPlugins(plugins: IPlugin[]): IPlugin[];
10
+ export declare function initializePlugins(processContext: IProcessTelemetryContext, extensions: IPlugin[]): void;
11
+ export declare function sortPlugins<T = IPlugin>(plugins: T[]): T[];