@microsoft/applicationinsights-web-basic 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft.ApplicationInsights, 2.8.0-nightly.2202-06
2
+ * Microsoft.ApplicationInsights, 2.8.0-nightly.2204-06
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -17,26 +17,6 @@ export declare class AppInsightsCore extends BaseCore implements IAppInsightsCor
17
17
  constructor();
18
18
  initialize(config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
19
19
  track(telemetryItem: ITelemetryItem): void;
20
- /**
21
- * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
22
- * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
23
- * called.
24
- * @param {INotificationListener} listener - An INotificationListener object.
25
- */
26
- addNotificationListener(listener: INotificationListener): void;
27
- /**
28
- * Removes all instances of the listener.
29
- * @param {INotificationListener} listener - INotificationListener to remove.
30
- */
31
- removeNotificationListener(listener: INotificationListener): void;
32
- /**
33
- * Periodically check logger.queue for
34
- */
35
- pollInternalLogs(eventName?: string): number;
36
- /**
37
- * Periodically check logger.queue for
38
- */
39
- stopPollingInternalLogs(): void;
40
20
  }
41
21
 
42
22
  /**
@@ -45,7 +25,6 @@ export declare class AppInsightsCore extends BaseCore implements IAppInsightsCor
45
25
  */
46
26
  export declare class ApplicationInsights {
47
27
  config: IConfiguration & IConfig;
48
- private core;
49
28
  /**
50
29
  * Creates an instance of ApplicationInsights.
51
30
  * @param {IConfiguration & IConfig} config
@@ -71,11 +50,51 @@ export declare class ApplicationInsights {
71
50
  * @memberof ApplicationInsights
72
51
  */
73
52
  flush(async?: boolean): void;
74
- private pollInternalLogs;
53
+ pollInternalLogs(): void;
75
54
  stopPollingInternalLogs(): void;
76
- private getSKUDefaults;
55
+ getSKUDefaults(): void;
56
+ /**
57
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
58
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
59
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
60
+ * approach is to create a new instance and initialize that instance.
61
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
62
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
63
+ */
64
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
65
+ /**
66
+ * Find and return the (first) plugin with the specified identifier if present
67
+ * @param pluginIdentifier
68
+ */
69
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
70
+ /**
71
+ * Add a new plugin to the installation
72
+ * @param plugin - The new plugin to add
73
+ * @param replaceExisting - should any existing plugin be replaced
74
+ * @param doAsync - Should the add be performed asynchronously
75
+ */
76
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
77
+ /**
78
+ * Returns the unique event namespace that should be used
79
+ */
80
+ evtNamespace(): string;
81
+ /**
82
+ * Add an unload handler that will be called when the SDK is being unloaded
83
+ * @param handler - the handler
84
+ */
85
+ addUnloadCb(handler: UnloadHandler): void;
77
86
  }
78
87
 
88
+ /**
89
+ * Performs the specified action for each element in an array. This helper exists to avoid adding a polyfil for older browsers
90
+ * that do not define Array.prototype.xxxx (eg. ES3 only, IE8) just in case any page checks for presence/absence of the prototype
91
+ * implementation. Note: For consistency this will not use the Array.prototype.xxxx implementation if it exists as this would
92
+ * cause a testing requirement to test with and without the implementations
93
+ * @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
94
+ * @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.
95
+ */
96
+ export declare function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => undefined | void | number, thisArg?: any): void;
97
+
79
98
  declare class BaseCore implements IAppInsightsCore {
80
99
  static defaultConfig: IConfiguration;
81
100
  config: IConfiguration;
@@ -88,6 +107,18 @@ declare class BaseCore implements IAppInsightsCore {
88
107
  track(telemetryItem: ITelemetryItem): void;
89
108
  getProcessTelContext(): IProcessTelemetryContext;
90
109
  getNotifyMgr(): INotificationManager;
110
+ /**
111
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
112
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
113
+ * called.
114
+ * @param {INotificationListener} listener - An INotificationListener object.
115
+ */
116
+ addNotificationListener(listener: INotificationListener): void;
117
+ /**
118
+ * Removes all instances of the listener.
119
+ * @param {INotificationListener} listener - INotificationListener to remove.
120
+ */
121
+ removeNotificationListener(listener: INotificationListener): void;
91
122
  /**
92
123
  * Get the current cookie manager for this instance
93
124
  */
@@ -100,7 +131,67 @@ declare class BaseCore implements IAppInsightsCore {
100
131
  getPerfMgr(): IPerfManager;
101
132
  setPerfMgr(perfMgr: IPerfManager): void;
102
133
  eventCnt(): number;
134
+ /**
135
+ * Periodically check logger.queue for
136
+ */
137
+ pollInternalLogs(eventName?: string): number;
138
+ /**
139
+ * Periodically check logger.queue for
140
+ */
141
+ stopPollingInternalLogs(): void;
142
+ /**
143
+ * Add a telemetry processor to decorate or drop telemetry events.
144
+ * @param telemetryInitializer - The Telemetry Initializer function
145
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
146
+ */
147
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
148
+ /**
149
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
150
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
151
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
152
+ * approach is to create a new instance and initialize that instance.
153
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
154
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
155
+ * @param isAsync - Can the unload be performed asynchronously (default)
156
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
157
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
158
+ */
159
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
160
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
161
+ /**
162
+ * Add a new plugin to the installation
163
+ * @param plugin - The new plugin to add
164
+ * @param replaceExisting - should any existing plugin be replaced, default is false
165
+ * @param doAsync - Should the add be performed asynchronously
166
+ * @param addCb - [Optional] callback to call after the plugin has been added
167
+ */
168
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
169
+ /**
170
+ * Returns the unique event namespace that should be used
171
+ */
172
+ evtNamespace(): string;
173
+ /**
174
+ * Add an unload handler that will be called when the SDK is being unloaded
175
+ * @param handler - the handler
176
+ */
177
+ addUnloadCb(handler: UnloadHandler): void;
178
+ /**
179
+ * Flush and send any batched / cached data immediately
180
+ * @param async - send data asynchronously when true (defaults to true)
181
+ * @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.
182
+ * If the caller doesn't return true the caller should assume that it may never be called.
183
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
184
+ * @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
185
+ */
186
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): void;
103
187
  protected releaseQueue(): void;
188
+ /**
189
+ * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
190
+ * @param updateCtx - The plugin update context
191
+ * @param updateState - The Update State
192
+ * @returns boolean - True means the extension class will call updateState otherwise the Core will
193
+ */
194
+ protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
104
195
  }
105
196
 
106
197
  /**
@@ -109,6 +200,13 @@ declare class BaseCore implements IAppInsightsCore {
109
200
  * implementation so that new default implementations can be added without breaking all plugins.
110
201
  */
111
202
  declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
203
+ identifier: string;
204
+ version?: string;
205
+ /**
206
+ * Holds the core instance that was used during initialization
207
+ */
208
+ core: IAppInsightsCore;
209
+ priority: number;
112
210
  /**
113
211
  * Call back for telemetry processing before it it is sent
114
212
  * @param env - This is the current event being reported
@@ -130,13 +228,6 @@ declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
130
228
  * Returns whether the plugin has been initialized
131
229
  */
132
230
  isInitialized: () => boolean;
133
- identifier: string;
134
- version?: string;
135
- /**
136
- * Holds the core instance that was used during initialization
137
- */
138
- core: IAppInsightsCore;
139
- priority: number;
140
231
  /**
141
232
  * Helper to return the current IProcessTelemetryContext, if the passed argument exists this just
142
233
  * returns that value (helps with minification for callers), otherwise it will return the configured
@@ -149,12 +240,51 @@ declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
149
240
  */
150
241
  protected setInitialized: (isInitialized: boolean) => void;
151
242
  /**
152
- * Internal helper to initialize the instance
243
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
244
+ * finishes it's removal.
245
+ * @param unloadCtx - This is the context that should be used during unloading.
246
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
247
+ * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async unload/teardown operations.
248
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
249
+ */
250
+ protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
251
+ /**
252
+ * Extension hook to allow implementations to perform some additional update operations before the BaseTelemetryPlugin finishes it's removal
253
+ * @param updateCtx - This is the context that should be used during updating.
254
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
255
+ * @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.
256
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
153
257
  */
154
- private _baseTelInit;
258
+ protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
155
259
  constructor();
156
260
  initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
261
+ /**
262
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
263
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
264
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
265
+ * @param unloadCtx - This is the context that should be used during unloading.
266
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
267
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
268
+ */
269
+ teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
157
270
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
271
+ /**
272
+ * The the plugin should re-evaluate configuration and update any cached configuration settings.
273
+ * @param updateCtx - This is the context that should be used during updating.
274
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
275
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
276
+ */
277
+ update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
278
+ /**
279
+ * Add an unload handler that will be called when the SDK is being unloaded
280
+ * @param handler - the handler
281
+ */
282
+ protected _addUnloadCb(handler: UnloadHandler): void;
283
+ /**
284
+ * Add this hook so that it is automatically removed during unloading
285
+ * @param hooks - The single hook or an array of IInstrumentHook objects
286
+ */
287
+ protected _addHook(hooks: IInstrumentHook | IInstrumentHook[]): void;
158
288
  }
159
289
 
160
290
  /**
@@ -165,7 +295,15 @@ declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
165
295
  */
166
296
  export declare const CoreUtils: ICoreUtils;
167
297
 
168
- declare enum DistributedTracingModes {
298
+ declare const DistributedTracingModes: EnumValue< {
299
+ AI: number;
300
+ AI_AND_W3C: number;
301
+ W3C: number;
302
+ }>;
303
+
304
+ declare type DistributedTracingModes = number | eDistributedTracingModes;
305
+
306
+ declare const enum eDistributedTracingModes {
169
307
  /**
170
308
  * (Default) Send Application Insights correlation headers
171
309
  */
@@ -180,6 +318,112 @@ declare enum DistributedTracingModes {
180
318
  W3C = 2
181
319
  }
182
320
 
321
+ export declare const enum _eInternalMessageId {
322
+ BrowserDoesNotSupportLocalStorage = 0,
323
+ BrowserCannotReadLocalStorage = 1,
324
+ BrowserCannotReadSessionStorage = 2,
325
+ BrowserCannotWriteLocalStorage = 3,
326
+ BrowserCannotWriteSessionStorage = 4,
327
+ BrowserFailedRemovalFromLocalStorage = 5,
328
+ BrowserFailedRemovalFromSessionStorage = 6,
329
+ CannotSendEmptyTelemetry = 7,
330
+ ClientPerformanceMathError = 8,
331
+ ErrorParsingAISessionCookie = 9,
332
+ ErrorPVCalc = 10,
333
+ ExceptionWhileLoggingError = 11,
334
+ FailedAddingTelemetryToBuffer = 12,
335
+ FailedMonitorAjaxAbort = 13,
336
+ FailedMonitorAjaxDur = 14,
337
+ FailedMonitorAjaxOpen = 15,
338
+ FailedMonitorAjaxRSC = 16,
339
+ FailedMonitorAjaxSend = 17,
340
+ FailedMonitorAjaxGetCorrelationHeader = 18,
341
+ FailedToAddHandlerForOnBeforeUnload = 19,
342
+ FailedToSendQueuedTelemetry = 20,
343
+ FailedToReportDataLoss = 21,
344
+ FlushFailed = 22,
345
+ MessageLimitPerPVExceeded = 23,
346
+ MissingRequiredFieldSpecification = 24,
347
+ NavigationTimingNotSupported = 25,
348
+ OnError = 26,
349
+ SessionRenewalDateIsZero = 27,
350
+ SenderNotInitialized = 28,
351
+ StartTrackEventFailed = 29,
352
+ StopTrackEventFailed = 30,
353
+ StartTrackFailed = 31,
354
+ StopTrackFailed = 32,
355
+ TelemetrySampledAndNotSent = 33,
356
+ TrackEventFailed = 34,
357
+ TrackExceptionFailed = 35,
358
+ TrackMetricFailed = 36,
359
+ TrackPVFailed = 37,
360
+ TrackPVFailedCalc = 38,
361
+ TrackTraceFailed = 39,
362
+ TransmissionFailed = 40,
363
+ FailedToSetStorageBuffer = 41,
364
+ FailedToRestoreStorageBuffer = 42,
365
+ InvalidBackendResponse = 43,
366
+ FailedToFixDepricatedValues = 44,
367
+ InvalidDurationValue = 45,
368
+ TelemetryEnvelopeInvalid = 46,
369
+ CreateEnvelopeError = 47,
370
+ CannotSerializeObject = 48,
371
+ CannotSerializeObjectNonSerializable = 49,
372
+ CircularReferenceDetected = 50,
373
+ ClearAuthContextFailed = 51,
374
+ ExceptionTruncated = 52,
375
+ IllegalCharsInName = 53,
376
+ ItemNotInArray = 54,
377
+ MaxAjaxPerPVExceeded = 55,
378
+ MessageTruncated = 56,
379
+ NameTooLong = 57,
380
+ SampleRateOutOfRange = 58,
381
+ SetAuthContextFailed = 59,
382
+ SetAuthContextFailedAccountName = 60,
383
+ StringValueTooLong = 61,
384
+ StartCalledMoreThanOnce = 62,
385
+ StopCalledWithoutStart = 63,
386
+ TelemetryInitializerFailed = 64,
387
+ TrackArgumentsNotSpecified = 65,
388
+ UrlTooLong = 66,
389
+ SessionStorageBufferFull = 67,
390
+ CannotAccessCookie = 68,
391
+ IdTooLong = 69,
392
+ InvalidEvent = 70,
393
+ FailedMonitorAjaxSetRequestHeader = 71,
394
+ SendBrowserInfoOnUserInit = 72,
395
+ PluginException = 73,
396
+ NotificationException = 74,
397
+ SnippetScriptLoadFailure = 99,
398
+ InvalidInstrumentationKey = 100,
399
+ CannotParseAiBlobValue = 101,
400
+ InvalidContentBlob = 102,
401
+ TrackPageActionEventFailed = 103,
402
+ FailedAddingCustomDefinedRequestContext = 104,
403
+ InMemoryStorageBufferFull = 105
404
+ }
405
+
406
+ declare const enum eLoggingSeverity {
407
+ /**
408
+ * Error will be sent as internal telemetry
409
+ */
410
+ CRITICAL = 1,
411
+ /**
412
+ * Error will NOT be sent as internal telemetry, and will only be shown in browser console
413
+ */
414
+ WARNING = 2
415
+ }
416
+
417
+ declare type EnumValue<E = any> = {
418
+ readonly [key in keyof E]: E[key];
419
+ };
420
+
421
+ declare const enum GetExtCfgMergeType {
422
+ None = 0,
423
+ MergeDefaultOnly = 1,
424
+ MergeDefaultFromRootOrDefault = 2
425
+ }
426
+
183
427
  export declare interface IAppInsightsCore extends IPerfManagerProvider {
184
428
  config: IConfiguration;
185
429
  logger: IDiagnosticLogger;
@@ -215,12 +459,62 @@ export declare interface IAppInsightsCore extends IPerfManagerProvider {
215
459
  * @param {INotificationListener} listener - INotificationListener to remove.
216
460
  */
217
461
  removeNotificationListener?(listener: INotificationListener): void;
462
+ /**
463
+ * Add a telemetry processor to decorate or drop telemetry events.
464
+ * @param telemetryInitializer - The Telemetry Initializer function
465
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
466
+ */
467
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
218
468
  pollInternalLogs?(eventName?: string): number;
219
469
  stopPollingInternalLogs?(): void;
220
470
  /**
221
471
  * Return a new instance of the IProcessTelemetryContext for processing events
222
472
  */
223
473
  getProcessTelContext(): IProcessTelemetryContext;
474
+ /**
475
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
476
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
477
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
478
+ * approach is to create a new instance and initialize that instance.
479
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
480
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
481
+ * @param isAsync - Can the unload be performed asynchronously (default)
482
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
483
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
484
+ */
485
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
486
+ /**
487
+ * Find and return the (first) plugin with the specified identifier if present
488
+ * @param pluginIdentifier
489
+ */
490
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
491
+ /**
492
+ * Add a new plugin to the installation
493
+ * @param plugin - The new plugin to add
494
+ * @param replaceExisting - should any existing plugin be replaced, default is false
495
+ * @param doAsync - Should the add be performed asynchronously
496
+ * @param addCb - [Optional] callback to call after the plugin has been added
497
+ */
498
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
499
+ /**
500
+ * Returns the unique event namespace that should be used when registering events
501
+ */
502
+ evtNamespace(): string;
503
+ /**
504
+ * Add a handler that will be called when the SDK is being unloaded
505
+ * @param handler - the handler
506
+ */
507
+ addUnloadCb(handler: UnloadHandler): void;
508
+ /**
509
+ * Flush and send any batched / cached data immediately
510
+ * @param async - send data asynchronously when true (defaults to true)
511
+ * @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.
512
+ * If the caller doesn't return true the caller should assume that it may never be called.
513
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
514
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
515
+ * @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
516
+ */
517
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
224
518
  }
225
519
 
226
520
  /**
@@ -304,6 +598,67 @@ declare interface IBackendResponse {
304
598
  readonly appId?: string;
305
599
  }
306
600
 
601
+ declare interface IBaseProcessingContext {
602
+ /**
603
+ * The current core instance for the request
604
+ */
605
+ core: () => IAppInsightsCore;
606
+ /**
607
+ * THe current diagnostic logger for the request
608
+ */
609
+ diagLog: () => IDiagnosticLogger;
610
+ /**
611
+ * Gets the current core config instance
612
+ */
613
+ getCfg: () => IConfiguration;
614
+ /**
615
+ * Gets the named extension config
616
+ */
617
+ getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
618
+ /**
619
+ * Gets the named config from either the named identifier extension or core config if neither exist then the
620
+ * default value is returned
621
+ * @param identifier The named extension identifier
622
+ * @param field The config field name
623
+ * @param defaultValue The default value to return if no defined config exists
624
+ */
625
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
626
+ /**
627
+ * Helper to allow plugins to check and possibly shortcut executing code only
628
+ * required if there is a nextPlugin
629
+ */
630
+ hasNext: () => boolean;
631
+ /**
632
+ * Returns the next configured plugin proxy
633
+ */
634
+ getNext: () => ITelemetryPluginChain;
635
+ /**
636
+ * Helper to set the next plugin proxy
637
+ */
638
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
639
+ /**
640
+ * Synchronously iterate over the context chain running the callback for each plugin, once
641
+ * every plugin has been executed via the callback, any associated onComplete will be called.
642
+ * @param callback - The function call for each plugin in the context chain
643
+ */
644
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
645
+ /**
646
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
647
+ * @param onComplete - The onComplete to call
648
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
649
+ * @param args - Any additional arguments to pass to the onComplete function
650
+ */
651
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
652
+ /**
653
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
654
+ * @param plugins - The execution order to process the plugins, if null or not supplied
655
+ * then the current execution order will be copied.
656
+ * @param startAt - The plugin to start processing from, if missing from the execution
657
+ * order then the next plugin will be NOT set.
658
+ */
659
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
660
+ }
661
+
307
662
  /**
308
663
  * Provides data transmission capabilities
309
664
  */
@@ -317,15 +672,23 @@ declare interface IChannelControls extends ITelemetryPlugin {
317
672
  */
318
673
  resume(): void;
319
674
  /**
320
- * Tear down transmission pipeline
675
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
676
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
677
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
678
+ * @param unloadCtx - This is the context that should be used during unloading.
679
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
680
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
321
681
  */
322
- teardown(): void;
682
+ teardown: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
323
683
  /**
324
684
  * Flush to send data immediately; channel should default to sending data asynchronously
325
- * @param async: send data asynchronously when true
326
- * @param callBack: if specified, notify caller when send is complete
685
+ * @param async - send data asynchronously when true
686
+ * @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.
687
+ * If the caller doesn't return true the caller should assume that it may never be called.
688
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
689
+ * @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
327
690
  */
328
- flush(async: boolean, callBack?: () => void): void;
691
+ flush(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void;
329
692
  }
330
693
 
331
694
  declare interface IChannelControlsAI extends IChannelControls {
@@ -1000,7 +1363,7 @@ declare interface ICoreUtils {
1000
1363
  * @param callback {any} - The callback function that needs to be executed for the given event
1001
1364
  * @return {boolean} - true if the handler was successfully added
1002
1365
  */
1003
- addEventHandler: (eventName: string, callback: any) => boolean;
1366
+ addEventHandler: (eventName: string, callback: any, evtNamespace?: string | string[]) => boolean;
1004
1367
  /**
1005
1368
  * Return the current time via the Date now() function (if available) and falls back to (new Date()).getTime() if now() is unavailable (IE8 or less)
1006
1369
  * https://caniuse.com/#search=Date.now
@@ -1133,15 +1496,39 @@ declare interface IDiagnosticLogger {
1133
1496
  }
1134
1497
 
1135
1498
  declare interface IEnvelope extends ISerializable {
1499
+ /**
1500
+ * 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.
1501
+ */
1136
1502
  ver: number;
1503
+ /**
1504
+ * Type name of telemetry data item.
1505
+ */
1137
1506
  name: string;
1507
+ /**
1508
+ * Event date time when telemetry item was created. This is the wall clock time on the client when the event was generated. There is no guarantee that the client's time is accurate. This field must be formatted in UTC ISO 8601 format, with a trailing 'Z' character, as described publicly on https://en.wikipedia.org/wiki/ISO_8601#UTC. Note: the number of decimal seconds digits provided are variable (and unspecified). Consumers should handle this, i.e. managed code consumers should not use format 'O' for parsing as it specifies a fixed length. Example: 2009-06-15T13:45:30.0000000Z.
1509
+ */
1138
1510
  time: string;
1511
+ /**
1512
+ * Sampling rate used in application. This telemetry item represents 1 / sampleRate actual telemetry items.
1513
+ */
1139
1514
  sampleRate: number;
1515
+ /**
1516
+ * Sequence field used to track absolute order of uploaded events.
1517
+ */
1140
1518
  seq: string;
1519
+ /**
1520
+ * The application's instrumentation key. The key is typically represented as a GUID, but there are cases when it is not a guid. No code should rely on iKey being a GUID. Instrumentation key is case insensitive.
1521
+ */
1141
1522
  iKey: string;
1523
+ /**
1524
+ * Key/value collection of context properties. See ContextTagKeys for information on available properties.
1525
+ */
1142
1526
  tags: {
1143
1527
  [name: string]: any;
1144
1528
  };
1529
+ /**
1530
+ * Telemetry data item.
1531
+ */
1145
1532
  data: any;
1146
1533
  }
1147
1534
 
@@ -1160,6 +1547,96 @@ export declare interface IEventTelemetry extends IPartC {
1160
1547
  iKey?: string;
1161
1548
  }
1162
1549
 
1550
+ declare interface IInstrumentCallDetails {
1551
+ name: string;
1552
+ inst: any;
1553
+ /**
1554
+ * This returns an object that the hook function can use to store hook specific
1555
+ * context, it it not shared with any other hook instances and is unique for the
1556
+ * current call.
1557
+ * A hook implementation can use this to pass / share context between different
1558
+ * hook callbacks eg. request/response requst/hookErrors etc.
1559
+ */
1560
+ ctx: () => any;
1561
+ /**
1562
+ * Allows the hook functions to replace the original arguments
1563
+ * @param idx - The argument index (0 based)
1564
+ * @param value - The new value for the argument
1565
+ */
1566
+ set: (idx: number, value: any) => void;
1567
+ /**
1568
+ * The result of the original method, only populated after the original method has returned
1569
+ */
1570
+ rslt?: any;
1571
+ /**
1572
+ * The error (exception) which occurred while executing the original method
1573
+ */
1574
+ err?: Error;
1575
+ /**
1576
+ * The Event object from (window.event) at the start of the original call
1577
+ */
1578
+ evt?: Event;
1579
+ }
1580
+
1581
+ /**
1582
+ * The holder of the specific instance callback
1583
+ */
1584
+ declare interface IInstrumentHook {
1585
+ /** Unique Id for this callback on the hooked method */
1586
+ id: number;
1587
+ /** Holds the callbacks */
1588
+ cbks: IInstrumentHooksCallbacks;
1589
+ /** Remove this hook from the function */
1590
+ rm: () => void;
1591
+ }
1592
+
1593
+ /**
1594
+ * The callbacks to call for the instrumented function, you must provide at least the request and/or response callbacks, both are not required.
1595
+ * You must always supply the error callback
1596
+ */
1597
+ declare interface IInstrumentHooksCallbacks {
1598
+ /**
1599
+ * [Optional] Namespace details (same as the namespace used for events), useful for debugging and testing to
1600
+ * identify the source of the instrumented hooks
1601
+ */
1602
+ ns?: string | string[];
1603
+ /**
1604
+ * The hook callback to call before the original function is called
1605
+ */
1606
+ req?: InstrumentorHooksCallback;
1607
+ /**
1608
+ * The hook callback to call after the original function was called
1609
+ */
1610
+ rsp?: InstrumentorHooksCallback;
1611
+ /**
1612
+ * The callback to call if the hook function causes an exception
1613
+ */
1614
+ hkErr?: InstrumentorHooksCallback;
1615
+ /**
1616
+ * The callback to call if the original function causes an exception, even if you
1617
+ * supply a callback the original exception will still be thrown
1618
+ */
1619
+ fnErr?: InstrumentorHooksCallback;
1620
+ }
1621
+
1622
+ export declare interface ILoadedPlugin<T extends IPlugin> {
1623
+ plugin: T;
1624
+ /**
1625
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
1626
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
1627
+ * @returns boolean = true if the plugin is in a state where it is operational.
1628
+ */
1629
+ isEnabled: () => boolean;
1630
+ /**
1631
+ * You can optionally enable / disable a plugin from processing events.
1632
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
1633
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
1634
+ * (unless it's also been re-initialized)
1635
+ */
1636
+ setEnabled: (isEnabled: boolean) => void;
1637
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
1638
+ }
1639
+
1163
1640
  export declare interface IMetricTelemetry extends IPartC {
1164
1641
  /**
1165
1642
  * @description (required) - name of this metric
@@ -1278,6 +1755,12 @@ declare interface INotificationManager {
1278
1755
  perfEvent?(perfEvent: IPerfEvent): void;
1279
1756
  }
1280
1757
 
1758
+ /**
1759
+ * A callback function that will be called for the wrapped instrumentation function
1760
+ * before the original function is executed.
1761
+ */
1762
+ declare type InstrumentorHooksCallback = (funcArgs: IInstrumentCallDetails, ...orgArgs: any[]) => void;
1763
+
1281
1764
  declare class _InternalLogMessage {
1282
1765
  static dataType: string;
1283
1766
  message: string;
@@ -1288,92 +1771,9 @@ declare class _InternalLogMessage {
1288
1771
  /**
1289
1772
  * Internal message ID. Please create a new one for every conceptually different message. Please keep alphabetically ordered
1290
1773
  */
1291
- declare const _InternalMessageId: {
1292
- BrowserDoesNotSupportLocalStorage: number;
1293
- BrowserCannotReadLocalStorage: number;
1294
- BrowserCannotReadSessionStorage: number;
1295
- BrowserCannotWriteLocalStorage: number;
1296
- BrowserCannotWriteSessionStorage: number;
1297
- BrowserFailedRemovalFromLocalStorage: number;
1298
- BrowserFailedRemovalFromSessionStorage: number;
1299
- CannotSendEmptyTelemetry: number;
1300
- ClientPerformanceMathError: number;
1301
- ErrorParsingAISessionCookie: number;
1302
- ErrorPVCalc: number;
1303
- ExceptionWhileLoggingError: number;
1304
- FailedAddingTelemetryToBuffer: number;
1305
- FailedMonitorAjaxAbort: number;
1306
- FailedMonitorAjaxDur: number;
1307
- FailedMonitorAjaxOpen: number;
1308
- FailedMonitorAjaxRSC: number;
1309
- FailedMonitorAjaxSend: number;
1310
- FailedMonitorAjaxGetCorrelationHeader: number;
1311
- FailedToAddHandlerForOnBeforeUnload: number;
1312
- FailedToSendQueuedTelemetry: number;
1313
- FailedToReportDataLoss: number;
1314
- FlushFailed: number;
1315
- MessageLimitPerPVExceeded: number;
1316
- MissingRequiredFieldSpecification: number;
1317
- NavigationTimingNotSupported: number;
1318
- OnError: number;
1319
- SessionRenewalDateIsZero: number;
1320
- SenderNotInitialized: number;
1321
- StartTrackEventFailed: number;
1322
- StopTrackEventFailed: number;
1323
- StartTrackFailed: number;
1324
- StopTrackFailed: number;
1325
- TelemetrySampledAndNotSent: number;
1326
- TrackEventFailed: number;
1327
- TrackExceptionFailed: number;
1328
- TrackMetricFailed: number;
1329
- TrackPVFailed: number;
1330
- TrackPVFailedCalc: number;
1331
- TrackTraceFailed: number;
1332
- TransmissionFailed: number;
1333
- FailedToSetStorageBuffer: number;
1334
- FailedToRestoreStorageBuffer: number;
1335
- InvalidBackendResponse: number;
1336
- FailedToFixDepricatedValues: number;
1337
- InvalidDurationValue: number;
1338
- TelemetryEnvelopeInvalid: number;
1339
- CreateEnvelopeError: number;
1340
- CannotSerializeObject: number;
1341
- CannotSerializeObjectNonSerializable: number;
1342
- CircularReferenceDetected: number;
1343
- ClearAuthContextFailed: number;
1344
- ExceptionTruncated: number;
1345
- IllegalCharsInName: number;
1346
- ItemNotInArray: number;
1347
- MaxAjaxPerPVExceeded: number;
1348
- MessageTruncated: number;
1349
- NameTooLong: number;
1350
- SampleRateOutOfRange: number;
1351
- SetAuthContextFailed: number;
1352
- SetAuthContextFailedAccountName: number;
1353
- StringValueTooLong: number;
1354
- StartCalledMoreThanOnce: number;
1355
- StopCalledWithoutStart: number;
1356
- TelemetryInitializerFailed: number;
1357
- TrackArgumentsNotSpecified: number;
1358
- UrlTooLong: number;
1359
- SessionStorageBufferFull: number;
1360
- CannotAccessCookie: number;
1361
- IdTooLong: number;
1362
- InvalidEvent: number;
1363
- FailedMonitorAjaxSetRequestHeader: number;
1364
- SendBrowserInfoOnUserInit: number;
1365
- PluginException: number;
1366
- NotificationException: number;
1367
- SnippetScriptLoadFailure: number;
1368
- InvalidInstrumentationKey: number;
1369
- CannotParseAiBlobValue: number;
1370
- InvalidContentBlob: number;
1371
- TrackPageActionEventFailed: number;
1372
- FailedAddingCustomDefinedRequestContext: number;
1373
- InMemoryStorageBufferFull: number;
1374
- };
1774
+ export declare const _InternalMessageId: EnumValue<typeof _eInternalMessageId>;
1375
1775
 
1376
- declare type _InternalMessageId = number | typeof _InternalMessageId;
1776
+ export declare type _InternalMessageId = number | _eInternalMessageId;
1377
1777
 
1378
1778
  export declare interface IPageViewPerformanceTelemetry extends IPartC {
1379
1779
  /**
@@ -1572,7 +1972,7 @@ declare interface IPerfManagerProvider {
1572
1972
  setPerfMgr(perfMgr: IPerfManager): void;
1573
1973
  }
1574
1974
 
1575
- declare interface IPlugin {
1975
+ export declare interface IPlugin {
1576
1976
  /**
1577
1977
  * Initialize plugin loaded by SDK
1578
1978
  * @param config - The config for the plugin to use
@@ -1588,10 +1988,14 @@ declare interface IPlugin {
1588
1988
  */
1589
1989
  isInitialized?: () => boolean;
1590
1990
  /**
1591
- * Tear down the plugin and remove any hooked value, the plugin should remove that it is no longer initialized and
1592
- * therefore can be re-initialized after being torn down.
1991
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
1992
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
1993
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
1994
+ * @param unloadCtx - This is the context that should be used during unloading.
1995
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
1996
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
1593
1997
  */
1594
- teardown?: () => void;
1998
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
1595
1999
  /**
1596
2000
  * Extension name
1597
2001
  */
@@ -1606,57 +2010,63 @@ declare interface IPlugin {
1606
2010
  * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
1607
2011
  * between multiple AppInsights instances
1608
2012
  */
1609
- declare interface IProcessTelemetryContext {
1610
- /**
1611
- * The current core instance for the request
1612
- */
1613
- core: () => IAppInsightsCore;
1614
- /**
1615
- * THe current diagnostic logger for the request
1616
- */
1617
- diagLog: () => IDiagnosticLogger;
1618
- /**
1619
- * Gets the current core config instance
1620
- */
1621
- getCfg: () => IConfiguration;
1622
- /**
1623
- * Gets the named extension config
1624
- */
1625
- getExtCfg: <T>(identifier: string, defaultValue?: T | any) => T;
2013
+ declare interface IProcessTelemetryContext extends IBaseProcessingContext {
1626
2014
  /**
1627
- * Gets the named config from either the named identifier extension or core config if neither exist then the
1628
- * default value is returned
1629
- * @param identifier The named extension identifier
1630
- * @param field The config field name
1631
- * @param defaultValue The default value to return if no defined config exists
2015
+ * Call back for telemetry processing before it it is sent
2016
+ * @param env - This is the current event being reported
2017
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1632
2018
  */
1633
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
2019
+ processNext: (env: ITelemetryItem) => boolean | void;
1634
2020
  /**
1635
- * Helper to allow plugins to check and possibly shortcut executing code only
1636
- * required if there is a nextPlugin
2021
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
2022
+ * @param plugins - The execution order to process the plugins, if null or not supplied
2023
+ * then the current execution order will be copied.
2024
+ * @param startAt - The plugin to start processing from, if missing from the execution
2025
+ * order then the next plugin will be NOT set.
1637
2026
  */
1638
- hasNext: () => boolean;
2027
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
2028
+ }
2029
+
2030
+ /**
2031
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
2032
+ * or the SDK is being unloaded.
2033
+ */
2034
+ declare interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
1639
2035
  /**
1640
- * Returns the next configured plugin proxy
2036
+ * This Plugin has finished unloading, so unload the next one
2037
+ * @param uploadState - The state of the unload process
2038
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1641
2039
  */
1642
- getNext: () => ITelemetryPluginChain;
2040
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
1643
2041
  /**
1644
- * Helper to set the next plugin proxy
2042
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
2043
+ * @param plugins - The execution order to process the plugins, if null or not supplied
2044
+ * then the current execution order will be copied.
2045
+ * @param startAt - The plugin to start processing from, if missing from the execution
2046
+ * order then the next plugin will be NOT set.
1645
2047
  */
1646
- setNext: (nextCtx: ITelemetryPluginChain) => void;
2048
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
2049
+ }
2050
+
2051
+ /**
2052
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
2053
+ * for when plugins are added, removed or the configuration was changed.
2054
+ */
2055
+ declare interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
1647
2056
  /**
1648
- * Call back for telemetry processing before it it is sent
1649
- * @param env - This is the current event being reported
2057
+ * This Plugin has finished unloading, so unload the next one
2058
+ * @param updateState - The update State
2059
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1650
2060
  */
1651
- processNext: (env: ITelemetryItem) => void;
2061
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
1652
2062
  /**
1653
- * Create a new context using the core and config from the current instance
2063
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1654
2064
  * @param plugins - The execution order to process the plugins, if null or not supplied
1655
2065
  * then the current execution order will be copied.
1656
2066
  * @param startAt - The plugin to start processing from, if missing from the execution
1657
2067
  * order then the next plugin will be NOT set.
1658
2068
  */
1659
- createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
2069
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
1660
2070
  }
1661
2071
 
1662
2072
  declare interface IRequestContext {
@@ -1793,11 +2203,17 @@ declare interface ISerializable {
1793
2203
  aiDataContract: any;
1794
2204
  }
1795
2205
 
2206
+ export declare function isNullOrUndefined(value: any): value is null | undefined;
2207
+
1796
2208
  declare interface IStackDetails {
1797
2209
  src: string;
1798
2210
  obj: string[];
1799
2211
  }
1800
2212
 
2213
+ declare interface ITelemetryInitializerHandler {
2214
+ remove(): void;
2215
+ }
2216
+
1801
2217
  /**
1802
2218
  * Telemety item supported in Core
1803
2219
  */
@@ -1847,15 +2263,7 @@ export declare interface ITelemetryItem {
1847
2263
  /**
1848
2264
  * Configuration provided to SDK core
1849
2265
  */
1850
- declare interface ITelemetryPlugin extends IPlugin {
1851
- /**
1852
- * Call back for telemetry processing before it it is sent
1853
- * @param env - This is the current event being reported
1854
- * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
1855
- * can optionally use this to access the current core instance or define / pass additional information
1856
- * to later plugins (vs appending items to the telemetry item)
1857
- */
1858
- processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2266
+ export declare interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
1859
2267
  /**
1860
2268
  * Set next extension for telemetry processing, this is not optional as plugins should use the
1861
2269
  * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
@@ -1871,7 +2279,7 @@ declare interface ITelemetryPlugin extends IPlugin {
1871
2279
  /**
1872
2280
  * Configuration provided to SDK core
1873
2281
  */
1874
- declare interface ITelemetryPluginChain {
2282
+ declare interface ITelemetryPluginChain extends ITelemetryProcessor {
1875
2283
  /**
1876
2284
  * Returns the underlying plugin that is being proxied for the processTelemetry call
1877
2285
  */
@@ -1880,6 +2288,16 @@ declare interface ITelemetryPluginChain {
1880
2288
  * Returns the next plugin
1881
2289
  */
1882
2290
  getNext: () => ITelemetryPluginChain;
2291
+ /**
2292
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
2293
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
2294
+ * @param unloadCtx - The unload context to use for this call.
2295
+ * @param unloadState - The details of the unload operation
2296
+ */
2297
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2298
+ }
2299
+
2300
+ declare interface ITelemetryProcessor {
1883
2301
  /**
1884
2302
  * Call back for telemetry processing before it it is sent
1885
2303
  * @param env - This is the current event being reported
@@ -1887,7 +2305,43 @@ declare interface ITelemetryPluginChain {
1887
2305
  * can optionally use this to access the current core instance or define / pass additional information
1888
2306
  * to later plugins (vs appending items to the telemetry item)
1889
2307
  */
1890
- processTelemetry: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
2308
+ processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2309
+ /**
2310
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
2311
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
2312
+ * the configuration has bee updated.
2313
+ * @param updateCtx - This is the context that should be used during updating.
2314
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
2315
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
2316
+ */
2317
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
2318
+ }
2319
+
2320
+ declare interface ITelemetryUnloadState {
2321
+ reason: TelemetryUnloadReason;
2322
+ isAsync: boolean;
2323
+ flushComplete?: boolean;
2324
+ }
2325
+
2326
+ declare interface ITelemetryUpdateState {
2327
+ /**
2328
+ * Identifies the reason for the update notification, this is a bitwise numeric value
2329
+ */
2330
+ reason: TelemetryUpdateReason;
2331
+ /**
2332
+ * If this is a configuration update this was the previous configuration that was used
2333
+ */
2334
+ /**
2335
+ * If this is a configuration update is the new configuration that is being used
2336
+ */
2337
+ /**
2338
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
2339
+ */
2340
+ added?: IPlugin[];
2341
+ /**
2342
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
2343
+ */
2344
+ removed?: IPlugin[];
1891
2345
  }
1892
2346
 
1893
2347
  export declare interface ITraceTelemetry extends IPartC {
@@ -1911,16 +2365,19 @@ export declare interface ITraceTelemetry extends IPartC {
1911
2365
  iKey?: string;
1912
2366
  }
1913
2367
 
1914
- declare enum LoggingSeverity {
1915
- /**
1916
- * Error will be sent as internal telemetry
1917
- */
1918
- CRITICAL = 1,
1919
- /**
1920
- * Error will NOT be sent as internal telemetry, and will only be shown in browser console
1921
- */
1922
- WARNING = 2
1923
- }
2368
+ declare const LoggingSeverity: EnumValue<typeof eLoggingSeverity>;
2369
+
2370
+ declare type LoggingSeverity = number | eLoggingSeverity;
2371
+
2372
+ /**
2373
+ * Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.
2374
+ *
2375
+ * @param target - The target object to be assigned with the source properties and functions
2376
+ * @param source - The source object which will be assigned / called by setting / calling the targets proxies
2377
+ * @param functionsToProxy - An array of function names that will be proxied on the target
2378
+ * @param overwriteTarget - If false this will not replace any pre-existing name otherwise (the default) it will overwrite any existing name
2379
+ */
2380
+ export declare function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget?: boolean): T;
1924
2381
 
1925
2382
  export declare class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
1926
2383
  static constructEnvelope(orig: ITelemetryItem, iKey: string, logger: IDiagnosticLogger, convertUndefined?: any): IEnvelope;
@@ -1966,7 +2423,6 @@ export declare class Sender extends BaseTelemetryPlugin implements IChannelContr
1966
2423
  * Will not flush if the Send has been paused.
1967
2424
  */
1968
2425
  onunloadFlush(): void;
1969
- teardown(): void;
1970
2426
  initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
1971
2427
  processTelemetry(telemetryItem: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
1972
2428
  /**
@@ -2008,7 +2464,7 @@ declare type SenderFunction = (payload: string[], isAsync: boolean) => void;
2008
2464
  /**
2009
2465
  * The EventsDiscardedReason enumeration contains a set of values that specify the reason for discarding an event.
2010
2466
  */
2011
- declare const enum SendRequestReason {
2467
+ export declare const enum SendRequestReason {
2012
2468
  /**
2013
2469
  * No specific reason was specified
2014
2470
  */
@@ -2037,6 +2493,10 @@ declare const enum SendRequestReason {
2037
2493
  * The event(s) being sent as a retry
2038
2494
  */
2039
2495
  Retry = 5,
2496
+ /**
2497
+ * The SDK is unloading
2498
+ */
2499
+ SdkUnload = 6,
2040
2500
  /**
2041
2501
  * Maximum batch size would be exceeded
2042
2502
  */
@@ -2062,6 +2522,55 @@ declare interface Tags {
2062
2522
  [key: string]: any;
2063
2523
  }
2064
2524
 
2525
+ declare type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
2526
+
2527
+ /**
2528
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
2529
+ */
2530
+ declare const enum TelemetryUnloadReason {
2531
+ /**
2532
+ * Teardown has been called without any context.
2533
+ */
2534
+ ManualTeardown = 0,
2535
+ /**
2536
+ * Just this plugin is being removed
2537
+ */
2538
+ PluginUnload = 1,
2539
+ /**
2540
+ * This instance of the plugin is being removed and replaced
2541
+ */
2542
+ PluginReplace = 2,
2543
+ /**
2544
+ * The entire SDK is being unloaded
2545
+ */
2546
+ SdkUnload = 50
2547
+ }
2548
+
2549
+ /**
2550
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
2551
+ */
2552
+ declare const enum TelemetryUpdateReason {
2553
+ /**
2554
+ * Unknown.
2555
+ */
2556
+ Unknown = 0,
2557
+ /**
2558
+ * The configuration has ben updated or changed
2559
+ */
2560
+ /**
2561
+ * One or more plugins have been added
2562
+ */
2563
+ PluginAdded = 16,
2564
+ /**
2565
+ * One or more plugins have been removed
2566
+ */
2567
+ PluginRemoved = 32
2568
+ }
2569
+
2570
+ export declare function throwError(message: string): never;
2571
+
2572
+ declare type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2573
+
2065
2574
  declare interface XDomainRequest extends XMLHttpRequestEventTarget {
2066
2575
  readonly responseText: string;
2067
2576
  send(payload: string): void;