@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
@@ -11,26 +11,6 @@ declare namespace ApplicationInsights {
11
11
  constructor();
12
12
  initialize(config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
13
13
  track(telemetryItem: ITelemetryItem): void;
14
- /**
15
- * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
16
- * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
17
- * called.
18
- * @param {INotificationListener} listener - An INotificationListener object.
19
- */
20
- addNotificationListener(listener: INotificationListener): void;
21
- /**
22
- * Removes all instances of the listener.
23
- * @param {INotificationListener} listener - INotificationListener to remove.
24
- */
25
- removeNotificationListener(listener: INotificationListener): void;
26
- /**
27
- * Periodically check logger.queue for
28
- */
29
- pollInternalLogs(eventName?: string): number;
30
- /**
31
- * Periodically check logger.queue for
32
- */
33
- stopPollingInternalLogs(): void;
34
14
  }
35
15
 
36
16
  /**
@@ -39,7 +19,6 @@ declare namespace ApplicationInsights {
39
19
  */
40
20
  class ApplicationInsights {
41
21
  config: IConfiguration & IConfig;
42
- private core;
43
22
  /**
44
23
  * Creates an instance of ApplicationInsights.
45
24
  * @param {IConfiguration & IConfig} config
@@ -65,11 +44,51 @@ declare namespace ApplicationInsights {
65
44
  * @memberof ApplicationInsights
66
45
  */
67
46
  flush(async?: boolean): void;
68
- private pollInternalLogs;
47
+ pollInternalLogs(): void;
69
48
  stopPollingInternalLogs(): void;
70
- private getSKUDefaults;
49
+ getSKUDefaults(): void;
50
+ /**
51
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
52
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
53
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
54
+ * approach is to create a new instance and initialize that instance.
55
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
56
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
57
+ */
58
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
59
+ /**
60
+ * Find and return the (first) plugin with the specified identifier if present
61
+ * @param pluginIdentifier
62
+ */
63
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
64
+ /**
65
+ * Add a new plugin to the installation
66
+ * @param plugin - The new plugin to add
67
+ * @param replaceExisting - should any existing plugin be replaced
68
+ * @param doAsync - Should the add be performed asynchronously
69
+ */
70
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
71
+ /**
72
+ * Returns the unique event namespace that should be used
73
+ */
74
+ evtNamespace(): string;
75
+ /**
76
+ * Add an unload handler that will be called when the SDK is being unloaded
77
+ * @param handler - the handler
78
+ */
79
+ addUnloadCb(handler: UnloadHandler): void;
71
80
  }
72
81
 
82
+ /**
83
+ * Performs the specified action for each element in an array. This helper exists to avoid adding a polyfil for older browsers
84
+ * that do not define Array.prototype.xxxx (eg. ES3 only, IE8) just in case any page checks for presence/absence of the prototype
85
+ * implementation. Note: For consistency this will not use the Array.prototype.xxxx implementation if it exists as this would
86
+ * cause a testing requirement to test with and without the implementations
87
+ * @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
88
+ * @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.
89
+ */
90
+ function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => undefined | void | number, thisArg?: any): void;
91
+
73
92
  class BaseCore implements IAppInsightsCore {
74
93
  static defaultConfig: IConfiguration;
75
94
  config: IConfiguration;
@@ -82,6 +101,18 @@ declare namespace ApplicationInsights {
82
101
  track(telemetryItem: ITelemetryItem): void;
83
102
  getProcessTelContext(): IProcessTelemetryContext;
84
103
  getNotifyMgr(): INotificationManager;
104
+ /**
105
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
106
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
107
+ * called.
108
+ * @param {INotificationListener} listener - An INotificationListener object.
109
+ */
110
+ addNotificationListener(listener: INotificationListener): void;
111
+ /**
112
+ * Removes all instances of the listener.
113
+ * @param {INotificationListener} listener - INotificationListener to remove.
114
+ */
115
+ removeNotificationListener(listener: INotificationListener): void;
85
116
  /**
86
117
  * Get the current cookie manager for this instance
87
118
  */
@@ -94,7 +125,67 @@ declare namespace ApplicationInsights {
94
125
  getPerfMgr(): IPerfManager;
95
126
  setPerfMgr(perfMgr: IPerfManager): void;
96
127
  eventCnt(): number;
128
+ /**
129
+ * Periodically check logger.queue for
130
+ */
131
+ pollInternalLogs(eventName?: string): number;
132
+ /**
133
+ * Periodically check logger.queue for
134
+ */
135
+ stopPollingInternalLogs(): void;
136
+ /**
137
+ * Add a telemetry processor to decorate or drop telemetry events.
138
+ * @param telemetryInitializer - The Telemetry Initializer function
139
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
140
+ */
141
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
142
+ /**
143
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
144
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
145
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
146
+ * approach is to create a new instance and initialize that instance.
147
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
148
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
149
+ * @param isAsync - Can the unload be performed asynchronously (default)
150
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
151
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
152
+ */
153
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
154
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
155
+ /**
156
+ * Add a new plugin to the installation
157
+ * @param plugin - The new plugin to add
158
+ * @param replaceExisting - should any existing plugin be replaced, default is false
159
+ * @param doAsync - Should the add be performed asynchronously
160
+ * @param addCb - [Optional] callback to call after the plugin has been added
161
+ */
162
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
163
+ /**
164
+ * Returns the unique event namespace that should be used
165
+ */
166
+ evtNamespace(): string;
167
+ /**
168
+ * Add an unload handler that will be called when the SDK is being unloaded
169
+ * @param handler - the handler
170
+ */
171
+ addUnloadCb(handler: UnloadHandler): void;
172
+ /**
173
+ * Flush and send any batched / cached data immediately
174
+ * @param async - send data asynchronously when true (defaults to true)
175
+ * @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.
176
+ * If the caller doesn't return true the caller should assume that it may never be called.
177
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
178
+ * @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
179
+ */
180
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): void;
97
181
  protected releaseQueue(): void;
182
+ /**
183
+ * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
184
+ * @param updateCtx - The plugin update context
185
+ * @param updateState - The Update State
186
+ * @returns boolean - True means the extension class will call updateState otherwise the Core will
187
+ */
188
+ protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
98
189
  }
99
190
 
100
191
  /**
@@ -103,6 +194,13 @@ declare namespace ApplicationInsights {
103
194
  * implementation so that new default implementations can be added without breaking all plugins.
104
195
  */
105
196
  abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
197
+ identifier: string;
198
+ version?: string;
199
+ /**
200
+ * Holds the core instance that was used during initialization
201
+ */
202
+ core: IAppInsightsCore;
203
+ priority: number;
106
204
  /**
107
205
  * Call back for telemetry processing before it it is sent
108
206
  * @param env - This is the current event being reported
@@ -124,13 +222,6 @@ declare namespace ApplicationInsights {
124
222
  * Returns whether the plugin has been initialized
125
223
  */
126
224
  isInitialized: () => boolean;
127
- identifier: string;
128
- version?: string;
129
- /**
130
- * Holds the core instance that was used during initialization
131
- */
132
- core: IAppInsightsCore;
133
- priority: number;
134
225
  /**
135
226
  * Helper to return the current IProcessTelemetryContext, if the passed argument exists this just
136
227
  * returns that value (helps with minification for callers), otherwise it will return the configured
@@ -143,12 +234,51 @@ declare namespace ApplicationInsights {
143
234
  */
144
235
  protected setInitialized: (isInitialized: boolean) => void;
145
236
  /**
146
- * Internal helper to initialize the instance
237
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
238
+ * finishes it's removal.
239
+ * @param unloadCtx - This is the context that should be used during unloading.
240
+ * @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.
241
+ * @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.
242
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
243
+ */
244
+ protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
245
+ /**
246
+ * Extension hook to allow implementations to perform some additional update operations before the BaseTelemetryPlugin finishes it's removal
247
+ * @param updateCtx - This is the context that should be used during updating.
248
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
249
+ * @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.
250
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
147
251
  */
148
- private _baseTelInit;
252
+ protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
149
253
  constructor();
150
254
  initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
255
+ /**
256
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
257
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
258
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
259
+ * @param unloadCtx - This is the context that should be used during unloading.
260
+ * @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.
261
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
262
+ */
263
+ teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
151
264
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
265
+ /**
266
+ * The the plugin should re-evaluate configuration and update any cached configuration settings.
267
+ * @param updateCtx - This is the context that should be used during updating.
268
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
269
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
270
+ */
271
+ update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
272
+ /**
273
+ * Add an unload handler that will be called when the SDK is being unloaded
274
+ * @param handler - the handler
275
+ */
276
+ protected _addUnloadCb(handler: UnloadHandler): void;
277
+ /**
278
+ * Add this hook so that it is automatically removed during unloading
279
+ * @param hooks - The single hook or an array of IInstrumentHook objects
280
+ */
281
+ protected _addHook(hooks: IInstrumentHook | IInstrumentHook[]): void;
152
282
  }
153
283
 
154
284
  /**
@@ -159,7 +289,15 @@ declare namespace ApplicationInsights {
159
289
  */
160
290
  const CoreUtils: ICoreUtils;
161
291
 
162
- enum DistributedTracingModes {
292
+ const DistributedTracingModes: EnumValue< {
293
+ AI: number;
294
+ AI_AND_W3C: number;
295
+ W3C: number;
296
+ }>;
297
+
298
+ type DistributedTracingModes = number | eDistributedTracingModes;
299
+
300
+ const enum eDistributedTracingModes {
163
301
  /**
164
302
  * (Default) Send Application Insights correlation headers
165
303
  */
@@ -174,6 +312,112 @@ declare namespace ApplicationInsights {
174
312
  W3C = 2
175
313
  }
176
314
 
315
+ const enum _eInternalMessageId {
316
+ BrowserDoesNotSupportLocalStorage = 0,
317
+ BrowserCannotReadLocalStorage = 1,
318
+ BrowserCannotReadSessionStorage = 2,
319
+ BrowserCannotWriteLocalStorage = 3,
320
+ BrowserCannotWriteSessionStorage = 4,
321
+ BrowserFailedRemovalFromLocalStorage = 5,
322
+ BrowserFailedRemovalFromSessionStorage = 6,
323
+ CannotSendEmptyTelemetry = 7,
324
+ ClientPerformanceMathError = 8,
325
+ ErrorParsingAISessionCookie = 9,
326
+ ErrorPVCalc = 10,
327
+ ExceptionWhileLoggingError = 11,
328
+ FailedAddingTelemetryToBuffer = 12,
329
+ FailedMonitorAjaxAbort = 13,
330
+ FailedMonitorAjaxDur = 14,
331
+ FailedMonitorAjaxOpen = 15,
332
+ FailedMonitorAjaxRSC = 16,
333
+ FailedMonitorAjaxSend = 17,
334
+ FailedMonitorAjaxGetCorrelationHeader = 18,
335
+ FailedToAddHandlerForOnBeforeUnload = 19,
336
+ FailedToSendQueuedTelemetry = 20,
337
+ FailedToReportDataLoss = 21,
338
+ FlushFailed = 22,
339
+ MessageLimitPerPVExceeded = 23,
340
+ MissingRequiredFieldSpecification = 24,
341
+ NavigationTimingNotSupported = 25,
342
+ OnError = 26,
343
+ SessionRenewalDateIsZero = 27,
344
+ SenderNotInitialized = 28,
345
+ StartTrackEventFailed = 29,
346
+ StopTrackEventFailed = 30,
347
+ StartTrackFailed = 31,
348
+ StopTrackFailed = 32,
349
+ TelemetrySampledAndNotSent = 33,
350
+ TrackEventFailed = 34,
351
+ TrackExceptionFailed = 35,
352
+ TrackMetricFailed = 36,
353
+ TrackPVFailed = 37,
354
+ TrackPVFailedCalc = 38,
355
+ TrackTraceFailed = 39,
356
+ TransmissionFailed = 40,
357
+ FailedToSetStorageBuffer = 41,
358
+ FailedToRestoreStorageBuffer = 42,
359
+ InvalidBackendResponse = 43,
360
+ FailedToFixDepricatedValues = 44,
361
+ InvalidDurationValue = 45,
362
+ TelemetryEnvelopeInvalid = 46,
363
+ CreateEnvelopeError = 47,
364
+ CannotSerializeObject = 48,
365
+ CannotSerializeObjectNonSerializable = 49,
366
+ CircularReferenceDetected = 50,
367
+ ClearAuthContextFailed = 51,
368
+ ExceptionTruncated = 52,
369
+ IllegalCharsInName = 53,
370
+ ItemNotInArray = 54,
371
+ MaxAjaxPerPVExceeded = 55,
372
+ MessageTruncated = 56,
373
+ NameTooLong = 57,
374
+ SampleRateOutOfRange = 58,
375
+ SetAuthContextFailed = 59,
376
+ SetAuthContextFailedAccountName = 60,
377
+ StringValueTooLong = 61,
378
+ StartCalledMoreThanOnce = 62,
379
+ StopCalledWithoutStart = 63,
380
+ TelemetryInitializerFailed = 64,
381
+ TrackArgumentsNotSpecified = 65,
382
+ UrlTooLong = 66,
383
+ SessionStorageBufferFull = 67,
384
+ CannotAccessCookie = 68,
385
+ IdTooLong = 69,
386
+ InvalidEvent = 70,
387
+ FailedMonitorAjaxSetRequestHeader = 71,
388
+ SendBrowserInfoOnUserInit = 72,
389
+ PluginException = 73,
390
+ NotificationException = 74,
391
+ SnippetScriptLoadFailure = 99,
392
+ InvalidInstrumentationKey = 100,
393
+ CannotParseAiBlobValue = 101,
394
+ InvalidContentBlob = 102,
395
+ TrackPageActionEventFailed = 103,
396
+ FailedAddingCustomDefinedRequestContext = 104,
397
+ InMemoryStorageBufferFull = 105
398
+ }
399
+
400
+ const enum eLoggingSeverity {
401
+ /**
402
+ * Error will be sent as internal telemetry
403
+ */
404
+ CRITICAL = 1,
405
+ /**
406
+ * Error will NOT be sent as internal telemetry, and will only be shown in browser console
407
+ */
408
+ WARNING = 2
409
+ }
410
+
411
+ type EnumValue<E = any> = {
412
+ readonly [key in keyof E]: E[key];
413
+ };
414
+
415
+ const enum GetExtCfgMergeType {
416
+ None = 0,
417
+ MergeDefaultOnly = 1,
418
+ MergeDefaultFromRootOrDefault = 2
419
+ }
420
+
177
421
  interface IAppInsightsCore extends IPerfManagerProvider {
178
422
  config: IConfiguration;
179
423
  logger: IDiagnosticLogger;
@@ -209,12 +453,62 @@ declare namespace ApplicationInsights {
209
453
  * @param {INotificationListener} listener - INotificationListener to remove.
210
454
  */
211
455
  removeNotificationListener?(listener: INotificationListener): void;
456
+ /**
457
+ * Add a telemetry processor to decorate or drop telemetry events.
458
+ * @param telemetryInitializer - The Telemetry Initializer function
459
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
460
+ */
461
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
212
462
  pollInternalLogs?(eventName?: string): number;
213
463
  stopPollingInternalLogs?(): void;
214
464
  /**
215
465
  * Return a new instance of the IProcessTelemetryContext for processing events
216
466
  */
217
467
  getProcessTelContext(): IProcessTelemetryContext;
468
+ /**
469
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
470
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
471
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
472
+ * approach is to create a new instance and initialize that instance.
473
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
474
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
475
+ * @param isAsync - Can the unload be performed asynchronously (default)
476
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
477
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
478
+ */
479
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
480
+ /**
481
+ * Find and return the (first) plugin with the specified identifier if present
482
+ * @param pluginIdentifier
483
+ */
484
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
485
+ /**
486
+ * Add a new plugin to the installation
487
+ * @param plugin - The new plugin to add
488
+ * @param replaceExisting - should any existing plugin be replaced, default is false
489
+ * @param doAsync - Should the add be performed asynchronously
490
+ * @param addCb - [Optional] callback to call after the plugin has been added
491
+ */
492
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
493
+ /**
494
+ * Returns the unique event namespace that should be used when registering events
495
+ */
496
+ evtNamespace(): string;
497
+ /**
498
+ * Add a handler that will be called when the SDK is being unloaded
499
+ * @param handler - the handler
500
+ */
501
+ addUnloadCb(handler: UnloadHandler): void;
502
+ /**
503
+ * Flush and send any batched / cached data immediately
504
+ * @param async - send data asynchronously when true (defaults to true)
505
+ * @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.
506
+ * If the caller doesn't return true the caller should assume that it may never be called.
507
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
508
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
509
+ * @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
510
+ */
511
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
218
512
  }
219
513
 
220
514
  /**
@@ -298,6 +592,67 @@ declare namespace ApplicationInsights {
298
592
  readonly appId?: string;
299
593
  }
300
594
 
595
+ interface IBaseProcessingContext {
596
+ /**
597
+ * The current core instance for the request
598
+ */
599
+ core: () => IAppInsightsCore;
600
+ /**
601
+ * THe current diagnostic logger for the request
602
+ */
603
+ diagLog: () => IDiagnosticLogger;
604
+ /**
605
+ * Gets the current core config instance
606
+ */
607
+ getCfg: () => IConfiguration;
608
+ /**
609
+ * Gets the named extension config
610
+ */
611
+ getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
612
+ /**
613
+ * Gets the named config from either the named identifier extension or core config if neither exist then the
614
+ * default value is returned
615
+ * @param identifier The named extension identifier
616
+ * @param field The config field name
617
+ * @param defaultValue The default value to return if no defined config exists
618
+ */
619
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
620
+ /**
621
+ * Helper to allow plugins to check and possibly shortcut executing code only
622
+ * required if there is a nextPlugin
623
+ */
624
+ hasNext: () => boolean;
625
+ /**
626
+ * Returns the next configured plugin proxy
627
+ */
628
+ getNext: () => ITelemetryPluginChain;
629
+ /**
630
+ * Helper to set the next plugin proxy
631
+ */
632
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
633
+ /**
634
+ * Synchronously iterate over the context chain running the callback for each plugin, once
635
+ * every plugin has been executed via the callback, any associated onComplete will be called.
636
+ * @param callback - The function call for each plugin in the context chain
637
+ */
638
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
639
+ /**
640
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
641
+ * @param onComplete - The onComplete to call
642
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
643
+ * @param args - Any additional arguments to pass to the onComplete function
644
+ */
645
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
646
+ /**
647
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
648
+ * @param plugins - The execution order to process the plugins, if null or not supplied
649
+ * then the current execution order will be copied.
650
+ * @param startAt - The plugin to start processing from, if missing from the execution
651
+ * order then the next plugin will be NOT set.
652
+ */
653
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
654
+ }
655
+
301
656
  /**
302
657
  * Provides data transmission capabilities
303
658
  */
@@ -311,15 +666,23 @@ declare namespace ApplicationInsights {
311
666
  */
312
667
  resume(): void;
313
668
  /**
314
- * Tear down transmission pipeline
669
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
670
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
671
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
672
+ * @param unloadCtx - This is the context that should be used during unloading.
673
+ * @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.
674
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
315
675
  */
316
- teardown(): void;
676
+ teardown: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
317
677
  /**
318
678
  * Flush to send data immediately; channel should default to sending data asynchronously
319
- * @param async: send data asynchronously when true
320
- * @param callBack: if specified, notify caller when send is complete
679
+ * @param async - send data asynchronously when true
680
+ * @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.
681
+ * If the caller doesn't return true the caller should assume that it may never be called.
682
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
683
+ * @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
321
684
  */
322
- flush(async: boolean, callBack?: () => void): void;
685
+ flush(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void;
323
686
  }
324
687
 
325
688
  interface IChannelControlsAI extends IChannelControls {
@@ -994,7 +1357,7 @@ declare namespace ApplicationInsights {
994
1357
  * @param callback {any} - The callback function that needs to be executed for the given event
995
1358
  * @return {boolean} - true if the handler was successfully added
996
1359
  */
997
- addEventHandler: (eventName: string, callback: any) => boolean;
1360
+ addEventHandler: (eventName: string, callback: any, evtNamespace?: string | string[]) => boolean;
998
1361
  /**
999
1362
  * 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)
1000
1363
  * https://caniuse.com/#search=Date.now
@@ -1127,15 +1490,39 @@ declare namespace ApplicationInsights {
1127
1490
  }
1128
1491
 
1129
1492
  interface IEnvelope extends ISerializable {
1493
+ /**
1494
+ * 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.
1495
+ */
1130
1496
  ver: number;
1497
+ /**
1498
+ * Type name of telemetry data item.
1499
+ */
1131
1500
  name: string;
1501
+ /**
1502
+ * 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.
1503
+ */
1132
1504
  time: string;
1505
+ /**
1506
+ * Sampling rate used in application. This telemetry item represents 1 / sampleRate actual telemetry items.
1507
+ */
1133
1508
  sampleRate: number;
1509
+ /**
1510
+ * Sequence field used to track absolute order of uploaded events.
1511
+ */
1134
1512
  seq: string;
1513
+ /**
1514
+ * 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.
1515
+ */
1135
1516
  iKey: string;
1517
+ /**
1518
+ * Key/value collection of context properties. See ContextTagKeys for information on available properties.
1519
+ */
1136
1520
  tags: {
1137
1521
  [name: string]: any;
1138
1522
  };
1523
+ /**
1524
+ * Telemetry data item.
1525
+ */
1139
1526
  data: any;
1140
1527
  }
1141
1528
 
@@ -1154,6 +1541,96 @@ declare namespace ApplicationInsights {
1154
1541
  iKey?: string;
1155
1542
  }
1156
1543
 
1544
+ interface IInstrumentCallDetails {
1545
+ name: string;
1546
+ inst: any;
1547
+ /**
1548
+ * This returns an object that the hook function can use to store hook specific
1549
+ * context, it it not shared with any other hook instances and is unique for the
1550
+ * current call.
1551
+ * A hook implementation can use this to pass / share context between different
1552
+ * hook callbacks eg. request/response requst/hookErrors etc.
1553
+ */
1554
+ ctx: () => any;
1555
+ /**
1556
+ * Allows the hook functions to replace the original arguments
1557
+ * @param idx - The argument index (0 based)
1558
+ * @param value - The new value for the argument
1559
+ */
1560
+ set: (idx: number, value: any) => void;
1561
+ /**
1562
+ * The result of the original method, only populated after the original method has returned
1563
+ */
1564
+ rslt?: any;
1565
+ /**
1566
+ * The error (exception) which occurred while executing the original method
1567
+ */
1568
+ err?: Error;
1569
+ /**
1570
+ * The Event object from (window.event) at the start of the original call
1571
+ */
1572
+ evt?: Event;
1573
+ }
1574
+
1575
+ /**
1576
+ * The holder of the specific instance callback
1577
+ */
1578
+ interface IInstrumentHook {
1579
+ /** Unique Id for this callback on the hooked method */
1580
+ id: number;
1581
+ /** Holds the callbacks */
1582
+ cbks: IInstrumentHooksCallbacks;
1583
+ /** Remove this hook from the function */
1584
+ rm: () => void;
1585
+ }
1586
+
1587
+ /**
1588
+ * The callbacks to call for the instrumented function, you must provide at least the request and/or response callbacks, both are not required.
1589
+ * You must always supply the error callback
1590
+ */
1591
+ interface IInstrumentHooksCallbacks {
1592
+ /**
1593
+ * [Optional] Namespace details (same as the namespace used for events), useful for debugging and testing to
1594
+ * identify the source of the instrumented hooks
1595
+ */
1596
+ ns?: string | string[];
1597
+ /**
1598
+ * The hook callback to call before the original function is called
1599
+ */
1600
+ req?: InstrumentorHooksCallback;
1601
+ /**
1602
+ * The hook callback to call after the original function was called
1603
+ */
1604
+ rsp?: InstrumentorHooksCallback;
1605
+ /**
1606
+ * The callback to call if the hook function causes an exception
1607
+ */
1608
+ hkErr?: InstrumentorHooksCallback;
1609
+ /**
1610
+ * The callback to call if the original function causes an exception, even if you
1611
+ * supply a callback the original exception will still be thrown
1612
+ */
1613
+ fnErr?: InstrumentorHooksCallback;
1614
+ }
1615
+
1616
+ interface ILoadedPlugin<T extends IPlugin> {
1617
+ plugin: T;
1618
+ /**
1619
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
1620
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
1621
+ * @returns boolean = true if the plugin is in a state where it is operational.
1622
+ */
1623
+ isEnabled: () => boolean;
1624
+ /**
1625
+ * You can optionally enable / disable a plugin from processing events.
1626
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
1627
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
1628
+ * (unless it's also been re-initialized)
1629
+ */
1630
+ setEnabled: (isEnabled: boolean) => void;
1631
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
1632
+ }
1633
+
1157
1634
  interface IMetricTelemetry extends IPartC {
1158
1635
  /**
1159
1636
  * @description (required) - name of this metric
@@ -1272,6 +1749,12 @@ declare namespace ApplicationInsights {
1272
1749
  perfEvent?(perfEvent: IPerfEvent): void;
1273
1750
  }
1274
1751
 
1752
+ /**
1753
+ * A callback function that will be called for the wrapped instrumentation function
1754
+ * before the original function is executed.
1755
+ */
1756
+ type InstrumentorHooksCallback = (funcArgs: IInstrumentCallDetails, ...orgArgs: any[]) => void;
1757
+
1275
1758
  class _InternalLogMessage {
1276
1759
  static dataType: string;
1277
1760
  message: string;
@@ -1282,92 +1765,9 @@ declare namespace ApplicationInsights {
1282
1765
  /**
1283
1766
  * Internal message ID. Please create a new one for every conceptually different message. Please keep alphabetically ordered
1284
1767
  */
1285
- const _InternalMessageId: {
1286
- BrowserDoesNotSupportLocalStorage: number;
1287
- BrowserCannotReadLocalStorage: number;
1288
- BrowserCannotReadSessionStorage: number;
1289
- BrowserCannotWriteLocalStorage: number;
1290
- BrowserCannotWriteSessionStorage: number;
1291
- BrowserFailedRemovalFromLocalStorage: number;
1292
- BrowserFailedRemovalFromSessionStorage: number;
1293
- CannotSendEmptyTelemetry: number;
1294
- ClientPerformanceMathError: number;
1295
- ErrorParsingAISessionCookie: number;
1296
- ErrorPVCalc: number;
1297
- ExceptionWhileLoggingError: number;
1298
- FailedAddingTelemetryToBuffer: number;
1299
- FailedMonitorAjaxAbort: number;
1300
- FailedMonitorAjaxDur: number;
1301
- FailedMonitorAjaxOpen: number;
1302
- FailedMonitorAjaxRSC: number;
1303
- FailedMonitorAjaxSend: number;
1304
- FailedMonitorAjaxGetCorrelationHeader: number;
1305
- FailedToAddHandlerForOnBeforeUnload: number;
1306
- FailedToSendQueuedTelemetry: number;
1307
- FailedToReportDataLoss: number;
1308
- FlushFailed: number;
1309
- MessageLimitPerPVExceeded: number;
1310
- MissingRequiredFieldSpecification: number;
1311
- NavigationTimingNotSupported: number;
1312
- OnError: number;
1313
- SessionRenewalDateIsZero: number;
1314
- SenderNotInitialized: number;
1315
- StartTrackEventFailed: number;
1316
- StopTrackEventFailed: number;
1317
- StartTrackFailed: number;
1318
- StopTrackFailed: number;
1319
- TelemetrySampledAndNotSent: number;
1320
- TrackEventFailed: number;
1321
- TrackExceptionFailed: number;
1322
- TrackMetricFailed: number;
1323
- TrackPVFailed: number;
1324
- TrackPVFailedCalc: number;
1325
- TrackTraceFailed: number;
1326
- TransmissionFailed: number;
1327
- FailedToSetStorageBuffer: number;
1328
- FailedToRestoreStorageBuffer: number;
1329
- InvalidBackendResponse: number;
1330
- FailedToFixDepricatedValues: number;
1331
- InvalidDurationValue: number;
1332
- TelemetryEnvelopeInvalid: number;
1333
- CreateEnvelopeError: number;
1334
- CannotSerializeObject: number;
1335
- CannotSerializeObjectNonSerializable: number;
1336
- CircularReferenceDetected: number;
1337
- ClearAuthContextFailed: number;
1338
- ExceptionTruncated: number;
1339
- IllegalCharsInName: number;
1340
- ItemNotInArray: number;
1341
- MaxAjaxPerPVExceeded: number;
1342
- MessageTruncated: number;
1343
- NameTooLong: number;
1344
- SampleRateOutOfRange: number;
1345
- SetAuthContextFailed: number;
1346
- SetAuthContextFailedAccountName: number;
1347
- StringValueTooLong: number;
1348
- StartCalledMoreThanOnce: number;
1349
- StopCalledWithoutStart: number;
1350
- TelemetryInitializerFailed: number;
1351
- TrackArgumentsNotSpecified: number;
1352
- UrlTooLong: number;
1353
- SessionStorageBufferFull: number;
1354
- CannotAccessCookie: number;
1355
- IdTooLong: number;
1356
- InvalidEvent: number;
1357
- FailedMonitorAjaxSetRequestHeader: number;
1358
- SendBrowserInfoOnUserInit: number;
1359
- PluginException: number;
1360
- NotificationException: number;
1361
- SnippetScriptLoadFailure: number;
1362
- InvalidInstrumentationKey: number;
1363
- CannotParseAiBlobValue: number;
1364
- InvalidContentBlob: number;
1365
- TrackPageActionEventFailed: number;
1366
- FailedAddingCustomDefinedRequestContext: number;
1367
- InMemoryStorageBufferFull: number;
1368
- };
1768
+ const _InternalMessageId: EnumValue<typeof _eInternalMessageId>;
1369
1769
 
1370
- type _InternalMessageId = number | typeof _InternalMessageId;
1770
+ type _InternalMessageId = number | _eInternalMessageId;
1371
1771
 
1372
1772
  interface IPageViewPerformanceTelemetry extends IPartC {
1373
1773
  /**
@@ -1582,10 +1982,14 @@ declare namespace ApplicationInsights {
1582
1982
  */
1583
1983
  isInitialized?: () => boolean;
1584
1984
  /**
1585
- * Tear down the plugin and remove any hooked value, the plugin should remove that it is no longer initialized and
1586
- * therefore can be re-initialized after being torn down.
1985
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
1986
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
1987
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
1988
+ * @param unloadCtx - This is the context that should be used during unloading.
1989
+ * @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.
1990
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
1587
1991
  */
1588
- teardown?: () => void;
1992
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
1589
1993
  /**
1590
1994
  * Extension name
1591
1995
  */
@@ -1600,57 +2004,63 @@ declare namespace ApplicationInsights {
1600
2004
  * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
1601
2005
  * between multiple AppInsights instances
1602
2006
  */
1603
- interface IProcessTelemetryContext {
1604
- /**
1605
- * The current core instance for the request
1606
- */
1607
- core: () => IAppInsightsCore;
1608
- /**
1609
- * THe current diagnostic logger for the request
1610
- */
1611
- diagLog: () => IDiagnosticLogger;
1612
- /**
1613
- * Gets the current core config instance
1614
- */
1615
- getCfg: () => IConfiguration;
1616
- /**
1617
- * Gets the named extension config
1618
- */
1619
- getExtCfg: <T>(identifier: string, defaultValue?: T | any) => T;
2007
+ interface IProcessTelemetryContext extends IBaseProcessingContext {
1620
2008
  /**
1621
- * Gets the named config from either the named identifier extension or core config if neither exist then the
1622
- * default value is returned
1623
- * @param identifier The named extension identifier
1624
- * @param field The config field name
1625
- * @param defaultValue The default value to return if no defined config exists
2009
+ * Call back for telemetry processing before it it is sent
2010
+ * @param env - This is the current event being reported
2011
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1626
2012
  */
1627
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
2013
+ processNext: (env: ITelemetryItem) => boolean | void;
1628
2014
  /**
1629
- * Helper to allow plugins to check and possibly shortcut executing code only
1630
- * required if there is a nextPlugin
2015
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
2016
+ * @param plugins - The execution order to process the plugins, if null or not supplied
2017
+ * then the current execution order will be copied.
2018
+ * @param startAt - The plugin to start processing from, if missing from the execution
2019
+ * order then the next plugin will be NOT set.
1631
2020
  */
1632
- hasNext: () => boolean;
2021
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
2022
+ }
2023
+
2024
+ /**
2025
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
2026
+ * or the SDK is being unloaded.
2027
+ */
2028
+ interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
1633
2029
  /**
1634
- * Returns the next configured plugin proxy
2030
+ * This Plugin has finished unloading, so unload the next one
2031
+ * @param uploadState - The state of the unload process
2032
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1635
2033
  */
1636
- getNext: () => ITelemetryPluginChain;
2034
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
1637
2035
  /**
1638
- * Helper to set the next plugin proxy
2036
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
2037
+ * @param plugins - The execution order to process the plugins, if null or not supplied
2038
+ * then the current execution order will be copied.
2039
+ * @param startAt - The plugin to start processing from, if missing from the execution
2040
+ * order then the next plugin will be NOT set.
1639
2041
  */
1640
- setNext: (nextCtx: ITelemetryPluginChain) => void;
2042
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
2043
+ }
2044
+
2045
+ /**
2046
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
2047
+ * for when plugins are added, removed or the configuration was changed.
2048
+ */
2049
+ interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
1641
2050
  /**
1642
- * Call back for telemetry processing before it it is sent
1643
- * @param env - This is the current event being reported
2051
+ * This Plugin has finished unloading, so unload the next one
2052
+ * @param updateState - The update State
2053
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1644
2054
  */
1645
- processNext: (env: ITelemetryItem) => void;
2055
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
1646
2056
  /**
1647
- * Create a new context using the core and config from the current instance
2057
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1648
2058
  * @param plugins - The execution order to process the plugins, if null or not supplied
1649
2059
  * then the current execution order will be copied.
1650
2060
  * @param startAt - The plugin to start processing from, if missing from the execution
1651
2061
  * order then the next plugin will be NOT set.
1652
2062
  */
1653
- createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
2063
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
1654
2064
  }
1655
2065
 
1656
2066
  interface IRequestContext {
@@ -1787,11 +2197,17 @@ declare namespace ApplicationInsights {
1787
2197
  aiDataContract: any;
1788
2198
  }
1789
2199
 
2200
+ function isNullOrUndefined(value: any): value is null | undefined;
2201
+
1790
2202
  interface IStackDetails {
1791
2203
  src: string;
1792
2204
  obj: string[];
1793
2205
  }
1794
2206
 
2207
+ interface ITelemetryInitializerHandler {
2208
+ remove(): void;
2209
+ }
2210
+
1795
2211
  /**
1796
2212
  * Telemety item supported in Core
1797
2213
  */
@@ -1841,15 +2257,7 @@ declare namespace ApplicationInsights {
1841
2257
  /**
1842
2258
  * Configuration provided to SDK core
1843
2259
  */
1844
- interface ITelemetryPlugin extends IPlugin {
1845
- /**
1846
- * Call back for telemetry processing before it it is sent
1847
- * @param env - This is the current event being reported
1848
- * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
1849
- * can optionally use this to access the current core instance or define / pass additional information
1850
- * to later plugins (vs appending items to the telemetry item)
1851
- */
1852
- processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2260
+ interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
1853
2261
  /**
1854
2262
  * Set next extension for telemetry processing, this is not optional as plugins should use the
1855
2263
  * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
@@ -1865,7 +2273,7 @@ declare namespace ApplicationInsights {
1865
2273
  /**
1866
2274
  * Configuration provided to SDK core
1867
2275
  */
1868
- interface ITelemetryPluginChain {
2276
+ interface ITelemetryPluginChain extends ITelemetryProcessor {
1869
2277
  /**
1870
2278
  * Returns the underlying plugin that is being proxied for the processTelemetry call
1871
2279
  */
@@ -1874,6 +2282,16 @@ declare namespace ApplicationInsights {
1874
2282
  * Returns the next plugin
1875
2283
  */
1876
2284
  getNext: () => ITelemetryPluginChain;
2285
+ /**
2286
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
2287
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
2288
+ * @param unloadCtx - The unload context to use for this call.
2289
+ * @param unloadState - The details of the unload operation
2290
+ */
2291
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2292
+ }
2293
+
2294
+ interface ITelemetryProcessor {
1877
2295
  /**
1878
2296
  * Call back for telemetry processing before it it is sent
1879
2297
  * @param env - This is the current event being reported
@@ -1881,7 +2299,43 @@ declare namespace ApplicationInsights {
1881
2299
  * can optionally use this to access the current core instance or define / pass additional information
1882
2300
  * to later plugins (vs appending items to the telemetry item)
1883
2301
  */
1884
- processTelemetry: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
2302
+ processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2303
+ /**
2304
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
2305
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
2306
+ * the configuration has bee updated.
2307
+ * @param updateCtx - This is the context that should be used during updating.
2308
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
2309
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
2310
+ */
2311
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
2312
+ }
2313
+
2314
+ interface ITelemetryUnloadState {
2315
+ reason: TelemetryUnloadReason;
2316
+ isAsync: boolean;
2317
+ flushComplete?: boolean;
2318
+ }
2319
+
2320
+ interface ITelemetryUpdateState {
2321
+ /**
2322
+ * Identifies the reason for the update notification, this is a bitwise numeric value
2323
+ */
2324
+ reason: TelemetryUpdateReason;
2325
+ /**
2326
+ * If this is a configuration update this was the previous configuration that was used
2327
+ */
2328
+ /**
2329
+ * If this is a configuration update is the new configuration that is being used
2330
+ */
2331
+ /**
2332
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
2333
+ */
2334
+ added?: IPlugin[];
2335
+ /**
2336
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
2337
+ */
2338
+ removed?: IPlugin[];
1885
2339
  }
1886
2340
 
1887
2341
  interface ITraceTelemetry extends IPartC {
@@ -1905,16 +2359,19 @@ declare namespace ApplicationInsights {
1905
2359
  iKey?: string;
1906
2360
  }
1907
2361
 
1908
- enum LoggingSeverity {
1909
- /**
1910
- * Error will be sent as internal telemetry
1911
- */
1912
- CRITICAL = 1,
1913
- /**
1914
- * Error will NOT be sent as internal telemetry, and will only be shown in browser console
1915
- */
1916
- WARNING = 2
1917
- }
2362
+ const LoggingSeverity: EnumValue<typeof eLoggingSeverity>;
2363
+
2364
+ type LoggingSeverity = number | eLoggingSeverity;
2365
+
2366
+ /**
2367
+ * Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.
2368
+ *
2369
+ * @param target - The target object to be assigned with the source properties and functions
2370
+ * @param source - The source object which will be assigned / called by setting / calling the targets proxies
2371
+ * @param functionsToProxy - An array of function names that will be proxied on the target
2372
+ * @param overwriteTarget - If false this will not replace any pre-existing name otherwise (the default) it will overwrite any existing name
2373
+ */
2374
+ function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget?: boolean): T;
1918
2375
 
1919
2376
  class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
1920
2377
  static constructEnvelope(orig: ITelemetryItem, iKey: string, logger: IDiagnosticLogger, convertUndefined?: any): IEnvelope;
@@ -1960,7 +2417,6 @@ declare namespace ApplicationInsights {
1960
2417
  * Will not flush if the Send has been paused.
1961
2418
  */
1962
2419
  onunloadFlush(): void;
1963
- teardown(): void;
1964
2420
  initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
1965
2421
  processTelemetry(telemetryItem: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
1966
2422
  /**
@@ -2031,6 +2487,10 @@ declare namespace ApplicationInsights {
2031
2487
  * The event(s) being sent as a retry
2032
2488
  */
2033
2489
  Retry = 5,
2490
+ /**
2491
+ * The SDK is unloading
2492
+ */
2493
+ SdkUnload = 6,
2034
2494
  /**
2035
2495
  * Maximum batch size would be exceeded
2036
2496
  */
@@ -2056,6 +2516,55 @@ declare namespace ApplicationInsights {
2056
2516
  [key: string]: any;
2057
2517
  }
2058
2518
 
2519
+ type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
2520
+
2521
+ /**
2522
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
2523
+ */
2524
+ const enum TelemetryUnloadReason {
2525
+ /**
2526
+ * Teardown has been called without any context.
2527
+ */
2528
+ ManualTeardown = 0,
2529
+ /**
2530
+ * Just this plugin is being removed
2531
+ */
2532
+ PluginUnload = 1,
2533
+ /**
2534
+ * This instance of the plugin is being removed and replaced
2535
+ */
2536
+ PluginReplace = 2,
2537
+ /**
2538
+ * The entire SDK is being unloaded
2539
+ */
2540
+ SdkUnload = 50
2541
+ }
2542
+
2543
+ /**
2544
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
2545
+ */
2546
+ const enum TelemetryUpdateReason {
2547
+ /**
2548
+ * Unknown.
2549
+ */
2550
+ Unknown = 0,
2551
+ /**
2552
+ * The configuration has ben updated or changed
2553
+ */
2554
+ /**
2555
+ * One or more plugins have been added
2556
+ */
2557
+ PluginAdded = 16,
2558
+ /**
2559
+ * One or more plugins have been removed
2560
+ */
2561
+ PluginRemoved = 32
2562
+ }
2563
+
2564
+ function throwError(message: string): never;
2565
+
2566
+ type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2567
+
2059
2568
  interface XDomainRequest extends XMLHttpRequestEventTarget {
2060
2569
  readonly responseText: string;
2061
2570
  send(payload: string): void;