@microsoft/applicationinsights-web-basic 3.0.0-beta.2210-01 → 3.0.0-beta.2210-03

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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft.ApplicationInsights, 3.0.0-beta.2210-01
2
+ * Microsoft.ApplicationInsights, 3.0.0-beta.2210-03
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -12,81 +12,7 @@ declare namespace ApplicationInsights {
12
12
  import { isNullOrUndefined } from '@nevware21/ts-utils';
13
13
  import { throwError } from '@nevware21/ts-utils';
14
14
 
15
- class AppInsightsCore extends BaseCore implements IAppInsightsCore {
16
- constructor();
17
- initialize(config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
18
- track(telemetryItem: ITelemetryItem): void;
19
- }
20
-
21
- /**
22
- * @export
23
- * @class ApplicationInsights
24
- */
25
- class ApplicationInsights {
26
- config: IConfiguration & IConfig;
27
- /**
28
- * Creates an instance of ApplicationInsights.
29
- * @param {IConfiguration & IConfig} config
30
- * @memberof ApplicationInsights
31
- */
32
- constructor(config: IConfiguration & IConfig);
33
- /**
34
- * Initialize this instance of ApplicationInsights
35
- *
36
- * @memberof ApplicationInsights
37
- */
38
- initialize(): void;
39
- /**
40
- * Send a manually constructed custom event
41
- *
42
- * @param {ITelemetryItem} item
43
- * @memberof ApplicationInsights
44
- */
45
- track(item: ITelemetryItem): void;
46
- /**
47
- * Immediately send all batched telemetry
48
- * @param {boolean} [async=true]
49
- * @memberof ApplicationInsights
50
- */
51
- flush(async?: boolean): void;
52
- pollInternalLogs(): void;
53
- stopPollingInternalLogs(): void;
54
- getSKUDefaults(): void;
55
- /**
56
- * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
57
- * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
58
- * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
59
- * approach is to create a new instance and initialize that instance.
60
- * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
61
- * to successfully remove any global references or they may just be completing the unload process asynchronously.
62
- */
63
- unload(isAsync?: boolean, unloadComplete?: () => void): void;
64
- /**
65
- * Find and return the (first) plugin with the specified identifier if present
66
- * @param pluginIdentifier
67
- */
68
- getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
69
- /**
70
- * Add a new plugin to the installation
71
- * @param plugin - The new plugin to add
72
- * @param replaceExisting - should any existing plugin be replaced
73
- * @param doAsync - Should the add be performed asynchronously
74
- */
75
- addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
76
- /**
77
- * Returns the unique event namespace that should be used
78
- */
79
- evtNamespace(): string;
80
- /**
81
- * Add an unload handler that will be called when the SDK is being unloaded
82
- * @param handler - the handler
83
- */
84
- addUnloadCb(handler: UnloadHandler): void;
85
- }
86
-
87
- export { arrForEach }
88
-
89
- class BaseCore implements IAppInsightsCore {
15
+ class AppInsightsCore implements IAppInsightsCore {
90
16
  static defaultConfig: IConfiguration;
91
17
  config: IConfiguration;
92
18
  logger: IDiagnosticLogger;
@@ -102,12 +28,12 @@ declare namespace ApplicationInsights {
102
28
  * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
103
29
  * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
104
30
  * called.
105
- * @param {INotificationListener} listener - An INotificationListener object.
31
+ * @param listener - An INotificationListener object.
106
32
  */
107
33
  addNotificationListener(listener: INotificationListener): void;
108
34
  /**
109
35
  * Removes all instances of the listener.
110
- * @param {INotificationListener} listener - INotificationListener to remove.
36
+ * @param listener - INotificationListener to remove.
111
37
  */
112
38
  removeNotificationListener(listener: INotificationListener): void;
113
39
  /**
@@ -135,7 +61,7 @@ declare namespace ApplicationInsights {
135
61
  * @param telemetryInitializer - The Telemetry Initializer function
136
62
  * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
137
63
  */
138
- addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
64
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler;
139
65
  /**
140
66
  * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
141
67
  * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
@@ -157,6 +83,12 @@ declare namespace ApplicationInsights {
157
83
  * @param addCb - [Optional] callback to call after the plugin has been added
158
84
  */
159
85
  addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
86
+ /**
87
+ * Update the configuration used and broadcast the changes to all loaded plugins
88
+ * @param newConfig - The new configuration is apply
89
+ * @param mergeExisting - Should the new configuration merge with the existing or just replace it. Default is to true.
90
+ */
91
+ updateCfg<T extends IConfiguration = IConfiguration>(newConfig: T, mergeExisting?: boolean): void;
160
92
  /**
161
93
  * Returns the unique event namespace that should be used
162
94
  */
@@ -184,6 +116,18 @@ declare namespace ApplicationInsights {
184
116
  * Sets the current distributed trace context for this instance if available
185
117
  */
186
118
  setTraceCtx(newTracectx: IDistributedTraceContext): void;
119
+ /**
120
+ * Add this hook so that it is automatically removed during unloading
121
+ * @param hooks - The single hook or an array of IInstrumentHook objects
122
+ */
123
+ addUnloadHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>): void;
124
+ /**
125
+ * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
126
+ * handler will be recalled.
127
+ * @param handler
128
+ * @returns A watcher handler instance that can be used to remove itself when being unloaded
129
+ */
130
+ onCfgChange<T extends IConfiguration = IConfiguration>(handler: WatcherFunction<T>): IUnloadHook;
187
131
  protected releaseQueue(): void;
188
132
  /**
189
133
  * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
@@ -194,6 +138,74 @@ declare namespace ApplicationInsights {
194
138
  protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
195
139
  }
196
140
 
141
+ /**
142
+ * @export
143
+ * @class ApplicationInsights
144
+ */
145
+ class ApplicationInsights {
146
+ readonly config: IConfiguration & IConfig;
147
+ /**
148
+ * Creates an instance of ApplicationInsights.
149
+ * @param config
150
+ * @memberof ApplicationInsights
151
+ */
152
+ constructor(config: IConfiguration & IConfig);
153
+ /**
154
+ * Initialize this instance of ApplicationInsights
155
+ *
156
+ * @memberof ApplicationInsights
157
+ */
158
+ initialize(): void;
159
+ /**
160
+ * Send a manually constructed custom event
161
+ *
162
+ * @param item
163
+ * @memberof ApplicationInsights
164
+ */
165
+ track(item: ITelemetryItem): void;
166
+ /**
167
+ * Immediately send all batched telemetry
168
+ * @param [async=true]
169
+ * @memberof ApplicationInsights
170
+ */
171
+ flush(async?: boolean): void;
172
+ pollInternalLogs(): void;
173
+ stopPollingInternalLogs(): void;
174
+ getSKUDefaults(): void;
175
+ /**
176
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
177
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
178
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
179
+ * approach is to create a new instance and initialize that instance.
180
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
181
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
182
+ */
183
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
184
+ /**
185
+ * Find and return the (first) plugin with the specified identifier if present
186
+ * @param pluginIdentifier
187
+ */
188
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
189
+ /**
190
+ * Add a new plugin to the installation
191
+ * @param plugin - The new plugin to add
192
+ * @param replaceExisting - should any existing plugin be replaced
193
+ * @param doAsync - Should the add be performed asynchronously
194
+ */
195
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
196
+ /**
197
+ * Returns the unique event namespace that should be used
198
+ */
199
+ evtNamespace(): string;
200
+ /**
201
+ * Add an unload handler that will be called when the SDK is being unloaded
202
+ * @param handler - the handler
203
+ */
204
+ addUnloadCb(handler: UnloadHandler): void;
205
+ }
206
+
207
+ export { arrForEach }
208
+
197
209
  /**
198
210
  * BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins
199
211
  * can avoid implementation the same set of boiler plate code as well as provide a base
@@ -284,7 +296,7 @@ declare namespace ApplicationInsights {
284
296
  * Add this hook so that it is automatically removed during unloading
285
297
  * @param hooks - The single hook or an array of IInstrumentHook objects
286
298
  */
287
- protected _addHook(hooks: IInstrumentHook | IInstrumentHook[]): void;
299
+ protected _addHook(hooks: IUnloadHook | IUnloadHook[] | ILegacyUnloadHook | ILegacyUnloadHook[]): void;
288
300
  }
289
301
 
290
302
  const DistributedTracingModes: EnumValue<typeof eDistributedTracingModes>;
@@ -389,10 +401,16 @@ declare namespace ApplicationInsights {
389
401
  TrackPageActionEventFailed = 103,
390
402
  FailedAddingCustomDefinedRequestContext = 104,
391
403
  InMemoryStorageBufferFull = 105,
392
- InstrumentationKeyDeprecation = 106
404
+ InstrumentationKeyDeprecation = 106,
405
+ ConfigWatcherException = 107,
406
+ DynamicConfigException = 108
393
407
  }
394
408
 
395
409
  const enum eLoggingSeverity {
410
+ /**
411
+ * No Logging will be enabled
412
+ */
413
+ DISABLED = 0,
396
414
  /**
397
415
  * Error will be sent as internal telemetry
398
416
  */
@@ -416,12 +434,6 @@ declare namespace ApplicationInsights {
416
434
  Critical = 4
417
435
  }
418
436
 
419
- const enum GetExtCfgMergeType {
420
- None = 0,
421
- MergeDefaultOnly = 1,
422
- MergeDefaultFromRootOrDefault = 2
423
- }
424
-
425
437
  interface IAppInsightsCore extends IPerfManagerProvider {
426
438
  config: IConfiguration;
427
439
  logger: IDiagnosticLogger;
@@ -449,12 +461,12 @@ declare namespace ApplicationInsights {
449
461
  * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
450
462
  * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
451
463
  * called.
452
- * @param {INotificationListener} listener - An INotificationListener object.
464
+ * @param listener - An INotificationListener object.
453
465
  */
454
466
  addNotificationListener?(listener: INotificationListener): void;
455
467
  /**
456
468
  * Removes all instances of the listener.
457
- * @param {INotificationListener} listener - INotificationListener to remove.
469
+ * @param listener - INotificationListener to remove.
458
470
  */
459
471
  removeNotificationListener?(listener: INotificationListener): void;
460
472
  /**
@@ -462,7 +474,7 @@ declare namespace ApplicationInsights {
462
474
  * @param telemetryInitializer - The Telemetry Initializer function
463
475
  * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
464
476
  */
465
- addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
477
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler;
466
478
  pollInternalLogs?(eventName?: string): number;
467
479
  stopPollingInternalLogs?(): void;
468
480
  /**
@@ -494,6 +506,14 @@ declare namespace ApplicationInsights {
494
506
  * @param addCb - [Optional] callback to call after the plugin has been added
495
507
  */
496
508
  addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
509
+ /**
510
+ * Update the configuration used and broadcast the changes to all loaded plugins, this does NOT support updating, adding or removing
511
+ * any the plugins (extensions or channels). It will notify each plugin (if supported) that the configuration has changed but it will
512
+ * not remove or add any new plugins, you need to call addPlugin or getPlugin(identifier).remove();
513
+ * @param newConfig - The new configuration is apply
514
+ * @param mergeExisting - Should the new configuration merge with the existing or just replace it. Default is to merge.
515
+ */
516
+ updateCfg<T extends IConfiguration = IConfiguration>(newConfig: T, mergeExisting?: boolean): void;
497
517
  /**
498
518
  * Returns the unique event namespace that should be used when registering events
499
519
  */
@@ -503,6 +523,11 @@ declare namespace ApplicationInsights {
503
523
  * @param handler - the handler
504
524
  */
505
525
  addUnloadCb(handler: UnloadHandler): void;
526
+ /**
527
+ * Add this hook so that it is automatically removed during unloading
528
+ * @param hooks - The single hook or an array of IInstrumentHook objects
529
+ */
530
+ addUnloadHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>): void;
506
531
  /**
507
532
  * Flush and send any batched / cached data immediately
508
533
  * @param async - send data asynchronously when true (defaults to true)
@@ -522,6 +547,13 @@ declare namespace ApplicationInsights {
522
547
  * Sets the current distributed trace context for this instance if available
523
548
  */
524
549
  setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
550
+ /**
551
+ * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
552
+ * handler will be recalled.
553
+ * @param handler
554
+ * @returns A watcher handler instance that can be used to remove itself when being unloaded
555
+ */
556
+ onCfgChange<T extends IConfiguration = IConfiguration>(handler: WatcherFunction<T>): IUnloadHook;
525
557
  }
526
558
 
527
559
  /**
@@ -621,13 +653,13 @@ declare namespace ApplicationInsights {
621
653
  /**
622
654
  * Gets the named extension config
623
655
  */
624
- getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
656
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
625
657
  /**
626
658
  * Gets the named config from either the named identifier extension or core config if neither exist then the
627
659
  * default value is returned
628
- * @param identifier The named extension identifier
629
- * @param field The config field name
630
- * @param defaultValue The default value to return if no defined config exists
660
+ * @param identifier - The named extension identifier
661
+ * @param field - The config field name
662
+ * @param defaultValue - The default value to return if no defined config exists
631
663
  */
632
664
  getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
633
665
  /**
@@ -1019,6 +1051,51 @@ declare namespace ApplicationInsights {
1019
1051
  addIntEndpoints?: boolean;
1020
1052
  }
1021
1053
 
1054
+ /**
1055
+ * The type to identify whether the default value should be applied in preference to the provided value.
1056
+ */
1057
+ type IConfigCheckFn<V> = (value: V) => boolean;
1058
+
1059
+ /**
1060
+ * The default values with a check function
1061
+ */
1062
+ interface IConfigDefaultCheck<T, V, C extends IConfiguration = IConfiguration> {
1063
+ /**
1064
+ * Callback function to check if the user-supplied value is valid, if not the default will be applied
1065
+ */
1066
+ isVal?: IConfigCheckFn<V>;
1067
+ /**
1068
+ * Optional function to allow converting and setting of the default value
1069
+ */
1070
+ set?: IConfigSetFn<T, V>;
1071
+ /**
1072
+ * The default value to apply if the user-supplied value is not valid
1073
+ */
1074
+ v?: V;
1075
+ /**
1076
+ * The default fallback key if the main key is not present, this is the key value from the config
1077
+ */
1078
+ fb?: keyof T | keyof C | Array<keyof T | keyof C>;
1079
+ /**
1080
+ * Use this check to determine the default fallback, default only checked whether the property isDefined,
1081
+ * therefore `null`; `""` are considered to be valid values.
1082
+ */
1083
+ dfVal?: (value: any) => boolean;
1084
+ }
1085
+
1086
+ /**
1087
+ * The Type definition to define default values to be applied to the config
1088
+ * The value may be either the direct value or a ConfigDefaultCheck definition
1089
+ */
1090
+ type IConfigDefaults<T, C extends IConfiguration = IConfiguration> = {
1091
+ [key in keyof T]: T[key] | IConfigDefaultCheck<T, T[key], C>;
1092
+ };
1093
+
1094
+ /**
1095
+ * The type which identifies the function use to validate the user supplied value
1096
+ */
1097
+ type IConfigSetFn<T, V> = (value: any, defValue: V, theConfig: T) => V;
1098
+
1022
1099
  /**
1023
1100
  * Configuration provided to SDK core
1024
1101
  */
@@ -1200,6 +1277,11 @@ declare namespace ApplicationInsights {
1200
1277
  * @returns - True if the cookie was marked for deletion otherwise false (Because cookie usage is not available)
1201
1278
  */
1202
1279
  purge(name: string, path?: string): boolean;
1280
+ /**
1281
+ * Optional Callback hook to allow the diagnostic logger to update it's configuration
1282
+ * @param updateState
1283
+ */
1284
+ update?(updateState: ITelemetryUpdateState): void;
1203
1285
  }
1204
1286
 
1205
1287
  /**
@@ -1300,20 +1382,20 @@ declare namespace ApplicationInsights {
1300
1382
  queue: _InternalLogMessage[];
1301
1383
  /**
1302
1384
  * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
1303
- * @param severity {LoggingSeverity} - The severity of the log message
1304
- * @param message {_InternalLogMessage} - The log message.
1385
+ * @param severity - {LoggingSeverity} - The severity of the log message
1386
+ * @param message - {_InternalLogMessage} - The log message.
1305
1387
  */
1306
1388
  throwInternal(severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
1307
1389
  /**
1308
1390
  * This will write a warning to the console if possible
1309
- * @param message {string} - The warning message
1391
+ * @param message - {string} - The warning message
1310
1392
  */
1311
1393
  warnToConsole(message: string): void;
1312
1394
  /**
1313
1395
  * This will write an error to the console if possible.
1314
1396
  * Provided by the default DiagnosticLogger instance, and internally the SDK will fall back to warnToConsole, however,
1315
1397
  * direct callers MUST check for its existence on the logger as you can provide your own IDiagnosticLogger instance.
1316
- * @param message {string} - The error message
1398
+ * @param message - {string} - The error message
1317
1399
  */
1318
1400
  errorToConsole?(message: string): void;
1319
1401
  /**
@@ -1322,10 +1404,15 @@ declare namespace ApplicationInsights {
1322
1404
  resetInternalMessageCount(): void;
1323
1405
  /**
1324
1406
  * Logs a message to the internal queue.
1325
- * @param severity {LoggingSeverity} - The severity of the log message
1326
- * @param message {_InternalLogMessage} - The message to log.
1407
+ * @param severity - {LoggingSeverity} - The severity of the log message
1408
+ * @param message - {_InternalLogMessage} - The message to log.
1327
1409
  */
1328
1410
  logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
1411
+ /**
1412
+ * Optional Callback hook to allow the diagnostic logger to update it's configuration
1413
+ * @param updateState
1414
+ */
1415
+ update?(updateState: ITelemetryUpdateState): void;
1329
1416
  }
1330
1417
 
1331
1418
  interface IDistributedTraceContext {
@@ -1372,6 +1459,39 @@ declare namespace ApplicationInsights {
1372
1459
  setTraceFlags(newValue?: number): void;
1373
1460
  }
1374
1461
 
1462
+ /**
1463
+ * This interface identifies the config which can track changes
1464
+ */
1465
+ interface IDynamicConfigHandler<T extends IConfiguration> {
1466
+ /**
1467
+ * Unique Id for this config handler
1468
+ */
1469
+ readonly uid: string;
1470
+ /**
1471
+ * Link back to the configuration object that should be used to get/set values
1472
+ */
1473
+ cfg: T;
1474
+ /**
1475
+ * The logger instance to use to loger any issues
1476
+ */
1477
+ logger: IDiagnosticLogger;
1478
+ /**
1479
+ * Helper to call any listeners that are waiting to be notified
1480
+ */
1481
+ notify: () => void;
1482
+ /**
1483
+ * Watch and track changes for accesses to the current config anb
1484
+ */
1485
+ watch: (configHandler: WatcherFunction<T>) => IWatcherHandler<T>;
1486
+ /**
1487
+ * Set the value against the provided config/name with the value, the property
1488
+ * will be converted to be dynamic (if not already) as long as the provided config
1489
+ * is already a tracked dynamic object.
1490
+ * @throws TypeError if the provided config is not a monitored dynamic config
1491
+ */
1492
+ set: <C, V>(theConfig: C, name: string, value: V) => V;
1493
+ }
1494
+
1375
1495
  interface IEnvelope extends ISerializable {
1376
1496
  /**
1377
1497
  * Envelope version. For internal use only. By assigning this the default, it will not be serialized within the payload unless changed to a value other than #1.
@@ -1424,76 +1544,14 @@ declare namespace ApplicationInsights {
1424
1544
  iKey?: string;
1425
1545
  }
1426
1546
 
1427
- interface IInstrumentCallDetails {
1428
- name: string;
1429
- inst: any;
1430
- /**
1431
- * This returns an object that the hook function can use to store hook specific
1432
- * context, it it not shared with any other hook instances and is unique for the
1433
- * current call.
1434
- * A hook implementation can use this to pass / share context between different
1435
- * hook callbacks eg. request/response requst/hookErrors etc.
1436
- */
1437
- ctx: () => any;
1438
- /**
1439
- * Allows the hook functions to replace the original arguments
1440
- * @param idx - The argument index (0 based)
1441
- * @param value - The new value for the argument
1442
- */
1443
- set: (idx: number, value: any) => void;
1444
- /**
1445
- * The result of the original method, only populated after the original method has returned
1446
- */
1447
- rslt?: any;
1448
- /**
1449
- * The error (exception) which occurred while executing the original method
1450
- */
1451
- err?: Error;
1452
- /**
1453
- * The Event object from (window.event) at the start of the original call
1454
- */
1455
- evt?: Event;
1456
- }
1457
-
1458
1547
  /**
1459
- * The holder of the specific instance callback
1548
+ * An alternate interface which provides automatic removal during unloading of the component
1460
1549
  */
1461
- interface IInstrumentHook {
1462
- /** Unique Id for this callback on the hooked method */
1463
- id: number;
1464
- /** Holds the callbacks */
1465
- cbks: IInstrumentHooksCallbacks;
1466
- /** Remove this hook from the function */
1467
- rm: () => void;
1468
- }
1469
-
1470
- /**
1471
- * The callbacks to call for the instrumented function, you must provide at least the request and/or response callbacks, both are not required.
1472
- * You must always supply the error callback
1473
- */
1474
- interface IInstrumentHooksCallbacks {
1475
- /**
1476
- * [Optional] Namespace details (same as the namespace used for events), useful for debugging and testing to
1477
- * identify the source of the instrumented hooks
1478
- */
1479
- ns?: string | string[];
1550
+ interface ILegacyUnloadHook {
1480
1551
  /**
1481
- * The hook callback to call before the original function is called
1552
+ * Legacy Self remove the referenced component
1482
1553
  */
1483
- req?: InstrumentorHooksCallback;
1484
- /**
1485
- * The hook callback to call after the original function was called
1486
- */
1487
- rsp?: InstrumentorHooksCallback;
1488
- /**
1489
- * The callback to call if the hook function causes an exception
1490
- */
1491
- hkErr?: InstrumentorHooksCallback;
1492
- /**
1493
- * The callback to call if the original function causes an exception, even if you
1494
- * supply a callback the original exception will still be thrown
1495
- */
1496
- fnErr?: InstrumentorHooksCallback;
1554
+ remove: () => void;
1497
1555
  }
1498
1556
 
1499
1557
  interface ILoadedPlugin<T extends IPlugin> {
@@ -1567,20 +1625,20 @@ declare namespace ApplicationInsights {
1567
1625
  interface INotificationListener {
1568
1626
  /**
1569
1627
  * [Optional] A function called when events are sent.
1570
- * @param {ITelemetryItem[]} events - The array of events that have been sent.
1628
+ * @param events - The array of events that have been sent.
1571
1629
  */
1572
1630
  eventsSent?: (events: ITelemetryItem[]) => void;
1573
1631
  /**
1574
1632
  * [Optional] A function called when events are discarded.
1575
- * @param {ITelemetryItem[]} events - The array of events that have been discarded.
1576
- * @param {number} reason - The reason for discarding the events. The EventsDiscardedReason
1633
+ * @param events - The array of events that have been discarded.
1634
+ * @param reason - The reason for discarding the events. The EventsDiscardedReason
1577
1635
  * constant should be used to check the different values.
1578
1636
  */
1579
1637
  eventsDiscarded?: (events: ITelemetryItem[], reason: number) => void;
1580
1638
  /**
1581
1639
  * [Optional] A function called when the events have been requested to be sent to the sever.
1582
- * @param {number} sendReason - The reason why the event batch is being sent.
1583
- * @param {boolean} isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1640
+ * @param sendReason - The reason why the event batch is being sent.
1641
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1584
1642
  */
1585
1643
  eventsSendRequest?: (sendReason: number, isAsync?: boolean) => void;
1586
1644
  /**
@@ -1598,46 +1656,40 @@ declare namespace ApplicationInsights {
1598
1656
  listeners: INotificationListener[];
1599
1657
  /**
1600
1658
  * Adds a notification listener.
1601
- * @param {INotificationListener} listener - The notification listener to be added.
1659
+ * @param listener - The notification listener to be added.
1602
1660
  */
1603
1661
  addNotificationListener(listener: INotificationListener): void;
1604
1662
  /**
1605
1663
  * Removes all instances of the listener.
1606
- * @param {INotificationListener} listener - AWTNotificationListener to remove.
1664
+ * @param listener - AWTNotificationListener to remove.
1607
1665
  */
1608
1666
  removeNotificationListener(listener: INotificationListener): void;
1609
1667
  /**
1610
1668
  * Notification for events sent.
1611
- * @param {ITelemetryItem[]} events - The array of events that have been sent.
1669
+ * @param events - The array of events that have been sent.
1612
1670
  */
1613
1671
  eventsSent(events: ITelemetryItem[]): void;
1614
1672
  /**
1615
1673
  * Notification for events being discarded.
1616
- * @param {ITelemetryItem[]} events - The array of events that have been discarded by the SDK.
1617
- * @param {number} reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
1674
+ * @param events - The array of events that have been discarded by the SDK.
1675
+ * @param reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
1618
1676
  * constant should be used to check the different values.
1619
1677
  */
1620
1678
  eventsDiscarded(events: ITelemetryItem[], reason: number): void;
1621
1679
  /**
1622
1680
  * [Optional] A function called when the events have been requested to be sent to the sever.
1623
- * @param {number} sendReason - The reason why the event batch is being sent.
1624
- * @param {boolean} isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1681
+ * @param sendReason - The reason why the event batch is being sent.
1682
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1625
1683
  */
1626
1684
  eventsSendRequest?(sendReason: number, isAsync: boolean): void;
1627
1685
  /**
1628
1686
  * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
1629
1687
  * the event can be displayed via the debug plugin extension.
1630
- * @param perfEvent
1688
+ * @param perfEvent - The perf event details
1631
1689
  */
1632
1690
  perfEvent?(perfEvent: IPerfEvent): void;
1633
1691
  }
1634
1692
 
1635
- /**
1636
- * A callback function that will be called for the wrapped instrumentation function
1637
- * before the original function is executed.
1638
- */
1639
- type InstrumentorHooksCallback = (funcArgs: IInstrumentCallDetails, ...orgArgs: any[]) => void;
1640
-
1641
1693
  class _InternalLogMessage {
1642
1694
  static dataType: string;
1643
1695
  message: string;
@@ -1645,11 +1697,6 @@ declare namespace ApplicationInsights {
1645
1697
  constructor(msgId: _InternalMessageId, msg: string, isUserAct?: boolean, properties?: Object);
1646
1698
  }
1647
1699
 
1648
- /**
1649
- * Internal message ID. Please create a new one for every conceptually different message. Please keep alphabetically ordered
1650
- */
1651
- const _InternalMessageId: EnumValue<typeof _eInternalMessageId>;
1652
-
1653
1700
  type _InternalMessageId = number | _eInternalMessageId;
1654
1701
 
1655
1702
  interface IPageViewPerformanceTelemetry extends IPartC {
@@ -1811,14 +1858,14 @@ declare namespace ApplicationInsights {
1811
1858
  /**
1812
1859
  * Create a new event and start timing, the manager may return null/undefined to indicate that it does not
1813
1860
  * want to monitor this source event.
1814
- * @param src The source name of the event
1861
+ * @param src - The source name of the event
1815
1862
  * @param payloadDetails - An optional callback function to fetch the payload details for the event.
1816
1863
  * @param isAsync - Is the event occurring from a async event
1817
1864
  */
1818
1865
  create(src: string, payloadDetails?: () => any, isAsync?: boolean): IPerfEvent | null | undefined;
1819
1866
  /**
1820
1867
  * Complete the perfEvent and fire any notifications.
1821
- * @param perfEvent Fire the event which will also complete the passed event
1868
+ * @param perfEvent - Fire the event which will also complete the passed event
1822
1869
  */
1823
1870
  fire(perfEvent: IPerfEvent): void;
1824
1871
  /**
@@ -1844,7 +1891,7 @@ declare namespace ApplicationInsights {
1844
1891
  getPerfMgr(): IPerfManager;
1845
1892
  /**
1846
1893
  * Set the current performance manager
1847
- * @param perfMgr The performance manager
1894
+ * @param perfMgr - The performance manager
1848
1895
  */
1849
1896
  setPerfMgr(perfMgr: IPerfManager): void;
1850
1897
  }
@@ -2013,68 +2060,68 @@ declare namespace ApplicationInsights {
2013
2060
  /**
2014
2061
  * The url to which payloads will be sent
2015
2062
  */
2016
- endpointUrl: () => string;
2063
+ endpointUrl: string;
2017
2064
  /**
2018
2065
  * The JSON format (normal vs line delimited). True means line delimited JSON.
2019
2066
  */
2020
- emitLineDelimitedJson: () => boolean;
2067
+ emitLineDelimitedJson: boolean;
2021
2068
  /**
2022
2069
  * The maximum size of a batch in bytes
2023
2070
  */
2024
- maxBatchSizeInBytes: () => number;
2071
+ maxBatchSizeInBytes: number;
2025
2072
  /**
2026
2073
  * The maximum interval allowed between calls to batchInvoke
2027
2074
  */
2028
- maxBatchInterval: () => number;
2075
+ maxBatchInterval: number;
2029
2076
  /**
2030
2077
  * The master off switch. Do not send any data if set to TRUE
2031
2078
  */
2032
- disableTelemetry: () => boolean;
2079
+ disableTelemetry: boolean;
2033
2080
  /**
2034
2081
  * Store a copy of a send buffer in the session storage
2035
2082
  */
2036
- enableSessionStorageBuffer: () => boolean;
2083
+ enableSessionStorageBuffer: boolean;
2037
2084
  /**
2038
2085
  * Is retry handler disabled.
2039
2086
  * If enabled, retry on 206 (partial success), 408 (timeout), 429 (too many requests), 500 (internal server error) and 503 (service unavailable).
2040
2087
  */
2041
- isRetryDisabled: () => boolean;
2042
- isBeaconApiDisabled: () => boolean;
2088
+ isRetryDisabled: boolean;
2089
+ isBeaconApiDisabled: boolean;
2043
2090
  /**
2044
2091
  * Don't use XMLHttpRequest or XDomainRequest (for IE < 9) by default instead attempt to use fetch() or sendBeacon.
2045
2092
  * If no other transport is available it will still use XMLHttpRequest
2046
2093
  */
2047
- disableXhr: () => boolean;
2094
+ disableXhr: boolean;
2048
2095
  /**
2049
2096
  * If fetch keepalive is supported do not use it for sending events during unload, it may still fallback to fetch() without keepalive
2050
2097
  */
2051
- onunloadDisableFetch: () => boolean;
2098
+ onunloadDisableFetch: boolean;
2052
2099
  /**
2053
2100
  * Is beacon disabled on page unload.
2054
2101
  * If enabled, flush events through beaconSender.
2055
2102
  */
2056
- onunloadDisableBeacon: () => boolean;
2103
+ onunloadDisableBeacon: boolean;
2057
2104
  /**
2058
2105
  * (Optional) Override the instrumentation key that this channel instance sends to
2059
2106
  */
2060
- instrumentationKey: () => string;
2061
- namePrefix: () => string;
2062
- samplingPercentage: () => number;
2107
+ instrumentationKey: string;
2108
+ namePrefix: string;
2109
+ samplingPercentage: number;
2063
2110
  /**
2064
2111
  * (Optional) The ability for the user to provide extra headers
2065
2112
  */
2066
- customHeaders: () => [{
2113
+ customHeaders: [{
2067
2114
  header: string;
2068
2115
  value: string;
2069
2116
  }];
2070
2117
  /**
2071
2118
  * (Optional) Provide user an option to convert undefined field to user defined value.
2072
2119
  */
2073
- convertUndefined: () => any;
2120
+ convertUndefined: any;
2074
2121
  /**
2075
2122
  * (Optional) The number of events that can be kept in memory before the SDK starts to drop events. By default, this is 10,000.
2076
2123
  */
2077
- eventsLimitInMem: () => number;
2124
+ eventsLimitInMem: number;
2078
2125
  }
2079
2126
 
2080
2127
  interface ISerializable {
@@ -2093,7 +2140,7 @@ declare namespace ApplicationInsights {
2093
2140
  obj: string[];
2094
2141
  }
2095
2142
 
2096
- interface ITelemetryInitializerHandler {
2143
+ interface ITelemetryInitializerHandler extends ILegacyUnloadHook {
2097
2144
  remove(): void;
2098
2145
  }
2099
2146
 
@@ -2211,12 +2258,22 @@ declare namespace ApplicationInsights {
2211
2258
  * Identifies the reason for the update notification, this is a bitwise numeric value
2212
2259
  */
2213
2260
  reason: TelemetryUpdateReason;
2261
+ /**
2262
+ * This is a new active configuration that should be used
2263
+ */
2264
+ cfg?: IConfiguration;
2265
+ /**
2266
+ * The detected changes
2267
+ */
2268
+ oldCfg?: IConfiguration;
2214
2269
  /**
2215
2270
  * If this is a configuration update this was the previous configuration that was used
2216
2271
  */
2272
+ newConfig?: IConfiguration;
2217
2273
  /**
2218
- * If this is a configuration update is the new configuration that is being used
2274
+ * Was the new config requested to be merged with the existing config
2219
2275
  */
2276
+ merge?: boolean;
2220
2277
  /**
2221
2278
  * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
2222
2279
  */
@@ -2248,6 +2305,26 @@ declare namespace ApplicationInsights {
2248
2305
  iKey?: string;
2249
2306
  }
2250
2307
 
2308
+ /**
2309
+ * An interface which provides automatic removal during unloading of the component
2310
+ */
2311
+ interface IUnloadHook {
2312
+ /**
2313
+ * Self remove the referenced component
2314
+ */
2315
+ rm: () => void;
2316
+ }
2317
+
2318
+ interface IWatchDetails<T extends IConfiguration> {
2319
+ cfg: T;
2320
+ hdlr: IDynamicConfigHandler<T>;
2321
+ }
2322
+
2323
+ interface IWatcherHandler<T extends IConfiguration> extends IUnloadHook {
2324
+ fn: WatcherFunction<T>;
2325
+ rm: () => void;
2326
+ }
2327
+
2251
2328
  const LoggingSeverity: EnumValue<typeof eLoggingSeverity>;
2252
2329
 
2253
2330
  type LoggingSeverity = number | eLoggingSeverity;
@@ -2314,8 +2391,8 @@ declare namespace ApplicationInsights {
2314
2391
  _xhrReadyStateChange(xhr: XMLHttpRequest, payload: string[], countOfItemsInPayload: number): void;
2315
2392
  /**
2316
2393
  * Immediately send buffered data
2317
- * @param async {boolean} - Indicates if the events should be sent asynchronously
2318
- * @param forcedSender {SenderFunction} - Indicates the forcedSender, undefined if not passed
2394
+ * @param async - {boolean} - Indicates if the events should be sent asynchronously
2395
+ * @param forcedSender - {SenderFunction} - Indicates the forcedSender, undefined if not passed
2319
2396
  */
2320
2397
  triggerSend(async?: boolean, forcedSender?: SenderFunction, sendReason?: SendRequestReason): void;
2321
2398
  /**
@@ -2336,8 +2413,8 @@ declare namespace ApplicationInsights {
2336
2413
  _xdrOnLoad(xdr: XDomainRequest, payload: string[]): void;
2337
2414
  /**
2338
2415
  * Add header to request
2339
- * @param name - Header name.
2340
- * @param value - Header value.
2416
+ * @param name - Header name.
2417
+ * @param value - Header value.
2341
2418
  */
2342
2419
  addHeader(name: string, value: string): void;
2343
2420
  }
@@ -2436,6 +2513,7 @@ declare namespace ApplicationInsights {
2436
2513
  /**
2437
2514
  * The configuration has ben updated or changed
2438
2515
  */
2516
+ ConfigurationChanged = 1,
2439
2517
  /**
2440
2518
  * One or more plugins have been added
2441
2519
  */
@@ -2450,6 +2528,8 @@ declare namespace ApplicationInsights {
2450
2528
 
2451
2529
  type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2452
2530
 
2531
+ type WatcherFunction<T extends IConfiguration> = (details: IWatchDetails<T>) => void;
2532
+
2453
2533
  interface XDomainRequest extends XMLHttpRequestEventTarget {
2454
2534
  readonly responseText: string;
2455
2535
  send(payload: string): void;