@microsoft/applicationinsights-core-js 2.8.0-beta.2203-03 → 2.8.0-beta.2203-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 (100) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +129 -26
  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 +1667 -177
  7. package/dist/applicationinsights-core-js.api.md +62 -8
  8. package/dist/applicationinsights-core-js.d.ts +121 -7
  9. package/dist/applicationinsights-core-js.js +129 -26
  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 +124 -10
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +29 -10
  16. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  17. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +30 -2
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  19. package/dist-esm/JavaScriptSDK/ChannelController.js +14 -2
  20. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  21. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  22. package/dist-esm/JavaScriptSDK/CookieMgr.js +3 -2
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  24. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  25. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +1 -1
  26. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  27. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +14 -1
  28. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  29. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
  30. package/dist-esm/JavaScriptSDK/EventHelpers.js +18 -13
  31. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/HelperFuncs.js +2 -12
  33. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  35. package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
  36. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  37. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  38. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +56 -5
  39. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  40. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  41. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
  42. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +3 -2
  43. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
  44. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +3 -2
  45. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -1
  46. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  47. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  49. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
  50. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +8 -0
  51. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +1 -0
  52. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +8 -0
  70. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +1 -0
  71. package/dist-esm/applicationinsights-core-js.js +2 -2
  72. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/JavaScriptSDK/BaseCore.ts +44 -9
  75. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +54 -2
  76. package/src/JavaScriptSDK/ChannelController.ts +18 -1
  77. package/src/JavaScriptSDK/CookieMgr.ts +3 -1
  78. package/src/JavaScriptSDK/DiagnosticLogger.ts +14 -0
  79. package/src/JavaScriptSDK/EventHelpers.ts +18 -12
  80. package/src/JavaScriptSDK/HelperFuncs.ts +3 -1
  81. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +71 -8
  82. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +3 -1
  83. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +3 -1
  84. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +27 -0
  85. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +11 -6
  86. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +25 -2
  87. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +12 -1
  88. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +34 -0
  89. package/types/JavaScriptSDK/BaseCore.d.ts +11 -2
  90. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +17 -1
  91. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +10 -0
  92. package/types/JavaScriptSDK/EventHelpers.d.ts +4 -2
  93. package/types/JavaScriptSDK/HelperFuncs.d.ts +2 -1
  94. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +9 -1
  95. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +20 -0
  96. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +5 -0
  97. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +23 -2
  98. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +11 -1
  99. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +22 -0
  100. package/types/applicationinsights-core-js.d.ts +5 -2
@@ -6,16 +6,17 @@ import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
6
6
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
7
7
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
8
8
  import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
9
- import { GetExtCfgMergeType, IBaseProcessingContext, IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
9
+ import { GetExtCfgMergeType, IBaseProcessingContext, IProcessTelemetryContext, IProcessTelemetryUnloadContext, IProcessTelemetryUpdateContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
10
10
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
11
- import { safeGetLogger } from "./DiagnosticLogger";
11
+ import { safeGetLogger, _throwInternal } from "./DiagnosticLogger";
12
12
  import { arrForEach, isArray, isFunction, isNullOrUndefined, isObject, isUndefined, objExtend, objForEachKey, objFreeze, objKeys, proxyFunctions } from "./HelperFuncs";
13
13
  import { doPerf } from "./PerfManager";
14
14
  import { eLoggingSeverity, _eInternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
15
15
  import { dumpObj } from "./EnvUtils";
16
- import { strCore, strDisabled, strEmpty, strIsInitialized, strTeardown } from "./InternalConstants";
16
+ import { strCore, strDisabled, strEmpty, strIsInitialized, strTeardown, strUpdate } from "./InternalConstants";
17
17
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
18
18
  import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
19
+ import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
19
20
  import { _getPluginState } from "./TelemetryHelpers";
20
21
 
21
22
  const strTelemetryPluginChain = "TelemetryPluginChain";
@@ -123,10 +124,11 @@ function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain
123
124
  try {
124
125
  completeDetails.func.call(completeDetails.self, completeDetails.args);
125
126
  } catch (e) {
126
- core.logger.throwInternal(
127
- eLoggingSeverity.WARNING,
128
- _eInternalMessageId.PluginException,
129
- "Unexpected Exception during onComplete - " + dumpObj(e));
127
+ _throwInternal(
128
+ core.logger,
129
+ eLoggingSeverity.WARNING,
130
+ _eInternalMessageId.PluginException,
131
+ "Unexpected Exception during onComplete - " + dumpObj(e));
130
132
  }
131
133
  });
132
134
 
@@ -265,6 +267,38 @@ export function createProcessTelemetryUnloadContext(telemetryChain: ITelemetryPl
265
267
  return context;
266
268
  }
267
269
 
270
+ /**
271
+ * Creates a new Telemetry Item context with the current config, core and plugin execution chain for updating the configuration
272
+ * @param plugins - The plugin instances that will be executed
273
+ * @param config - The current config
274
+ * @param core - The current core instance
275
+ * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
276
+ */
277
+ export function createProcessTelemetryUpdateContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUpdateContext {
278
+ let internalContext: IInternalContext<IProcessTelemetryUpdateContext> = _createInternalContext<IProcessTelemetryUpdateContext>(telemetryChain, config, core, startAt);
279
+ let context = internalContext.ctx;
280
+
281
+ function _processNext(updateState: ITelemetryUpdateState) {
282
+ return context.iterate((plugin) => {
283
+ if (isFunction(plugin[strUpdate])) {
284
+ plugin[strUpdate](context, updateState);
285
+ }
286
+ });
287
+ }
288
+
289
+ function _createNew(plugins: IPlugin[] | ITelemetryPluginChain = null, startAt?: IPlugin) {
290
+ if (isArray(plugins)) {
291
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
292
+ }
293
+
294
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
295
+ }
296
+
297
+ context.processNext = _processNext;
298
+ context.createNew = _createNew;
299
+
300
+ return context;
301
+ }
268
302
 
269
303
  /**
270
304
  * Creates an execution chain from the array of plugins
@@ -340,6 +374,7 @@ export function createTelemetryPluginProxy(plugin: ITelemetryPlugin, config: ICo
340
374
  },
341
375
  processTelemetry: _processTelemetry,
342
376
  unload: _unloadPlugin,
377
+ update: _updatePlugin,
343
378
  _id: chainId,
344
379
  _setNext: (nextPlugin: IInternalTelemetryPluginChain) => {
345
380
  nextProxy = nextPlugin;
@@ -405,7 +440,8 @@ export function createTelemetryPluginProxy(plugin: ITelemetryPlugin, config: ICo
405
440
 
406
441
  // Either we have no next plugin or the current one did not attempt to call the next plugin
407
442
  // Which means the current one is the root of the failure so log/report this failure
408
- itemCtx.diagLog().throwInternal(
443
+ _throwInternal(
444
+ itemCtx.diagLog(),
409
445
  eLoggingSeverity.CRITICAL,
410
446
  _eInternalMessageId.PluginException,
411
447
  "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
@@ -482,6 +518,33 @@ export function createTelemetryPluginProxy(plugin: ITelemetryPlugin, config: ICo
482
518
  }
483
519
  }
484
520
 
521
+ function _updatePlugin(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) {
522
+
523
+ function _callUpdate() {
524
+ // Setting default of hasRun as false so the proxyProcessFn() is called as teardown() doesn't have to exist or call unloadNext().
525
+ let hasRun = false;
526
+ if (plugin) {
527
+ let pluginState = _getPluginState(plugin);
528
+ let pluginCore = plugin[strCore] || pluginState.core;
529
+
530
+ // Only update the plugin if it was initialized by the current core (i.e. It's not a shared plugin)
531
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
532
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
533
+ // plugin told us that it was going to (or has) call unloadCtx.processNext()
534
+ hasRun = true;
535
+ }
536
+ }
537
+ }
538
+
539
+ return hasRun;
540
+ }
541
+
542
+ if (!_processChain(updateCtx, _callUpdate, "update", () => {}, false)) {
543
+ // Only called if we hasRun was not true
544
+ updateCtx.processNext(updateState);
545
+ }
546
+ }
547
+
485
548
  return objFreeze(proxyChain);
486
549
  }
487
550
 
@@ -7,6 +7,7 @@ import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTe
7
7
  import { ITelemetryInitializerContainer, ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
8
8
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
9
9
  import { BaseTelemetryPlugin } from "./BaseTelemetryPlugin";
10
+ import { _throwInternal } from "./DiagnosticLogger";
10
11
  import { dumpObj } from "./EnvUtils";
11
12
  import { arrForEach, getExceptionName } from "./HelperFuncs";
12
13
  import { strDoTeardown } from "./InternalConstants";
@@ -68,7 +69,8 @@ export class TelemetryInitializerPlugin extends BaseTelemetryPlugin implements I
68
69
  } catch (e) {
69
70
  // log error but dont stop executing rest of the telemetry initializers
70
71
  // doNotSendItem = true;
71
- itemCtx.diagLog().throwInternal(
72
+ _throwInternal(
73
+ itemCtx.diagLog(),
72
74
  eLoggingSeverity.CRITICAL,
73
75
  _eInternalMessageId.TelemetryInitializerFailed,
74
76
  "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e),
@@ -4,6 +4,7 @@
4
4
  import { eLoggingSeverity, _eInternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
5
5
  import { IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
6
6
  import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
7
+ import { _throwInternal } from "./DiagnosticLogger";
7
8
  import { dumpObj } from "./EnvUtils";
8
9
  import { arrForEach } from "./HelperFuncs";
9
10
 
@@ -28,7 +29,8 @@ export function createUnloadHandlerContainer() {
28
29
  try {
29
30
  handler(unloadCtx, unloadState);
30
31
  } catch (e) {
31
- unloadCtx.diagLog().throwInternal(
32
+ _throwInternal(
33
+ unloadCtx.diagLog(),
32
34
  eLoggingSeverity.WARNING,
33
35
  _eInternalMessageId.PluginException,
34
36
  "Unexpected error calling unload handler - " + dumpObj(e));
@@ -0,0 +1,27 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ /**
5
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
6
+ */
7
+ export const enum TelemetryUpdateReason {
8
+ /**
9
+ * Unknown.
10
+ */
11
+ Unknown = 0,
12
+
13
+ /**
14
+ * The configuration has ben updated or changed
15
+ */
16
+ //ConfigurationChanged = 0x01,
17
+
18
+ /**
19
+ * One or more plugins have been added
20
+ */
21
+ PluginAdded = 0x10,
22
+
23
+ /**
24
+ * One or more plugins have been removed
25
+ */
26
+ PluginRemoved = 0x20,
27
+ }
@@ -12,6 +12,11 @@ export type InstrumentorHooksCallback = (funcArgs:IInstrumentCallDetails, ...org
12
12
  * You must always supply the error callback
13
13
  */
14
14
  export interface IInstrumentHooksCallbacks {
15
+ /**
16
+ * [Optional] Namespace details (same as the namespace used for events), useful for debugging and testing to
17
+ * identify the source of the instrumented hooks
18
+ */
19
+ ns?: string | string[];
15
20
 
16
21
  /**
17
22
  * The hook callback to call before the original function is called
@@ -40,20 +45,20 @@ export interface IInstrumentHooksCallbacks {
40
45
  */
41
46
  export interface IInstrumentHook {
42
47
  /** Unique Id for this callback on the hooked method */
43
- id:number;
48
+ id: number;
44
49
 
45
50
  /** Holds the callbacks */
46
- cbks:IInstrumentHooksCallbacks;
51
+ cbks: IInstrumentHooksCallbacks;
47
52
 
48
53
  /** Remove this hook from the function */
49
54
  rm: () => void;
50
55
  }
51
56
 
52
57
  export interface IInstrumentHooks {
53
- i:number; // Used to create unique ids
54
- n:string; // Function name
55
- f:any; // Original Function
56
- h:IInstrumentHook[]; // The hook
58
+ i: number; // Used to create unique ids
59
+ n: string; // Function name
60
+ f: any; // Original Function
61
+ h: IInstrumentHook[]; // The hook
57
62
  }
58
63
 
59
64
  export interface IInstrumentCallDetails {
@@ -9,6 +9,7 @@ import { ITelemetryItem } from "./ITelemetryItem";
9
9
  import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
10
10
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
11
11
  import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
12
+ import { ITelemetryUpdateState } from "./ITelemetryUpdateState";
12
13
 
13
14
  export const enum GetExtCfgMergeType {
14
15
  None = 0,
@@ -110,8 +111,8 @@ export interface IProcessTelemetryContext extends IBaseProcessingContext {
110
111
  }
111
112
 
112
113
  /**
113
- * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
114
- * between multiple AppInsights instances
114
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
115
+ * or the SDK is being unloaded.
115
116
  */
116
117
  export interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
117
118
 
@@ -131,3 +132,25 @@ export interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
131
132
  */
132
133
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
133
134
  }
135
+
136
+ /**
137
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
138
+ * for when plugins are added, removed or the configuration was changed.
139
+ */
140
+ export interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
141
+ /**
142
+ * This Plugin has finished unloading, so unload the next one
143
+ * @param updateState - The update State
144
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
145
+ */
146
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
147
+
148
+ /**
149
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
150
+ * @param plugins - The execution order to process the plugins, if null or not supplied
151
+ * then the current execution order will be copied.
152
+ * @param startAt - The plugin to start processing from, if missing from the execution
153
+ * order then the next plugin will be NOT set.
154
+ */
155
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
156
+ }
@@ -5,9 +5,10 @@
5
5
  import { ITelemetryItem } from "./ITelemetryItem";
6
6
  import { IConfiguration } from "./IConfiguration";
7
7
  import { IAppInsightsCore } from "./IAppInsightsCore";
8
- import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
8
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext, IProcessTelemetryUpdateContext } from "./IProcessTelemetryContext";
9
9
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
10
10
  import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
11
+ import { ITelemetryUpdateState } from "./ITelemetryUpdateState";
11
12
 
12
13
  export interface ITelemetryProcessor {
13
14
  /**
@@ -18,6 +19,16 @@ export interface ITelemetryProcessor {
18
19
  * to later plugins (vs appending items to the telemetry item)
19
20
  */
20
21
  processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
22
+
23
+ /**
24
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
25
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
26
+ * the configuration has bee updated.
27
+ * @param updateCtx - This is the context that should be used during updating.
28
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
29
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
30
+ */
31
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
21
32
  }
22
33
 
23
34
  /**
@@ -0,0 +1,34 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { TelemetryUpdateReason } from "../JavaScriptSDK.Enums/TelemetryUpdateReason";
5
+ import { IConfiguration } from "./IConfiguration";
6
+ import { IPlugin } from "./ITelemetryPlugin";
7
+
8
+ export interface ITelemetryUpdateState {
9
+
10
+ /**
11
+ * Identifies the reason for the update notification, this is a bitwise numeric value
12
+ */
13
+ reason: TelemetryUpdateReason;
14
+
15
+ /**
16
+ * If this is a configuration update this was the previous configuration that was used
17
+ */
18
+ //prvCfg?: IConfiguration,
19
+
20
+ /**
21
+ * If this is a configuration update is the new configuration that is being used
22
+ */
23
+ //newCfg?: IConfiguration,
24
+
25
+ /**
26
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
27
+ */
28
+ added?: IPlugin[];
29
+
30
+ /**
31
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
32
+ */
33
+ removed?: IPlugin[]
34
+ }
@@ -6,11 +6,13 @@ import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
6
  import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
7
7
  import { INotificationListener } from "../JavaScriptSDK.Interfaces/INotificationListener";
8
8
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
9
- import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
9
+ import { IProcessTelemetryContext, IProcessTelemetryUpdateContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
10
10
  import { IPerfManager } from "../JavaScriptSDK.Interfaces/IPerfManager";
11
11
  import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
12
12
  import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
13
13
  import { UnloadHandler } from "./UnloadHandlerContainer";
14
+ import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
15
+ import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
14
16
  export declare class BaseCore implements IAppInsightsCore {
15
17
  static defaultConfig: IConfiguration;
16
18
  config: IConfiguration;
@@ -69,7 +71,7 @@ export declare class BaseCore implements IAppInsightsCore {
69
71
  * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
70
72
  * to successfully remove any global references or they may just be completing the unload process asynchronously.
71
73
  */
72
- unload(isAsync?: boolean, unloadComplete?: () => void): void;
74
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
73
75
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
74
76
  addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
75
77
  /**
@@ -82,4 +84,11 @@ export declare class BaseCore implements IAppInsightsCore {
82
84
  */
83
85
  addUnloadCb(handler: UnloadHandler): void;
84
86
  protected releaseQueue(): void;
87
+ /**
88
+ * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
89
+ * @param updateCtx - The plugin update context
90
+ * @param updateState - The Update State
91
+ * @returns boolean - True means the extension class will call updateState otherwise the Core will
92
+ */
93
+ protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
85
94
  }
@@ -3,11 +3,12 @@ import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
3
3
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
4
4
  import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
5
5
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
- import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
6
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext, IProcessTelemetryUpdateContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
7
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
8
8
  import { UnloadHandler } from "./UnloadHandlerContainer";
9
9
  import { IInstrumentHook } from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
10
10
  import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
11
+ import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
11
12
  /**
12
13
  * BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins
13
14
  * can avoid implementation the same set of boiler plate code as well as provide a base
@@ -62,6 +63,14 @@ export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
62
63
  * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
63
64
  */
64
65
  protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
66
+ /**
67
+ * Extension hook to allow implementations to perform some additional update operations before the BaseTelemetryPlugin finishes it's removal
68
+ * @param updateCtx - This is the context that should be used during updating.
69
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
70
+ * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async update operations.
71
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
72
+ */
73
+ protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
65
74
  constructor();
66
75
  initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
67
76
  /**
@@ -74,6 +83,13 @@ export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
74
83
  */
75
84
  teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
76
85
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
86
+ /**
87
+ * The the plugin should re-evaluate configuration and update any cached configuration settings.
88
+ * @param updateCtx - This is the context that should be used during updating.
89
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
90
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
91
+ */
92
+ update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
77
93
  /**
78
94
  * Add an unload handler that will be called when the SDK is being unloaded
79
95
  * @param handler - the handler
@@ -63,3 +63,13 @@ export declare class DiagnosticLogger implements IDiagnosticLogger {
63
63
  */
64
64
  logInternalMessage(severity: LoggingSeverity, message: _InternalLogMessage): void;
65
65
  }
66
+ /**
67
+ * This is a helper method which will call throwInternal on the passed logger, will throw exceptions in
68
+ * debug mode or attempt to log the error as a console warning. This helper is provided mostly to better
69
+ * support minification as logger.throwInternal() will not compress the publish "throwInternal" used throughout
70
+ * the code.
71
+ * @param logger - The Diagnostic Logger instance to use.
72
+ * @param severity {LoggingSeverity} - The severity of the log message
73
+ * @param message {_InternalLogMessage} - The log message.
74
+ */
75
+ export declare function _throwInternal(logger: IDiagnosticLogger, severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
@@ -6,9 +6,11 @@ export interface _IRegisteredEvents {
6
6
  * Get all of the registered events on the target object, this is primarily used for testing cleanup but may also be used by
7
7
  * applications to remove their own events
8
8
  * @param target - The EventTarget that has registered events
9
- * @param evtName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)
9
+ * @param eventName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)
10
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
11
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
10
12
  */
11
- export declare function __getRegisteredEvents(target: any, evtName?: string): _IRegisteredEvents[];
13
+ export declare function __getRegisteredEvents(target: any, eventName?: string, evtNamespace?: string | string[]): _IRegisteredEvents[];
12
14
  export declare function mergeEvtNamespace(theNamespace: string, namespaces: string | string[]): string | string[];
13
15
  /**
14
16
  * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
@@ -259,4 +259,5 @@ export declare function optimizeObject<T>(theObject: T): T;
259
259
  * @param obj5 - object to merge.
260
260
  * @returns The extended first object.
261
261
  */
262
- export declare function objExtend<T1, T2, T3, T4, T5, T6>(obj?: boolean | T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6;
262
+ export declare function objExtend<T2, T3, T4, T5, T6>(deepExtend?: boolean, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T2 & T3 & T4 & T5 & T6;
263
+ export declare function objExtend<T1, T2, T3, T4, T5, T6>(obj1?: T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6;
@@ -2,7 +2,7 @@ import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
2
2
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
3
3
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
4
4
  import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
5
- import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
5
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext, IProcessTelemetryUpdateContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
6
6
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
7
7
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
8
8
  /**
@@ -21,6 +21,14 @@ export declare function createProcessTelemetryContext(telemetryChain: ITelemetry
21
21
  * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
22
22
  */
23
23
  export declare function createProcessTelemetryUnloadContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUnloadContext;
24
+ /**
25
+ * Creates a new Telemetry Item context with the current config, core and plugin execution chain for updating the configuration
26
+ * @param plugins - The plugin instances that will be executed
27
+ * @param config - The current config
28
+ * @param core - The current core instance
29
+ * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
30
+ */
31
+ export declare function createProcessTelemetryUpdateContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUpdateContext;
24
32
  /**
25
33
  * Creates an execution chain from the array of plugins
26
34
  * @param plugins - The array of plugins that will be executed in this order
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
3
+ */
4
+ export declare const enum TelemetryUpdateReason {
5
+ /**
6
+ * Unknown.
7
+ */
8
+ Unknown = 0,
9
+ /**
10
+ * The configuration has ben updated or changed
11
+ */
12
+ /**
13
+ * One or more plugins have been added
14
+ */
15
+ PluginAdded = 16,
16
+ /**
17
+ * One or more plugins have been removed
18
+ */
19
+ PluginRemoved = 32
20
+ }
@@ -8,6 +8,11 @@ export declare type InstrumentorHooksCallback = (funcArgs: IInstrumentCallDetail
8
8
  * You must always supply the error callback
9
9
  */
10
10
  export interface IInstrumentHooksCallbacks {
11
+ /**
12
+ * [Optional] Namespace details (same as the namespace used for events), useful for debugging and testing to
13
+ * identify the source of the instrumented hooks
14
+ */
15
+ ns?: string | string[];
11
16
  /**
12
17
  * The hook callback to call before the original function is called
13
18
  */
@@ -5,6 +5,7 @@ import { ITelemetryItem } from "./ITelemetryItem";
5
5
  import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
6
6
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
7
7
  import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
8
+ import { ITelemetryUpdateState } from "./ITelemetryUpdateState";
8
9
  export declare const enum GetExtCfgMergeType {
9
10
  None = 0,
10
11
  MergeDefaultOnly = 1,
@@ -91,8 +92,8 @@ export interface IProcessTelemetryContext extends IBaseProcessingContext {
91
92
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
92
93
  }
93
94
  /**
94
- * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
95
- * between multiple AppInsights instances
95
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
96
+ * or the SDK is being unloaded.
96
97
  */
97
98
  export interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
98
99
  /**
@@ -110,3 +111,23 @@ export interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
110
111
  */
111
112
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
112
113
  }
114
+ /**
115
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
116
+ * for when plugins are added, removed or the configuration was changed.
117
+ */
118
+ export interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
119
+ /**
120
+ * This Plugin has finished unloading, so unload the next one
121
+ * @param updateState - The update State
122
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
123
+ */
124
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
125
+ /**
126
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
127
+ * @param plugins - The execution order to process the plugins, if null or not supplied
128
+ * then the current execution order will be copied.
129
+ * @param startAt - The plugin to start processing from, if missing from the execution
130
+ * order then the next plugin will be NOT set.
131
+ */
132
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
133
+ }
@@ -1,9 +1,10 @@
1
1
  import { ITelemetryItem } from "./ITelemetryItem";
2
2
  import { IConfiguration } from "./IConfiguration";
3
3
  import { IAppInsightsCore } from "./IAppInsightsCore";
4
- import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
4
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext, IProcessTelemetryUpdateContext } from "./IProcessTelemetryContext";
5
5
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
6
6
  import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
7
+ import { ITelemetryUpdateState } from "./ITelemetryUpdateState";
7
8
  export interface ITelemetryProcessor {
8
9
  /**
9
10
  * Call back for telemetry processing before it it is sent
@@ -13,6 +14,15 @@ export interface ITelemetryProcessor {
13
14
  * to later plugins (vs appending items to the telemetry item)
14
15
  */
15
16
  processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
17
+ /**
18
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
19
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
20
+ * the configuration has bee updated.
21
+ * @param updateCtx - This is the context that should be used during updating.
22
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
23
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
24
+ */
25
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
16
26
  }
17
27
  /**
18
28
  * Configuration provided to SDK core
@@ -0,0 +1,22 @@
1
+ import { TelemetryUpdateReason } from "../JavaScriptSDK.Enums/TelemetryUpdateReason";
2
+ import { IPlugin } from "./ITelemetryPlugin";
3
+ export interface ITelemetryUpdateState {
4
+ /**
5
+ * Identifies the reason for the update notification, this is a bitwise numeric value
6
+ */
7
+ reason: TelemetryUpdateReason;
8
+ /**
9
+ * If this is a configuration update this was the previous configuration that was used
10
+ */
11
+ /**
12
+ * If this is a configuration update is the new configuration that is being used
13
+ */
14
+ /**
15
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
16
+ */
17
+ added?: IPlugin[];
18
+ /**
19
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
20
+ */
21
+ removed?: IPlugin[];
22
+ }