@microsoft/applicationinsights-teechannel-js 3.1.0-nightly3.2402-09 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/browser/es5/{applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.cjs.js → applicationinsights-teechannel-js.3.1.0.cjs.js} +2 -2
  2. package/browser/es5/applicationinsights-teechannel-js.3.1.0.cjs.js.map +1 -0
  3. package/browser/es5/{applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.cjs.min.js → applicationinsights-teechannel-js.3.1.0.cjs.min.js} +2 -2
  4. package/browser/es5/applicationinsights-teechannel-js.3.1.0.cjs.min.js.map +1 -0
  5. package/browser/es5/{applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.gbl.js → applicationinsights-teechannel-js.3.1.0.gbl.js} +4 -4
  6. package/browser/es5/applicationinsights-teechannel-js.3.1.0.gbl.js.map +1 -0
  7. package/browser/es5/applicationinsights-teechannel-js.3.1.0.gbl.min.js +6 -0
  8. package/browser/es5/applicationinsights-teechannel-js.3.1.0.gbl.min.js.map +1 -0
  9. package/browser/es5/applicationinsights-teechannel-js.3.1.0.integrity.json +66 -0
  10. package/browser/es5/{applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.js → applicationinsights-teechannel-js.3.1.0.js} +4 -4
  11. package/browser/es5/applicationinsights-teechannel-js.3.1.0.js.map +1 -0
  12. package/browser/es5/applicationinsights-teechannel-js.3.1.0.min.js +6 -0
  13. package/browser/es5/applicationinsights-teechannel-js.3.1.0.min.js.map +1 -0
  14. package/browser/es5/applicationinsights-teechannel-js.3.cjs.js +1 -1
  15. package/browser/es5/applicationinsights-teechannel-js.3.cjs.js.map +1 -1
  16. package/browser/es5/applicationinsights-teechannel-js.3.cjs.min.js +1 -1
  17. package/browser/es5/applicationinsights-teechannel-js.3.cjs.min.js.map +1 -1
  18. package/browser/es5/applicationinsights-teechannel-js.3.gbl.js +3 -3
  19. package/browser/es5/applicationinsights-teechannel-js.3.gbl.js.map +1 -1
  20. package/browser/es5/applicationinsights-teechannel-js.3.gbl.min.js +2 -2
  21. package/browser/es5/applicationinsights-teechannel-js.3.gbl.min.js.map +1 -1
  22. package/browser/es5/applicationinsights-teechannel-js.3.integrity.json +25 -25
  23. package/browser/es5/applicationinsights-teechannel-js.3.js +3 -3
  24. package/browser/es5/applicationinsights-teechannel-js.3.js.map +1 -1
  25. package/browser/es5/applicationinsights-teechannel-js.3.min.js +2 -2
  26. package/browser/es5/applicationinsights-teechannel-js.3.min.js.map +1 -1
  27. package/dist/es5/applicationinsights-teechannel-js.js +1 -1
  28. package/dist/es5/applicationinsights-teechannel-js.js.map +1 -1
  29. package/dist/es5/applicationinsights-teechannel-js.min.js +1 -1
  30. package/dist/es5/applicationinsights-teechannel-js.min.js.map +1 -1
  31. package/dist-es5/ChannelController.js +1 -1
  32. package/dist-es5/Interfaces/ITeeChannelConfig.js +1 -1
  33. package/dist-es5/TeeChannel.js +1 -1
  34. package/dist-es5/__DynamicConstants.js +1 -1
  35. package/dist-es5/applicationinsights-teechannel-js.js +1 -1
  36. package/package.json +63 -66
  37. package/types/applicationinsights-teechannel-js.d.ts +2 -2
  38. package/types/applicationinsights-teechannel-js.namespaced.d.ts +2428 -18
  39. package/browser/es5/applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.cjs.js.map +0 -1
  40. package/browser/es5/applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.cjs.min.js.map +0 -1
  41. package/browser/es5/applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.gbl.js.map +0 -1
  42. package/browser/es5/applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.gbl.min.js +0 -6
  43. package/browser/es5/applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.gbl.min.js.map +0 -1
  44. package/browser/es5/applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.integrity.json +0 -66
  45. package/browser/es5/applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.js.map +0 -1
  46. package/browser/es5/applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.min.js +0 -6
  47. package/browser/es5/applicationinsights-teechannel-js.3.1.0-nightly3.2402-09.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights JavaScript SDK Tee Channel, 3.1.0-nightly3.2402-09
2
+ * Microsoft Application Insights JavaScript SDK Tee Channel, 3.1.0
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -7,22 +7,1942 @@
7
7
  */
8
8
 
9
9
  declare namespace ApplicationInsights {
10
- import { BaseTelemetryPlugin } from '@microsoft/applicationinsights-core-js';
11
- import { IAppInsightsCore } from '@microsoft/applicationinsights-core-js';
12
- import { IChannelControls } from '@microsoft/applicationinsights-core-js';
13
- import { IChannelControlsHost } from '@microsoft/applicationinsights-core-js';
14
- import { IConfig } from '@microsoft/applicationinsights-common';
15
- import { IConfiguration } from '@microsoft/applicationinsights-core-js';
16
- import { IPlugin } from '@microsoft/applicationinsights-core-js';
17
- import { IProcessTelemetryContext } from '@microsoft/applicationinsights-core-js';
18
- import { IProcessTelemetryUnloadContext } from '@microsoft/applicationinsights-core-js';
19
- import { IProcessTelemetryUpdateContext } from '@microsoft/applicationinsights-core-js';
20
- import { IPromise } from '@nevware21/ts-async';
21
- import { ITelemetryItem } from '@microsoft/applicationinsights-core-js';
22
- import { ITelemetryPluginChain } from '@microsoft/applicationinsights-core-js';
23
- import { ITelemetryUnloadState } from '@microsoft/applicationinsights-core-js';
24
- import { ITelemetryUpdateState } from '@microsoft/applicationinsights-core-js';
25
- import { SendRequestReason } from '@microsoft/applicationinsights-core-js';
10
+ /**
11
+ * BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins
12
+ * can avoid implementation the same set of boiler plate code as well as provide a base
13
+ * implementation so that new default implementations can be added without breaking all plugins.
14
+ */
15
+ abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
16
+ identifier: string;
17
+ version?: string;
18
+ /**
19
+ * Holds the core instance that was used during initialization
20
+ */
21
+ core: IAppInsightsCore;
22
+ priority: number;
23
+ /**
24
+ * Call back for telemetry processing before it it is sent
25
+ * @param env - This is the current event being reported
26
+ * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
27
+ * can optionally use this to access the current core instance or define / pass additional information
28
+ * to later plugins (vs appending items to the telemetry item)
29
+ */
30
+ processNext: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
31
+ /**
32
+ * Set next extension for telemetry processing
33
+ */
34
+ setNextPlugin: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
35
+ /**
36
+ * Returns the current diagnostic logger that can be used to log issues, if no logger is currently
37
+ * assigned a new default one will be created and returned.
38
+ */
39
+ diagLog: (itemCtx?: IProcessTelemetryContext) => IDiagnosticLogger;
40
+ /**
41
+ * Returns whether the plugin has been initialized
42
+ */
43
+ isInitialized: () => boolean;
44
+ /**
45
+ * Helper to return the current IProcessTelemetryContext, if the passed argument exists this just
46
+ * returns that value (helps with minification for callers), otherwise it will return the configured
47
+ * context or a temporary one.
48
+ * @param currentCtx - [Optional] The current execution context
49
+ */
50
+ protected _getTelCtx: (currentCtx?: IProcessTelemetryContext) => IProcessTelemetryContext;
51
+ /**
52
+ * Internal helper to allow setting of the internal initialized setting for inherited instances and unit testing
53
+ */
54
+ protected setInitialized: (isInitialized: boolean) => void;
55
+ /**
56
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
57
+ * finishes it's removal.
58
+ * @param unloadCtx - This is the context that should be used during unloading.
59
+ * @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.
60
+ * @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.
61
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
62
+ */
63
+ protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
64
+ /**
65
+ * Extension hook to allow implementations to perform some additional update operations before the BaseTelemetryPlugin finishes it's removal
66
+ * @param updateCtx - This is the context that should be used during updating.
67
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
68
+ * @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.
69
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
70
+ */
71
+ protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
72
+ /**
73
+ * Exposes the underlying unload hook container instance for this extension to allow it to be passed down to any sub components of the class.
74
+ * This should NEVER be exposed or called publically as it's scope is for internal use by BaseTelemetryPlugin and any derived class (which is why
75
+ * it's scoped as protected)
76
+ */
77
+ protected readonly _unloadHooks: IUnloadHookContainer;
78
+ constructor();
79
+ initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
80
+ /**
81
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
82
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
83
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
84
+ * @param unloadCtx - This is the context that should be used during unloading.
85
+ * @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.
86
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
87
+ */
88
+ teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
89
+ abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
90
+ /**
91
+ * The the plugin should re-evaluate configuration and update any cached configuration settings.
92
+ * @param updateCtx - This is the context that should be used during updating.
93
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
94
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
95
+ */
96
+ update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
97
+ /**
98
+ * Add an unload handler that will be called when the SDK is being unloaded
99
+ * @param handler - the handler
100
+ */
101
+ protected _addUnloadCb(handler: UnloadHandler): void;
102
+ /**
103
+ * Add this hook so that it is automatically removed during unloading
104
+ * @param hooks - The single hook or an array of IInstrumentHook objects
105
+ */
106
+ protected _addHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>): void;
107
+ }
108
+
109
+ const DistributedTracingModes: EnumValue<typeof eDistributedTracingModes>;
110
+
111
+ type DistributedTracingModes = number | eDistributedTracingModes;
112
+
113
+ const enum eDistributedTracingModes {
114
+ /**
115
+ * (Default) Send Application Insights correlation headers
116
+ */
117
+ AI = 0,
118
+ /**
119
+ * Send both W3C Trace Context headers and back-compatibility Application Insights headers
120
+ */
121
+ AI_AND_W3C = 1,
122
+ /**
123
+ * Send W3C Trace Context headers
124
+ */
125
+ W3C = 2
126
+ }
127
+
128
+ const enum _eInternalMessageId {
129
+ BrowserDoesNotSupportLocalStorage = 0,
130
+ BrowserCannotReadLocalStorage = 1,
131
+ BrowserCannotReadSessionStorage = 2,
132
+ BrowserCannotWriteLocalStorage = 3,
133
+ BrowserCannotWriteSessionStorage = 4,
134
+ BrowserFailedRemovalFromLocalStorage = 5,
135
+ BrowserFailedRemovalFromSessionStorage = 6,
136
+ CannotSendEmptyTelemetry = 7,
137
+ ClientPerformanceMathError = 8,
138
+ ErrorParsingAISessionCookie = 9,
139
+ ErrorPVCalc = 10,
140
+ ExceptionWhileLoggingError = 11,
141
+ FailedAddingTelemetryToBuffer = 12,
142
+ FailedMonitorAjaxAbort = 13,
143
+ FailedMonitorAjaxDur = 14,
144
+ FailedMonitorAjaxOpen = 15,
145
+ FailedMonitorAjaxRSC = 16,
146
+ FailedMonitorAjaxSend = 17,
147
+ FailedMonitorAjaxGetCorrelationHeader = 18,
148
+ FailedToAddHandlerForOnBeforeUnload = 19,
149
+ FailedToSendQueuedTelemetry = 20,
150
+ FailedToReportDataLoss = 21,
151
+ FlushFailed = 22,
152
+ MessageLimitPerPVExceeded = 23,
153
+ MissingRequiredFieldSpecification = 24,
154
+ NavigationTimingNotSupported = 25,
155
+ OnError = 26,
156
+ SessionRenewalDateIsZero = 27,
157
+ SenderNotInitialized = 28,
158
+ StartTrackEventFailed = 29,
159
+ StopTrackEventFailed = 30,
160
+ StartTrackFailed = 31,
161
+ StopTrackFailed = 32,
162
+ TelemetrySampledAndNotSent = 33,
163
+ TrackEventFailed = 34,
164
+ TrackExceptionFailed = 35,
165
+ TrackMetricFailed = 36,
166
+ TrackPVFailed = 37,
167
+ TrackPVFailedCalc = 38,
168
+ TrackTraceFailed = 39,
169
+ TransmissionFailed = 40,
170
+ FailedToSetStorageBuffer = 41,
171
+ FailedToRestoreStorageBuffer = 42,
172
+ InvalidBackendResponse = 43,
173
+ FailedToFixDepricatedValues = 44,
174
+ InvalidDurationValue = 45,
175
+ TelemetryEnvelopeInvalid = 46,
176
+ CreateEnvelopeError = 47,
177
+ CannotSerializeObject = 48,
178
+ CannotSerializeObjectNonSerializable = 49,
179
+ CircularReferenceDetected = 50,
180
+ ClearAuthContextFailed = 51,
181
+ ExceptionTruncated = 52,
182
+ IllegalCharsInName = 53,
183
+ ItemNotInArray = 54,
184
+ MaxAjaxPerPVExceeded = 55,
185
+ MessageTruncated = 56,
186
+ NameTooLong = 57,
187
+ SampleRateOutOfRange = 58,
188
+ SetAuthContextFailed = 59,
189
+ SetAuthContextFailedAccountName = 60,
190
+ StringValueTooLong = 61,
191
+ StartCalledMoreThanOnce = 62,
192
+ StopCalledWithoutStart = 63,
193
+ TelemetryInitializerFailed = 64,
194
+ TrackArgumentsNotSpecified = 65,
195
+ UrlTooLong = 66,
196
+ SessionStorageBufferFull = 67,
197
+ CannotAccessCookie = 68,
198
+ IdTooLong = 69,
199
+ InvalidEvent = 70,
200
+ FailedMonitorAjaxSetRequestHeader = 71,
201
+ SendBrowserInfoOnUserInit = 72,
202
+ PluginException = 73,
203
+ NotificationException = 74,
204
+ SnippetScriptLoadFailure = 99,
205
+ InvalidInstrumentationKey = 100,
206
+ CannotParseAiBlobValue = 101,
207
+ InvalidContentBlob = 102,
208
+ TrackPageActionEventFailed = 103,
209
+ FailedAddingCustomDefinedRequestContext = 104,
210
+ InMemoryStorageBufferFull = 105,
211
+ InstrumentationKeyDeprecation = 106,
212
+ ConfigWatcherException = 107,
213
+ DynamicConfigException = 108,
214
+ DefaultThrottleMsgKey = 109,
215
+ CdnDeprecation = 110,
216
+ SdkLdrUpdate = 111
217
+ }
218
+
219
+ const enum eLoggingSeverity {
220
+ /**
221
+ * No Logging will be enabled
222
+ */
223
+ DISABLED = 0,
224
+ /**
225
+ * Error will be sent as internal telemetry
226
+ */
227
+ CRITICAL = 1,
228
+ /**
229
+ * Error will NOT be sent as internal telemetry, and will only be shown in browser console
230
+ */
231
+ WARNING = 2,
232
+ /**
233
+ * The Error will NOT be sent as an internal telemetry, and will only be shown in the browser
234
+ * console if the logging level allows it.
235
+ */
236
+ DEBUG = 3
237
+ }
238
+
239
+ /**
240
+ * A type that identifies an enum class generated from a constant enum.
241
+ * @group Enum
242
+ * @typeParam E - The constant enum type
243
+ *
244
+ * Returned from {@link createEnum}
245
+ */
246
+ type EnumCls<E = any> = {
247
+ readonly [key in keyof E extends string | number | symbol ? keyof E : never]: key extends string ? E[key] : key;
248
+ } & {
249
+ readonly [key in keyof E]: E[key];
250
+ };
251
+
252
+ type EnumValue<E = any> = EnumCls<E>;
253
+
254
+ const enum FeatureOptInMode {
255
+ /**
256
+ * not set, completely depends on cdn cfg
257
+ */
258
+ none = 1,
259
+ /**
260
+ * try to not apply config from cdn
261
+ */
262
+ disable = 2,
263
+ /**
264
+ * try to apply config from cdn
265
+ */
266
+ enable = 3
267
+ }
268
+
269
+ /**
270
+ * This defines the handler function that is called via the finally when the promise is resolved or rejected
271
+ */
272
+ type FinallyPromiseHandler = (() => void) | undefined | null;
273
+
274
+ interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider {
275
+ readonly config: CfgType;
276
+ /**
277
+ * The current logger instance for this instance.
278
+ */
279
+ readonly logger: IDiagnosticLogger;
280
+ /**
281
+ * An array of the installed plugins that provide a version
282
+ */
283
+ readonly pluginVersionStringArr: string[];
284
+ /**
285
+ * The formatted string of the installed plugins that contain a version number
286
+ */
287
+ readonly pluginVersionString: string;
288
+ /**
289
+ * Returns a value that indicates whether the instance has already been previously initialized.
290
+ */
291
+ isInitialized?: () => boolean;
292
+ initialize(config: CfgType, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
293
+ getChannels(): IChannelControls[];
294
+ track(telemetryItem: ITelemetryItem): void;
295
+ /**
296
+ * Get the current notification manager
297
+ */
298
+ getNotifyMgr(): INotificationManager;
299
+ /**
300
+ * Get the current cookie manager for this instance
301
+ */
302
+ getCookieMgr(): ICookieMgr;
303
+ /**
304
+ * Set the current cookie manager for this instance
305
+ * @param cookieMgr - The manager, if set to null/undefined will cause the default to be created
306
+ */
307
+ setCookieMgr(cookieMgr: ICookieMgr): void;
308
+ /**
309
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
310
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
311
+ * called.
312
+ * @param listener - An INotificationListener object.
313
+ */
314
+ addNotificationListener?(listener: INotificationListener): void;
315
+ /**
316
+ * Removes all instances of the listener.
317
+ * @param listener - INotificationListener to remove.
318
+ */
319
+ removeNotificationListener?(listener: INotificationListener): void;
320
+ /**
321
+ * Add a telemetry processor to decorate or drop telemetry events.
322
+ * @param telemetryInitializer - The Telemetry Initializer function
323
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
324
+ */
325
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler;
326
+ pollInternalLogs?(eventName?: string): ITimerHandler;
327
+ stopPollingInternalLogs?(): void;
328
+ /**
329
+ * Return a new instance of the IProcessTelemetryContext for processing events
330
+ */
331
+ getProcessTelContext(): IProcessTelemetryContext;
332
+ /**
333
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
334
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
335
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
336
+ * approach is to create a new instance and initialize that instance.
337
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
338
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
339
+ * If you pass isAsync as `true` (also the default) and DO NOT pass a callback function then an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
340
+ * will be returned which will resolve once the unload is complete. The actual implementation of the `IPromise`
341
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
342
+ * @param isAsync - Can the unload be performed asynchronously (default)
343
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
344
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the
345
+ * unload. Defaults to 5 seconds.
346
+ * @return Nothing or if occurring asynchronously a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
347
+ * which will be resolved once the unload is complete, the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
348
+ * will only be returned when no callback is provided and isAsync is true
349
+ */
350
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void | IPromise<ITelemetryUnloadState>;
351
+ /**
352
+ * Find and return the (first) plugin with the specified identifier if present
353
+ * @param pluginIdentifier
354
+ */
355
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
356
+ /**
357
+ * Add a new plugin to the installation
358
+ * @param plugin - The new plugin to add
359
+ * @param replaceExisting - should any existing plugin be replaced, default is false
360
+ * @param doAsync - Should the add be performed asynchronously
361
+ * @param addCb - [Optional] callback to call after the plugin has been added
362
+ */
363
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
364
+ /**
365
+ * Update the configuration used and broadcast the changes to all loaded plugins, this does NOT support updating, adding or removing
366
+ * any the plugins (extensions or channels). It will notify each plugin (if supported) that the configuration has changed but it will
367
+ * not remove or add any new plugins, you need to call addPlugin or getPlugin(identifier).remove();
368
+ * @param newConfig - The new configuration is apply
369
+ * @param mergeExisting - Should the new configuration merge with the existing or just replace it. Default is to merge.
370
+ */
371
+ updateCfg(newConfig: CfgType, mergeExisting?: boolean): void;
372
+ /**
373
+ * Returns the unique event namespace that should be used when registering events
374
+ */
375
+ evtNamespace(): string;
376
+ /**
377
+ * Add a handler that will be called when the SDK is being unloaded
378
+ * @param handler - the handler
379
+ */
380
+ addUnloadCb(handler: UnloadHandler): void;
381
+ /**
382
+ * Add this hook so that it is automatically removed during unloading
383
+ * @param hooks - The single hook or an array of IInstrumentHook objects
384
+ */
385
+ addUnloadHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>): void;
386
+ /**
387
+ * Flush and send any batched / cached data immediately
388
+ * @param async - send data asynchronously when true (defaults to true)
389
+ * @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.
390
+ * If the caller doesn't return true the caller should assume that it may never be called.
391
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
392
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
393
+ * @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
394
+ */
395
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
396
+ /**
397
+ * Gets the current distributed trace context for this instance if available
398
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
399
+ */
400
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
401
+ /**
402
+ * Sets the current distributed trace context for this instance if available
403
+ */
404
+ setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
405
+ /**
406
+ * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
407
+ * handler will be recalled.
408
+ * @param handler
409
+ * @returns A watcher handler instance that can be used to remove itself when being unloaded
410
+ */
411
+ onCfgChange(handler: WatcherFunction<CfgType>): IUnloadHook;
412
+ /**
413
+ * Function used to identify the get w parameter used to identify status bit to some channels
414
+ */
415
+ getWParam: () => number;
416
+ }
417
+
418
+ interface IBaseProcessingContext {
419
+ /**
420
+ * The current core instance for the request
421
+ */
422
+ core: () => IAppInsightsCore;
423
+ /**
424
+ * THe current diagnostic logger for the request
425
+ */
426
+ diagLog: () => IDiagnosticLogger;
427
+ /**
428
+ * Gets the current core config instance
429
+ */
430
+ getCfg: () => IConfiguration;
431
+ /**
432
+ * Gets the named extension config
433
+ */
434
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
435
+ /**
436
+ * Gets the named config from either the named identifier extension or core config if neither exist then the
437
+ * default value is returned
438
+ * @param identifier - The named extension identifier
439
+ * @param field - The config field name
440
+ * @param defaultValue - The default value to return if no defined config exists
441
+ */
442
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
443
+ /**
444
+ * Helper to allow plugins to check and possibly shortcut executing code only
445
+ * required if there is a nextPlugin
446
+ */
447
+ hasNext: () => boolean;
448
+ /**
449
+ * Returns the next configured plugin proxy
450
+ */
451
+ getNext: () => ITelemetryPluginChain;
452
+ /**
453
+ * Helper to set the next plugin proxy
454
+ */
455
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
456
+ /**
457
+ * Synchronously iterate over the context chain running the callback for each plugin, once
458
+ * every plugin has been executed via the callback, any associated onComplete will be called.
459
+ * @param callback - The function call for each plugin in the context chain
460
+ */
461
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
462
+ /**
463
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
464
+ * @param onComplete - The onComplete to call
465
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
466
+ * @param args - Any additional arguments to pass to the onComplete function
467
+ */
468
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
469
+ /**
470
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
471
+ * @param plugins - The execution order to process the plugins, if null or not supplied
472
+ * then the current execution order will be copied.
473
+ * @param startAt - The plugin to start processing from, if missing from the execution
474
+ * order then the next plugin will be NOT set.
475
+ */
476
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
477
+ }
478
+
479
+ /**
480
+ * Provides data transmission capabilities
481
+ */
482
+ interface IChannelControls extends ITelemetryPlugin {
483
+ /**
484
+ * Pause sending data
485
+ */
486
+ pause?(): void;
487
+ /**
488
+ * Resume sending data
489
+ */
490
+ resume?(): void;
491
+ /**
492
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
493
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
494
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
495
+ * @param unloadCtx - This is the context that should be used during unloading.
496
+ * @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.
497
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
498
+ */
499
+ teardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
500
+ /**
501
+ * Flush to send data immediately; channel should default to sending data asynchronously. If executing asynchronously and
502
+ * you DO NOT pass a callback function then a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
503
+ * will be returned which will resolve once the flush is complete. The actual implementation of the `IPromise`
504
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
505
+ * @param async - send data asynchronously when true
506
+ * @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.
507
+ * If the caller doesn't return true the caller should assume that it may never be called.
508
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
509
+ * @returns - If a callback is provided `true` to indicate that callback will be called after the flush is complete otherwise the caller
510
+ * should assume that any provided callback will never be called, Nothing or if occurring asynchronously a
511
+ * [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) which will be resolved once the unload is complete,
512
+ * the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) will only be returned when no callback is provided
513
+ * and async is true.
514
+ */
515
+ flush?(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void | IPromise<boolean>;
516
+ /**
517
+ * Get offline support
518
+ * @returns IInternalOfflineSupport
519
+ */
520
+ getOfflineSupport?: () => IInternalOfflineSupport;
521
+ }
522
+
523
+ interface IChannelControlsHost extends IChannelControls {
524
+ /**
525
+ * Get and return the named channel instance (if present) from the queues
526
+ * @param pluginIdentifier - The identifier name of the plugin
527
+ */
528
+ getChannel<T extends IPlugin = IPlugin>(pluginIdentifier: string): T;
529
+ }
530
+
531
+ /**
532
+ * Configuration settings for how telemetry is sent
533
+ * @export
534
+ * @interface IConfig
535
+ */
536
+ interface IConfig {
537
+ /**
538
+ * The JSON format (normal vs line delimited). True means line delimited JSON.
539
+ */
540
+ emitLineDelimitedJson?: boolean;
541
+ /**
542
+ * An optional account id, if your app groups users into accounts. No spaces, commas, semicolons, equals, or vertical bars.
543
+ */
544
+ accountId?: string;
545
+ /**
546
+ * A session is logged if the user is inactive for this amount of time in milliseconds. Default 30 mins.
547
+ * @default 30*60*1000
548
+ */
549
+ sessionRenewalMs?: number;
550
+ /**
551
+ * A session is logged if it has continued for this amount of time in milliseconds. Default 24h.
552
+ * @default 24*60*60*1000
553
+ */
554
+ sessionExpirationMs?: number;
555
+ /**
556
+ * Max size of telemetry batch. If batch exceeds limit, it is sent and a new batch is started
557
+ * @default 100000
558
+ */
559
+ maxBatchSizeInBytes?: number;
560
+ /**
561
+ * How long to batch telemetry for before sending (milliseconds)
562
+ * @default 15 seconds
563
+ */
564
+ maxBatchInterval?: number;
565
+ /**
566
+ * If true, debugging data is thrown as an exception by the logger. Default false
567
+ * @defaultValue false
568
+ */
569
+ enableDebug?: boolean;
570
+ /**
571
+ * If true, exceptions are not autocollected. Default is false
572
+ * @defaultValue false
573
+ */
574
+ disableExceptionTracking?: boolean;
575
+ /**
576
+ * If true, telemetry is not collected or sent. Default is false
577
+ * @defaultValue false
578
+ */
579
+ disableTelemetry?: boolean;
580
+ /**
581
+ * Percentage of events that will be sent. Default is 100, meaning all events are sent.
582
+ * @defaultValue 100
583
+ */
584
+ samplingPercentage?: number;
585
+ /**
586
+ * If true, on a pageview, the previous instrumented page's view time is tracked and sent as telemetry and a new timer is started for the current pageview. It is sent as a custom metric named PageVisitTime in milliseconds and is calculated via the Date now() function (if available) and falls back to (new Date()).getTime() if now() is unavailable (IE8 or less). Default is false.
587
+ */
588
+ autoTrackPageVisitTime?: boolean;
589
+ /**
590
+ * Automatically track route changes in Single Page Applications (SPA). If true, each route change will send a new Pageview to Application Insights.
591
+ */
592
+ enableAutoRouteTracking?: boolean;
593
+ /**
594
+ * If true, Ajax calls are not autocollected. Default is false
595
+ * @defaultValue false
596
+ */
597
+ disableAjaxTracking?: boolean;
598
+ /**
599
+ * If true, Fetch requests are not autocollected. Default is false (Since 2.8.0, previously true).
600
+ * @defaultValue false
601
+ */
602
+ disableFetchTracking?: boolean;
603
+ /**
604
+ * Provide a way to exclude specific route from automatic tracking for XMLHttpRequest or Fetch request. For an ajax / fetch request that the request url matches with the regex patterns, auto tracking is turned off.
605
+ * @defaultValue undefined.
606
+ */
607
+ excludeRequestFromAutoTrackingPatterns?: string[] | RegExp[];
608
+ /**
609
+ * Provide a way to enrich dependencies logs with context at the beginning of api call.
610
+ * Default is undefined.
611
+ */
612
+ addRequestContext?: (requestContext?: IRequestContext) => ICustomProperties;
613
+ /**
614
+ * If true, default behavior of trackPageView is changed to record end of page view duration interval when trackPageView is called. If false and no custom duration is provided to trackPageView, the page view performance is calculated using the navigation timing API. Default is false
615
+ * @defaultValue false
616
+ */
617
+ overridePageViewDuration?: boolean;
618
+ /**
619
+ * Default 500 - controls how many ajax calls will be monitored per page view. Set to -1 to monitor all (unlimited) ajax calls on the page.
620
+ */
621
+ maxAjaxCallsPerView?: number;
622
+ /**
623
+ * @ignore
624
+ * If false, internal telemetry sender buffers will be checked at startup for items not yet sent. Default is true
625
+ * @defaultValue true
626
+ */
627
+ disableDataLossAnalysis?: boolean;
628
+ /**
629
+ * If false, the SDK will add two headers ('Request-Id' and 'Request-Context') to all dependency requests to correlate them with corresponding requests on the server side. Default is false.
630
+ * @defaultValue false
631
+ */
632
+ disableCorrelationHeaders?: boolean;
633
+ /**
634
+ * Sets the distributed tracing mode. If AI_AND_W3C mode or W3C mode is set, W3C trace context headers (traceparent/tracestate) will be generated and included in all outgoing requests.
635
+ * AI_AND_W3C is provided for back-compatibility with any legacy Application Insights instrumented services
636
+ * @defaultValue AI_AND_W3C
637
+ */
638
+ distributedTracingMode?: DistributedTracingModes;
639
+ /**
640
+ * Disable correlation headers for specific domain
641
+ */
642
+ correlationHeaderExcludedDomains?: string[];
643
+ /**
644
+ * Default false. If true, flush method will not be called when onBeforeUnload, onUnload, onPageHide or onVisibilityChange (hidden state) event(s) trigger.
645
+ */
646
+ disableFlushOnBeforeUnload?: boolean;
647
+ /**
648
+ * Default value of {@link #disableFlushOnBeforeUnload}. If true, flush method will not be called when onPageHide or onVisibilityChange (hidden state) event(s) trigger.
649
+ */
650
+ disableFlushOnUnload?: boolean;
651
+ /**
652
+ * If true, the buffer with all unsent telemetry is stored in session storage. The buffer is restored on page load. Default is true.
653
+ * @defaultValue true
654
+ */
655
+ enableSessionStorageBuffer?: boolean;
656
+ /**
657
+ * If specified, overrides the storage & retrieval mechanism that is used to manage unsent telemetry.
658
+ */
659
+ bufferOverride?: IStorageBuffer;
660
+ /**
661
+ * @deprecated Use either disableCookiesUsage or specify a cookieCfg with the enabled value set.
662
+ * If true, the SDK will not store or read any data from cookies. Default is false. As this field is being deprecated, when both
663
+ * isCookieUseDisabled and disableCookiesUsage are used disableCookiesUsage will take precedent.
664
+ * @defaultValue false
665
+ */
666
+ isCookieUseDisabled?: boolean;
667
+ /**
668
+ * If true, the SDK will not store or read any data from cookies. Default is false.
669
+ * If you have also specified a cookieCfg then enabled property (if specified) will take precedent over this value.
670
+ * @defaultValue false
671
+ */
672
+ disableCookiesUsage?: boolean;
673
+ /**
674
+ * Custom cookie domain. This is helpful if you want to share Application Insights cookies across subdomains.
675
+ * @defaultValue ""
676
+ */
677
+ cookieDomain?: string;
678
+ /**
679
+ * Custom cookie path. This is helpful if you want to share Application Insights cookies behind an application gateway.
680
+ * @defaultValue ""
681
+ */
682
+ cookiePath?: string;
683
+ /**
684
+ * Default false. If false, retry on 206 (partial success), 408 (timeout), 429 (too many requests), 500 (internal server error), 503 (service unavailable), and 0 (offline, only if detected)
685
+ * @description
686
+ * @defaultValue false
687
+ */
688
+ isRetryDisabled?: boolean;
689
+ /**
690
+ * @deprecated Used when initizialing from snippet only.
691
+ * The url from where the JS SDK will be downloaded.
692
+ */
693
+ url?: string;
694
+ /**
695
+ * If true, the SDK will not store or read any data from local and session storage. Default is false.
696
+ * @defaultValue false
697
+ */
698
+ isStorageUseDisabled?: boolean;
699
+ /**
700
+ * If false, the SDK will send all telemetry using the [Beacon API](https://www.w3.org/TR/beacon)
701
+ * @defaultValue true
702
+ */
703
+ isBeaconApiDisabled?: boolean;
704
+ /**
705
+ * Don't use XMLHttpRequest or XDomainRequest (for IE < 9) by default instead attempt to use fetch() or sendBeacon.
706
+ * If no other transport is available it will still use XMLHttpRequest
707
+ */
708
+ disableXhr?: boolean;
709
+ /**
710
+ * If fetch keepalive is supported do not use it for sending events during unload, it may still fallback to fetch() without keepalive
711
+ */
712
+ onunloadDisableFetch?: boolean;
713
+ /**
714
+ * Sets the sdk extension name. Only alphabetic characters are allowed. The extension name is added as a prefix to the 'ai.internal.sdkVersion' tag (e.g. 'ext_javascript:2.0.0'). Default is null.
715
+ * @defaultValue null
716
+ */
717
+ sdkExtension?: string;
718
+ /**
719
+ * Default is false. If true, the SDK will track all [Browser Link](https://docs.microsoft.com/en-us/aspnet/core/client-side/using-browserlink) requests.
720
+ * @defaultValue false
721
+ */
722
+ isBrowserLinkTrackingEnabled?: boolean;
723
+ /**
724
+ * AppId is used for the correlation between AJAX dependencies happening on the client-side with the server-side requets. When Beacon API is enabled, it cannot be used automatically, but can be set manually in the configuration. Default is null
725
+ * @defaultValue null
726
+ */
727
+ appId?: string;
728
+ /**
729
+ * If true, the SDK will add two headers ('Request-Id' and 'Request-Context') to all CORS requests to correlate outgoing AJAX dependencies with corresponding requests on the server side. Default is false
730
+ * @defaultValue false
731
+ */
732
+ enableCorsCorrelation?: boolean;
733
+ /**
734
+ * An optional value that will be used as name postfix for localStorage and session cookie name.
735
+ * @defaultValue null
736
+ */
737
+ namePrefix?: string;
738
+ /**
739
+ * An optional value that will be used as name postfix for session cookie name. If undefined, namePrefix is used as name postfix for session cookie name.
740
+ * @defaultValue null
741
+ */
742
+ sessionCookiePostfix?: string;
743
+ /**
744
+ * An optional value that will be used as name postfix for user cookie name. If undefined, no postfix is added on user cookie name.
745
+ * @defaultValue null
746
+ */
747
+ userCookiePostfix?: string;
748
+ /**
749
+ * An optional value that will track Request Header through trackDependency function.
750
+ * @defaultValue false
751
+ */
752
+ enableRequestHeaderTracking?: boolean;
753
+ /**
754
+ * An optional value that will track Response Header through trackDependency function.
755
+ * @defaultValue false
756
+ */
757
+ enableResponseHeaderTracking?: boolean;
758
+ /**
759
+ * An optional value that will track Response Error data through trackDependency function.
760
+ * @defaultValue false
761
+ */
762
+ enableAjaxErrorStatusText?: boolean;
763
+ /**
764
+ * Flag to enable looking up and including additional browser window.performance timings
765
+ * in the reported ajax (XHR and fetch) reported metrics.
766
+ * Defaults to false.
767
+ */
768
+ enableAjaxPerfTracking?: boolean;
769
+ /**
770
+ * The maximum number of times to look for the window.performance timings (if available), this
771
+ * is required as not all browsers populate the window.performance before reporting the
772
+ * end of the XHR request and for fetch requests this is added after its complete
773
+ * Defaults to 3
774
+ */
775
+ maxAjaxPerfLookupAttempts?: number;
776
+ /**
777
+ * The amount of time to wait before re-attempting to find the windows.performance timings
778
+ * for an ajax request, time is in milliseconds and is passed directly to setTimeout()
779
+ * Defaults to 25.
780
+ */
781
+ ajaxPerfLookupDelay?: number;
782
+ /**
783
+ * Default false. when tab is closed, the SDK will send all remaining telemetry using the [Beacon API](https://www.w3.org/TR/beacon)
784
+ * @defaultValue false
785
+ */
786
+ onunloadDisableBeacon?: boolean;
787
+ /**
788
+ * @ignore
789
+ * Internal only
790
+ */
791
+ autoExceptionInstrumented?: boolean;
792
+ /**
793
+ *
794
+ */
795
+ correlationHeaderDomains?: string[];
796
+ /**
797
+ * @ignore
798
+ * Internal only
799
+ */
800
+ autoUnhandledPromiseInstrumented?: boolean;
801
+ /**
802
+ * Default false. Define whether to track unhandled promise rejections and report as JS errors.
803
+ * When disableExceptionTracking is enabled (dont track exceptions) this value will be false.
804
+ * @defaultValue false
805
+ */
806
+ enableUnhandledPromiseRejectionTracking?: boolean;
807
+ /**
808
+ * Disable correlation headers using regular expressions
809
+ */
810
+ correlationHeaderExcludePatterns?: RegExp[];
811
+ /**
812
+ * The ability for the user to provide extra headers
813
+ */
814
+ customHeaders?: [{
815
+ header: string;
816
+ value: string;
817
+ }];
818
+ /**
819
+ * Provide user an option to convert undefined field to user defined value.
820
+ */
821
+ convertUndefined?: any;
822
+ /**
823
+ * [Optional] The number of events that can be kept in memory before the SDK starts to drop events. By default, this is 10,000.
824
+ */
825
+ eventsLimitInMem?: number;
826
+ /**
827
+ * [Optional] Disable iKey deprecation error message.
828
+ * @defaultValue true
829
+ */
830
+ disableIkeyDeprecationMessage?: boolean;
831
+ /**
832
+ * [Optional] Sets to true if user wants to disable sending internal log message 'SendBrowserInfoOnUserInit'
833
+ * default to be false for versions 2.8.x and 3.0.x, true for versions 3.1.x and later
834
+ */
835
+ disableUserInitMessage?: boolean;
836
+ /**
837
+ * [Optional] Flag to indicate whether the internal looking endpoints should be automatically
838
+ * added to the `excludeRequestFromAutoTrackingPatterns` collection. (defaults to true).
839
+ * This flag exists as the provided regex is generic and may unexpectedly match a domain that
840
+ * should not be excluded.
841
+ */
842
+ addIntEndpoints?: boolean;
843
+ /**
844
+ * [Optional] Sets throttle mgr configuration by key
845
+ */
846
+ throttleMgrCfg?: {
847
+ [key: number]: IThrottleMgrConfig;
848
+ };
849
+ }
850
+
851
+ /**
852
+ * The type to identify whether the default value should be applied in preference to the provided value.
853
+ */
854
+ type IConfigCheckFn<V> = (value: V) => boolean;
855
+
856
+ /**
857
+ * The default values with a check function
858
+ */
859
+ interface IConfigDefaultCheck<T, V, C = IConfiguration> {
860
+ /**
861
+ * Callback function to check if the user-supplied value is valid, if not the default will be applied
862
+ */
863
+ isVal?: IConfigCheckFn<V>;
864
+ /**
865
+ * Optional function to allow converting and setting of the default value
866
+ */
867
+ set?: IConfigSetFn<T, V>;
868
+ /**
869
+ * The default value to apply if the user-supplied value is not valid
870
+ */
871
+ v?: V | IConfigDefaults<V, T>;
872
+ /**
873
+ * The default fallback key if the main key is not present, this is the key value from the config
874
+ */
875
+ fb?: keyof T | keyof C | Array<keyof T | keyof C>;
876
+ /**
877
+ * Use this check to determine the default fallback, default only checked whether the property isDefined,
878
+ * therefore `null`; `""` are considered to be valid values.
879
+ */
880
+ dfVal?: (value: any) => boolean;
881
+ /**
882
+ * Specify that any provided value should have the default value(s) merged into the value rather than
883
+ * just using either the default of user provided values. Mergeed objects will automatically be marked
884
+ * as referenced.
885
+ */
886
+ mrg?: boolean;
887
+ /**
888
+ * Set this field of the target as referenced, which will cause any object or array instance
889
+ * to be updated in-place rather than being entirely replaced. All other values will continue to be replaced.
890
+ * This is required for nested default objects to avoid multiple repetitive updates to listeners
891
+ * @returns The referenced properties current value
892
+ */
893
+ ref?: boolean;
894
+ /**
895
+ * Set this field of the target as read-only, which will block this single named property from
896
+ * ever being changed for the target instance.
897
+ * This does NOT freeze or seal the instance, it just stops the direct re-assignment of the named property,
898
+ * if the value is a non-primitive (ie. an object or array) it's properties will still be mutable.
899
+ * @returns The referenced properties current value
900
+ */
901
+ rdOnly?: boolean;
902
+ /**
903
+ * Block the value associated with this property from having it's properties / values converted into
904
+ * dynamic properties, this is generally used to block objects or arrays provided by external libraries
905
+ * which may be a plain object with readonly (non-configurable) or const properties.
906
+ */
907
+ blkVal?: boolean;
908
+ }
909
+
910
+ /**
911
+ * The Type definition to define default values to be applied to the config
912
+ * The value may be either the direct value or a ConfigDefaultCheck definition
913
+ */
914
+ type IConfigDefaults<T, C = IConfiguration> = {
915
+ [key in keyof T]: T[key] | IConfigDefaultCheck<T, T[key], C>;
916
+ };
917
+
918
+ /**
919
+ * The type which identifies the function use to validate the user supplied value
920
+ */
921
+ type IConfigSetFn<T, V> = (value: any, defValue: V, theConfig: T) => V;
922
+
923
+ /**
924
+ * Configuration provided to SDK core
925
+ */
926
+ interface IConfiguration {
927
+ /**
928
+ * Instrumentation key of resource. Either this or connectionString must be specified.
929
+ */
930
+ instrumentationKey?: string;
931
+ /**
932
+ * Connection string of resource. Either this or instrumentationKey must be specified.
933
+ */
934
+ connectionString?: string;
935
+ /**
936
+ * Set the timer interval (in ms) for internal logging queue, this is the
937
+ * amount of time to wait after logger.queue messages are detected to be sent.
938
+ * Note: since 3.0.1 and 2.8.13 the diagnostic logger timer is a normal timeout timer
939
+ * and not an interval timer. So this now represents the timer "delay" and not
940
+ * the frequency at which the events are sent.
941
+ */
942
+ diagnosticLogInterval?: number;
943
+ /**
944
+ * Maximum number of iKey transmitted logging telemetry per page view
945
+ */
946
+ maxMessageLimit?: number;
947
+ /**
948
+ * Console logging level. All logs with a severity level higher
949
+ * than the configured level will be printed to console. Otherwise
950
+ * they are suppressed. ie Level 2 will print both CRITICAL and
951
+ * WARNING logs to console, level 1 prints only CRITICAL.
952
+ *
953
+ * Note: Logs sent as telemetry to instrumentation key will also
954
+ * be logged to console if their severity meets the configured loggingConsoleLevel
955
+ *
956
+ * 0: ALL console logging off
957
+ * 1: logs to console: severity >= CRITICAL
958
+ * 2: logs to console: severity >= WARNING
959
+ */
960
+ loggingLevelConsole?: number;
961
+ /**
962
+ * Telemtry logging level to instrumentation key. All logs with a severity
963
+ * level higher than the configured level will sent as telemetry data to
964
+ * the configured instrumentation key.
965
+ *
966
+ * 0: ALL iKey logging off
967
+ * 1: logs to iKey: severity >= CRITICAL
968
+ * 2: logs to iKey: severity >= WARNING
969
+ */
970
+ loggingLevelTelemetry?: number;
971
+ /**
972
+ * If enabled, uncaught exceptions will be thrown to help with debugging
973
+ */
974
+ enableDebug?: boolean;
975
+ /**
976
+ * Endpoint where telemetry data is sent
977
+ */
978
+ endpointUrl?: string;
979
+ /**
980
+ * Extension configs loaded in SDK
981
+ */
982
+ extensionConfig?: {
983
+ [key: string]: any;
984
+ };
985
+ /**
986
+ * Additional plugins that should be loaded by core at runtime
987
+ */
988
+ readonly extensions?: ITelemetryPlugin[];
989
+ /**
990
+ * Channel queues that is setup by caller in desired order.
991
+ * If channels are provided here, core will ignore any channels that are already setup, example if there is a SKU with an initialized channel
992
+ */
993
+ readonly channels?: IChannelControls[][];
994
+ /**
995
+ * @type {boolean}
996
+ * Flag that disables the Instrumentation Key validation.
997
+ */
998
+ disableInstrumentationKeyValidation?: boolean;
999
+ /**
1000
+ * [Optional] When enabled this will create local perfEvents based on sections of the code that have been instrumented
1001
+ * to emit perfEvents (via the doPerf()) when this is enabled. This can be used to identify performance issues within
1002
+ * the SDK, the way you are using it or optionally your own instrumented code.
1003
+ * The provided IPerfManager implementation does NOT send any additional telemetry events to the server it will only fire
1004
+ * the new perfEvent() on the INotificationManager which you can listen to.
1005
+ * This also does not use the window.performance API, so it will work in environments where this API is not supported.
1006
+ */
1007
+ enablePerfMgr?: boolean;
1008
+ /**
1009
+ * [Optional] Callback function that will be called to create a the IPerfManager instance when required and ```enablePerfMgr```
1010
+ * is enabled, this enables you to override the default creation of a PerfManager() without needing to ```setPerfMgr()```
1011
+ * after initialization.
1012
+ */
1013
+ createPerfMgr?: (core: IAppInsightsCore, notificationManager: INotificationManager) => IPerfManager;
1014
+ /**
1015
+ * [Optional] Fire every single performance event not just the top level root performance event. Defaults to false.
1016
+ */
1017
+ perfEvtsSendAll?: boolean;
1018
+ /**
1019
+ * [Optional] Identifies the default length used to generate random session and user id's if non currently exists for the user / session.
1020
+ * Defaults to 22, previous default value was 5, if you need to keep the previous maximum length you should set this value to 5.
1021
+ */
1022
+ idLength?: number;
1023
+ /**
1024
+ * @description Custom cookie domain. This is helpful if you want to share Application Insights cookies across subdomains. It
1025
+ * can be set here or as part of the cookieCfg.domain, the cookieCfg takes precedence if both are specified.
1026
+ * @type {string}
1027
+ * @defaultValue ""
1028
+ */
1029
+ cookieDomain?: string;
1030
+ /**
1031
+ * @description Custom cookie path. This is helpful if you want to share Application Insights cookies behind an application
1032
+ * gateway. It can be set here or as part of the cookieCfg.domain, the cookieCfg takes precedence if both are specified.
1033
+ * @type {string}
1034
+ * @defaultValue ""
1035
+ */
1036
+ cookiePath?: string;
1037
+ /**
1038
+ * [Optional] A boolean that indicated whether to disable the use of cookies by the SDK. If true, the SDK will not store or
1039
+ * read any data from cookies. Cookie usage can be re-enabled after initialization via the core.getCookieMgr().enable().
1040
+ */
1041
+ disableCookiesUsage?: boolean;
1042
+ /**
1043
+ * [Optional] A Cookie Manager configuration which includes hooks to allow interception of the get, set and delete cookie
1044
+ * operations. If this configuration is specified any specified enabled and domain properties will take precedence over the
1045
+ * cookieDomain and disableCookiesUsage values.
1046
+ */
1047
+ cookieCfg?: ICookieMgrConfig;
1048
+ /**
1049
+ * [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload
1050
+ * event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
1051
+ * Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide"
1052
+ */
1053
+ disablePageUnloadEvents?: string[];
1054
+ /**
1055
+ * [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event
1056
+ * hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
1057
+ * Page Show events include "pageshow" and "visibilitychange" (with 'visible' state)
1058
+ */
1059
+ disablePageShowEvents?: string[];
1060
+ /**
1061
+ * [Optional] A flag for performance optimization to disable attempting to use the Chrome Debug Extension, if disabled and the extension is installed
1062
+ * this will not send any notifications.
1063
+ */
1064
+ disableDbgExt?: boolean;
1065
+ /**
1066
+ * Add "&w=0" parameter to support UA Parsing when web-workers don't have access to Document.
1067
+ * Default is false
1068
+ */
1069
+ enableWParam?: boolean;
1070
+ /**
1071
+ * Custom optional value that will be added as a prefix for storage name.
1072
+ * @defaultValue undefined
1073
+ */
1074
+ storagePrefix?: string;
1075
+ /**
1076
+ * Custom optional value to opt in features
1077
+ * @defaultValue undefined
1078
+ */
1079
+ featureOptIn?: IFeatureOptIn;
1080
+ }
1081
+
1082
+ interface ICookieMgr {
1083
+ /**
1084
+ * Enable or Disable the usage of cookies
1085
+ */
1086
+ setEnabled(value: boolean): void;
1087
+ /**
1088
+ * Can the system use cookies, if this returns false then all cookie setting and access functions will return nothing
1089
+ */
1090
+ isEnabled(): boolean;
1091
+ /**
1092
+ * Set the named cookie with the value and optional domain and optional
1093
+ * @param name - The name of the cookie
1094
+ * @param value - The value of the cookie (Must already be encoded)
1095
+ * @param maxAgeSec - [optional] The maximum number of SECONDS that this cookie should survive
1096
+ * @param domain - [optional] The domain to set for the cookie
1097
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
1098
+ * @returns - True if the cookie was set otherwise false (Because cookie usage is not enabled or available)
1099
+ */
1100
+ set(name: string, value: string, maxAgeSec?: number, domain?: string, path?: string): boolean;
1101
+ /**
1102
+ * Get the value of the named cookie
1103
+ * @param name - The name of the cookie
1104
+ */
1105
+ get(name: string): string;
1106
+ /**
1107
+ * Delete/Remove the named cookie if cookie support is available and enabled.
1108
+ * Note: Not using "delete" as the name because it's a reserved word which would cause issues on older browsers
1109
+ * @param name - The name of the cookie
1110
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
1111
+ * @returns - True if the cookie was marked for deletion otherwise false (Because cookie usage is not enabled or available)
1112
+ */
1113
+ del(name: string, path?: string): boolean;
1114
+ /**
1115
+ * Purge the cookie from the system if cookie support is available, this function ignores the enabled setting of the manager
1116
+ * so any cookie will be removed.
1117
+ * Note: Not using "delete" as the name because it's a reserved word which would cause issues on older browsers
1118
+ * @param name - The name of the cookie
1119
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
1120
+ * @returns - True if the cookie was marked for deletion otherwise false (Because cookie usage is not available)
1121
+ */
1122
+ purge(name: string, path?: string): boolean;
1123
+ /**
1124
+ * Optional Callback hook to allow the cookie manager to update it's configuration, not generally implemented now that
1125
+ * dynamic configuration is supported
1126
+ * @param updateState
1127
+ */
1128
+ update?(updateState: ITelemetryUpdateState): void;
1129
+ /**
1130
+ * Unload and remove any state that this ICookieMgr may be holding, this is generally called when the
1131
+ * owning SDK is being unloaded.
1132
+ * @param isAsync - Can the unload be performed asynchronously (default)
1133
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1134
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1135
+ * / Promise to allow any listeners to wait for the operation to complete.
1136
+ */
1137
+ unload?(isAsync?: boolean): void | IPromise<void>;
1138
+ }
1139
+
1140
+ /**
1141
+ * Configuration definition for instance based cookie management configuration
1142
+ */
1143
+ interface ICookieMgrConfig {
1144
+ /**
1145
+ * Defaults to true, A boolean that indicates whether the use of cookies by the SDK is enabled by the current instance.
1146
+ * If false, the instance of the SDK initialized by this configuration will not store or read any data from cookies
1147
+ */
1148
+ enabled?: boolean;
1149
+ /**
1150
+ * Custom cookie domain. This is helpful if you want to share Application Insights cookies across subdomains.
1151
+ */
1152
+ domain?: string;
1153
+ /**
1154
+ * Specifies the path to use for the cookie, defaults to '/'
1155
+ */
1156
+ path?: string;
1157
+ /**
1158
+ * Specify the cookie name(s) to be ignored, this will cause any matching cookie name to never be read or written.
1159
+ * They may still be explicitly purged or deleted. You do not need to repeat the name in the `blockedCookies`
1160
+ * configuration.(Since v2.8.8)
1161
+ */
1162
+ ignoreCookies?: string[];
1163
+ /**
1164
+ * Specify the cookie name(s) to never be written, this will cause any cookie name to never be created or updated,
1165
+ * they will still be read unless also included in the ignoreCookies and may still be explicitly purged or deleted.
1166
+ * If not provided defaults to the same list provided in ignoreCookies. (Since v2.8.8)
1167
+ */
1168
+ blockedCookies?: string[];
1169
+ /**
1170
+ * Hook function to fetch the named cookie value.
1171
+ * @param name - The name of the cookie
1172
+ */
1173
+ getCookie?: (name: string) => string;
1174
+ /**
1175
+ * Hook function to set the named cookie with the specified value.
1176
+ * @param name - The name of the cookie
1177
+ * @param value - The value to set for the cookie
1178
+ */
1179
+ setCookie?: (name: string, value: string) => void;
1180
+ /**
1181
+ * Hook function to delete the named cookie with the specified value, separated from
1182
+ * setCookie to avoid the need to parse the value to determine whether the cookie is being
1183
+ * added or removed.
1184
+ * @param name - The name of the cookie
1185
+ * @param cookieValue - The value to set to expire the cookie
1186
+ */
1187
+ delCookie?: (name: string, cookieValue: string) => void;
1188
+ }
1189
+
1190
+ interface ICustomProperties {
1191
+ [key: string]: any;
1192
+ }
1193
+
1194
+ interface IDiagnosticLogger {
1195
+ /**
1196
+ * 0: OFF
1197
+ * 1: only critical (default)
1198
+ * 2: critical + info
1199
+ */
1200
+ consoleLoggingLevel: () => number;
1201
+ /**
1202
+ * The internal logging queue
1203
+ */
1204
+ queue: _InternalLogMessage[];
1205
+ /**
1206
+ * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
1207
+ * @param severity - The severity of the log message
1208
+ * @param message - The log message.
1209
+ */
1210
+ throwInternal(severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
1211
+ /**
1212
+ * This will write a debug message to the console if possible
1213
+ * @param message - {string} - The debug message
1214
+ */
1215
+ debugToConsole?(message: string): void;
1216
+ /**
1217
+ * This will write a warning to the console if possible
1218
+ * @param message - The warning message
1219
+ */
1220
+ warnToConsole(message: string): void;
1221
+ /**
1222
+ * This will write an error to the console if possible.
1223
+ * Provided by the default DiagnosticLogger instance, and internally the SDK will fall back to warnToConsole, however,
1224
+ * direct callers MUST check for its existence on the logger as you can provide your own IDiagnosticLogger instance.
1225
+ * @param message - The error message
1226
+ */
1227
+ errorToConsole?(message: string): void;
1228
+ /**
1229
+ * Resets the internal message count
1230
+ */
1231
+ resetInternalMessageCount(): void;
1232
+ /**
1233
+ * Logs a message to the internal queue.
1234
+ * @param severity - The severity of the log message
1235
+ * @param message - The message to log.
1236
+ */
1237
+ logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
1238
+ /**
1239
+ * Optional Callback hook to allow the diagnostic logger to update it's configuration
1240
+ * @param updateState
1241
+ */
1242
+ update?(updateState: ITelemetryUpdateState): void;
1243
+ /**
1244
+ * Unload and remove any state that this IDiagnosticLogger may be holding, this is generally called when the
1245
+ * owning SDK is being unloaded.
1246
+ * @param isAsync - Can the unload be performed asynchronously (default)
1247
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1248
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1249
+ * / Promise to allow any listeners to wait for the operation to complete.
1250
+ */
1251
+ unload?(isAsync?: boolean): void | IPromise<void>;
1252
+ }
1253
+
1254
+ interface IDistributedTraceContext {
1255
+ /**
1256
+ * Returns the current name of the page
1257
+ */
1258
+ getName(): string;
1259
+ /**
1260
+ * Sets the current name of the page
1261
+ * @param pageName
1262
+ */
1263
+ setName(pageName: string): void;
1264
+ /**
1265
+ * Returns the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1266
+ * Must be read from incoming headers or generated according to the W3C TraceContext specification,
1267
+ * in a hex representation of 16-byte array. A.k.a. trace-id, TraceID or Distributed TraceID
1268
+ */
1269
+ getTraceId(): string;
1270
+ /**
1271
+ * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1272
+ * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
1273
+ * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
1274
+ */
1275
+ setTraceId(newValue: string): void;
1276
+ /**
1277
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1278
+ * Also know as the parentId, used to link requests together
1279
+ */
1280
+ getSpanId(): string;
1281
+ /**
1282
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1283
+ * Also know as the parentId, used to link requests together
1284
+ * https://www.w3.org/TR/trace-context/#parent-id
1285
+ */
1286
+ setSpanId(newValue: string): void;
1287
+ /**
1288
+ * An integer representation of the W3C TraceContext trace-flags.
1289
+ */
1290
+ getTraceFlags(): number | undefined;
1291
+ /**
1292
+ * https://www.w3.org/TR/trace-context/#trace-flags
1293
+ * @param newValue
1294
+ */
1295
+ setTraceFlags(newValue?: number): void;
1296
+ }
1297
+
1298
+ interface IFeatureOptIn {
1299
+ [feature: string]: IFeatureOptInDetails;
1300
+ }
1301
+
1302
+ interface IFeatureOptInDetails {
1303
+ /**
1304
+ * sets feature opt-in mode
1305
+ * @default undefined
1306
+ */
1307
+ mode?: FeatureOptInMode;
1308
+ /**
1309
+ * Identifies configuration override values when given feature is enabled
1310
+ * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1311
+ * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: {["extensionConfig.Analytics.disableAjaxTrackig"]:1}
1312
+ * Default: undefined
1313
+ */
1314
+ onCfg?: {
1315
+ [field: string]: any;
1316
+ };
1317
+ /**
1318
+ * Identifies configuration override values when given feature is disabled
1319
+ * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1320
+ * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: {["extensionConfig.Analytics.disableAjaxTrackig"]:1}
1321
+ * Default: undefined
1322
+ */
1323
+ offCfg?: {
1324
+ [field: string]: any;
1325
+ };
1326
+ /**
1327
+ * define if should block any changes from cdn cfg, if set to true, cfgValue will be applied under all scenarios
1328
+ * @default false
1329
+ */
1330
+ blockCdnCfg?: boolean;
1331
+ }
1332
+
1333
+ /**
1334
+ * Internal Interface
1335
+ */
1336
+ interface IInternalOfflineSupport {
1337
+ /**
1338
+ * Get current endpoint url
1339
+ * @returns endpoint
1340
+ */
1341
+ getUrl: () => string;
1342
+ /**
1343
+ * Create payload data
1344
+ * @param data data
1345
+ * @returns IPayloadData
1346
+ */
1347
+ createPayload: (data: string | Uint8Array) => IPayloadData;
1348
+ /**
1349
+ * Serialize an item into a string
1350
+ * @param input telemetry item
1351
+ * @param convertUndefined convert undefined to a custom-defined object
1352
+ * @returns Serialized string
1353
+ */
1354
+ serialize?: (input: ITelemetryItem, convertUndefined?: any) => string;
1355
+ /**
1356
+ * Batch an array of strings into one string
1357
+ * @param arr array of strings
1358
+ * @returns a string represent all items in the given array
1359
+ */
1360
+ batch?: (arr: string[]) => string;
1361
+ /**
1362
+ * If the item should be processed by offline channel
1363
+ * @param evt telemetry item
1364
+ * @returns should process or not
1365
+ */
1366
+ shouldProcess?: (evt: ITelemetryItem) => boolean;
1367
+ }
1368
+
1369
+ /**
1370
+ * An alternate interface which provides automatic removal during unloading of the component
1371
+ */
1372
+ interface ILegacyUnloadHook {
1373
+ /**
1374
+ * Legacy Self remove the referenced component
1375
+ */
1376
+ remove: () => void;
1377
+ }
1378
+
1379
+ interface ILoadedPlugin<T extends IPlugin> {
1380
+ plugin: T;
1381
+ /**
1382
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
1383
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
1384
+ * @returns boolean = true if the plugin is in a state where it is operational.
1385
+ */
1386
+ isEnabled: () => boolean;
1387
+ /**
1388
+ * You can optionally enable / disable a plugin from processing events.
1389
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
1390
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
1391
+ * (unless it's also been re-initialized)
1392
+ */
1393
+ setEnabled: (isEnabled: boolean) => void;
1394
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
1395
+ }
1396
+
1397
+ /**
1398
+ * An interface used for the notification listener.
1399
+ * @interface
1400
+ */
1401
+ interface INotificationListener {
1402
+ /**
1403
+ * [Optional] A function called when events are sent.
1404
+ * @param events - The array of events that have been sent.
1405
+ */
1406
+ eventsSent?: (events: ITelemetryItem[]) => void;
1407
+ /**
1408
+ * [Optional] A function called when events are discarded.
1409
+ * @param events - The array of events that have been discarded.
1410
+ * @param reason - The reason for discarding the events. The EventsDiscardedReason
1411
+ * constant should be used to check the different values.
1412
+ */
1413
+ eventsDiscarded?: (events: ITelemetryItem[], reason: number) => void;
1414
+ /**
1415
+ * [Optional] A function called when the events have been requested to be sent to the sever.
1416
+ * @param sendReason - The reason why the event batch is being sent.
1417
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1418
+ */
1419
+ eventsSendRequest?: (sendReason: number, isAsync?: boolean) => void;
1420
+ /**
1421
+ * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
1422
+ * the event can be displayed via the debug plugin extension.
1423
+ * @param perfEvent
1424
+ */
1425
+ perfEvent?: (perfEvent: IPerfEvent) => void;
1426
+ /**
1427
+ * Unload and remove any state that this INotificationListener may be holding, this is generally called when the
1428
+ * owning Manager is being unloaded.
1429
+ * @param isAsync - Can the unload be performed asynchronously (default)
1430
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1431
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1432
+ * / Promise to allow any listeners to wait for the operation to complete.
1433
+ */
1434
+ unload?(isAsync?: boolean): void | IPromise<void>;
1435
+ }
1436
+
1437
+ /**
1438
+ * Class to manage sending notifications to all the listeners.
1439
+ */
1440
+ interface INotificationManager {
1441
+ listeners: INotificationListener[];
1442
+ /**
1443
+ * Adds a notification listener.
1444
+ * @param listener - The notification listener to be added.
1445
+ */
1446
+ addNotificationListener(listener: INotificationListener): void;
1447
+ /**
1448
+ * Removes all instances of the listener.
1449
+ * @param listener - AWTNotificationListener to remove.
1450
+ */
1451
+ removeNotificationListener(listener: INotificationListener): void;
1452
+ /**
1453
+ * Notification for events sent.
1454
+ * @param events - The array of events that have been sent.
1455
+ */
1456
+ eventsSent(events: ITelemetryItem[]): void;
1457
+ /**
1458
+ * Notification for events being discarded.
1459
+ * @param events - The array of events that have been discarded by the SDK.
1460
+ * @param reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
1461
+ * constant should be used to check the different values.
1462
+ */
1463
+ eventsDiscarded(events: ITelemetryItem[], reason: number): void;
1464
+ /**
1465
+ * [Optional] A function called when the events have been requested to be sent to the sever.
1466
+ * @param sendReason - The reason why the event batch is being sent.
1467
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1468
+ */
1469
+ eventsSendRequest?(sendReason: number, isAsync: boolean): void;
1470
+ /**
1471
+ * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
1472
+ * the event can be displayed via the debug plugin extension.
1473
+ * @param perfEvent - The perf event details
1474
+ */
1475
+ perfEvent?(perfEvent: IPerfEvent): void;
1476
+ /**
1477
+ * Unload and remove any state that this INotificationManager may be holding, this is generally called when the
1478
+ * owning SDK is being unloaded.
1479
+ * @param isAsync - Can the unload be performed asynchronously (default)
1480
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1481
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1482
+ * / Promise to allow any listeners to wait for the operation to complete.
1483
+ */
1484
+ unload?(isAsync?: boolean): void | IPromise<void>;
1485
+ }
1486
+
1487
+ class _InternalLogMessage {
1488
+ static dataType: string;
1489
+ message: string;
1490
+ messageId: _InternalMessageId;
1491
+ constructor(msgId: _InternalMessageId, msg: string, isUserAct?: boolean, properties?: Object);
1492
+ }
1493
+
1494
+ type _InternalMessageId = number | _eInternalMessageId;
1495
+
1496
+ /** IPayloadData describes interface of payload sent via POST channel */
1497
+ interface IPayloadData {
1498
+ urlString: string;
1499
+ data: Uint8Array | string;
1500
+ headers?: {
1501
+ [name: string]: string;
1502
+ };
1503
+ timeout?: number;
1504
+ disableXhrSync?: boolean;
1505
+ disableFetchKeepAlive?: boolean;
1506
+ sendReason?: SendRequestReason;
1507
+ }
1508
+
1509
+ /**
1510
+ * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
1511
+ */
1512
+ interface IPerfEvent {
1513
+ /**
1514
+ * The name of the performance event
1515
+ */
1516
+ name: string;
1517
+ /**
1518
+ * The start time of the performance event
1519
+ */
1520
+ start: number;
1521
+ /**
1522
+ * The payload (contents) of the perfEvent, may be null or only set after the event has completed depending on
1523
+ * the runtime environment.
1524
+ */
1525
+ payload: any;
1526
+ /**
1527
+ * Is this occurring from an asynchronous event
1528
+ */
1529
+ isAsync: boolean;
1530
+ /**
1531
+ * Identifies the total inclusive time spent for this event, including the time spent for child events,
1532
+ * this will be undefined until the event is completed
1533
+ */
1534
+ time?: number;
1535
+ /**
1536
+ * Identifies the exclusive time spent in for this event (not including child events),
1537
+ * this will be undefined until the event is completed.
1538
+ */
1539
+ exTime?: number;
1540
+ /**
1541
+ * The Parent event that was started before this event was created
1542
+ */
1543
+ parent?: IPerfEvent;
1544
+ /**
1545
+ * The child perf events that are contained within the total time of this event.
1546
+ */
1547
+ childEvts?: IPerfEvent[];
1548
+ /**
1549
+ * Identifies whether this event is a child event of a parent
1550
+ */
1551
+ isChildEvt: () => boolean;
1552
+ /**
1553
+ * Get the names additional context associated with this perf event
1554
+ */
1555
+ getCtx?: (key: string) => any;
1556
+ /**
1557
+ * Set the named additional context to be associated with this perf event, this will replace any existing value
1558
+ */
1559
+ setCtx?: (key: string, value: any) => void;
1560
+ /**
1561
+ * Mark this event as completed, calculating the total execution time.
1562
+ */
1563
+ complete: () => void;
1564
+ }
1565
+
1566
+ /**
1567
+ * This defines an internal performance manager for tracking and reporting the internal performance of the SDK -- It does
1568
+ * not represent or report any event to the server.
1569
+ */
1570
+ interface IPerfManager {
1571
+ /**
1572
+ * Create a new event and start timing, the manager may return null/undefined to indicate that it does not
1573
+ * want to monitor this source event.
1574
+ * @param src - The source name of the event
1575
+ * @param payloadDetails - An optional callback function to fetch the payload details for the event.
1576
+ * @param isAsync - Is the event occurring from a async event
1577
+ */
1578
+ create(src: string, payloadDetails?: () => any, isAsync?: boolean): IPerfEvent | null | undefined;
1579
+ /**
1580
+ * Complete the perfEvent and fire any notifications.
1581
+ * @param perfEvent - Fire the event which will also complete the passed event
1582
+ */
1583
+ fire(perfEvent: IPerfEvent): void;
1584
+ /**
1585
+ * Set an execution context value
1586
+ * @param key - The context key name
1587
+ * @param value - The value
1588
+ */
1589
+ setCtx(key: string, value: any): void;
1590
+ /**
1591
+ * Get the execution context value
1592
+ * @param key - The context key
1593
+ */
1594
+ getCtx(key: string): any;
1595
+ }
1596
+
1597
+ /**
1598
+ * Identifies an interface to a host that can provide an IPerfManager implementation
1599
+ */
1600
+ interface IPerfManagerProvider {
1601
+ /**
1602
+ * Get the current performance manager
1603
+ */
1604
+ getPerfMgr(): IPerfManager;
1605
+ /**
1606
+ * Set the current performance manager
1607
+ * @param perfMgr - The performance manager
1608
+ */
1609
+ setPerfMgr(perfMgr: IPerfManager): void;
1610
+ }
1611
+
1612
+ interface IPlugin {
1613
+ /**
1614
+ * Initialize plugin loaded by SDK
1615
+ * @param config - The config for the plugin to use
1616
+ * @param core - The current App Insights core to use for initializing this plugin instance
1617
+ * @param extensions - The complete set of extensions to be used for initializing the plugin
1618
+ * @param pluginChain - [Optional] specifies the current plugin chain which identifies the
1619
+ * set of plugins and the order they should be executed for the current request.
1620
+ */
1621
+ initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) => void;
1622
+ /**
1623
+ * Returns a value that indicates whether the plugin has already been previously initialized.
1624
+ * New plugins should implement this method to avoid being initialized more than once.
1625
+ */
1626
+ isInitialized?: () => boolean;
1627
+ /**
1628
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
1629
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
1630
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
1631
+ * @param unloadCtx - This is the context that should be used during unloading.
1632
+ * @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.
1633
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
1634
+ */
1635
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
1636
+ /**
1637
+ * Extension name
1638
+ */
1639
+ readonly identifier: string;
1640
+ /**
1641
+ * Plugin version (available in data.properties.version in common schema)
1642
+ */
1643
+ readonly version?: string;
1644
+ /**
1645
+ * The App Insights core to use for backward compatibility.
1646
+ * Therefore the interface will be able to access the core without needing to cast to "any".
1647
+ * [optional] any 3rd party plugins which are already implementing this interface don't fail to compile.
1648
+ */
1649
+ core?: IAppInsightsCore;
1650
+ }
1651
+
1652
+ /**
1653
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
1654
+ * between multiple AppInsights instances
1655
+ */
1656
+ interface IProcessTelemetryContext extends IBaseProcessingContext {
1657
+ /**
1658
+ * Call back for telemetry processing before it it is sent
1659
+ * @param env - This is the current event being reported
1660
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1661
+ */
1662
+ processNext: (env: ITelemetryItem) => boolean | void;
1663
+ /**
1664
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1665
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1666
+ * then the current execution order will be copied.
1667
+ * @param startAt - The plugin to start processing from, if missing from the execution
1668
+ * order then the next plugin will be NOT set.
1669
+ */
1670
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
1671
+ }
1672
+
1673
+ /**
1674
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
1675
+ * or the SDK is being unloaded.
1676
+ */
1677
+ interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
1678
+ /**
1679
+ * This Plugin has finished unloading, so unload the next one
1680
+ * @param uploadState - The state of the unload process
1681
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1682
+ */
1683
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
1684
+ /**
1685
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1686
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1687
+ * then the current execution order will be copied.
1688
+ * @param startAt - The plugin to start processing from, if missing from the execution
1689
+ * order then the next plugin will be NOT set.
1690
+ */
1691
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
1692
+ }
1693
+
1694
+ /**
1695
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
1696
+ * for when plugins are added, removed or the configuration was changed.
1697
+ */
1698
+ interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
1699
+ /**
1700
+ * This Plugin has finished unloading, so unload the next one
1701
+ * @param updateState - The update State
1702
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1703
+ */
1704
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
1705
+ /**
1706
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1707
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1708
+ * then the current execution order will be copied.
1709
+ * @param startAt - The plugin to start processing from, if missing from the execution
1710
+ * order then the next plugin will be NOT set.
1711
+ */
1712
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
1713
+ }
1714
+
1715
+ /**
1716
+ * Create a Promise object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
1717
+ * This interface definition, closely mirrors the typescript / javascript PromiseLike<T> and Promise<T> definitions as well as providing
1718
+ * simular functions as that provided by jQuery deferred objects.
1719
+ *
1720
+ * The returned Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers
1721
+ * with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous
1722
+ * methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point
1723
+ * in the future.
1724
+ *
1725
+ * A Promise is in one of these states:
1726
+ * <ul>
1727
+ * <li> pending: initial state, neither fulfilled nor rejected.
1728
+ * <li> fulfilled: meaning that the operation was completed successfully.
1729
+ * <li> rejected: meaning that the operation failed.
1730
+ * </ul>
1731
+ *
1732
+ * A pending promise can either be fulfilled with a value or rejected with a reason (error). When either of these options happens, the
1733
+ * associated handlers queued up by a promise's then method are called synchronously. If the promise has already been fulfilled or rejected
1734
+ * when a corresponding handler is attached, the handler will be called synchronously, so there is no race condition between an asynchronous
1735
+ * operation completing and its handlers being attached.
1736
+ *
1737
+ * As the `then()` and `catch()` methods return promises, they can be chained.
1738
+ * @typeParam T - Identifies the expected return type from the promise
1739
+ */
1740
+ interface IPromise<T> extends PromiseLike<T>, Promise<T> {
1741
+ /**
1742
+ * Returns a string representation of the current state of the promise. The promise can be in one of four states.
1743
+ * <ul>
1744
+ * <li> <b>"pending"</b>: The promise is not yet in a completed state (neither "rejected"; or "resolved").</li>
1745
+ * <li> <b>"resolved"</b>: The promise is in the resolved state.</li>
1746
+ * <li> <b>"rejected"</b>: The promise is in the rejected state.</li>
1747
+ * </ul>
1748
+ * @example
1749
+ * ```ts
1750
+ * let doResolve;
1751
+ * let promise: IPromise<any> = createSyncPromise((resolve) => {
1752
+ * doResolve = resolve;
1753
+ * });
1754
+ *
1755
+ * let state: string = promise.state();
1756
+ * console.log("State: " + state); // State: pending
1757
+ * doResolve(true); // Promise will resolve synchronously as it's a synchronous promise
1758
+ * console.log("State: " + state); // State: resolved
1759
+ * ```
1760
+ */
1761
+ state?: string;
1762
+ /**
1763
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1764
+ * @param onResolved The callback to execute when the Promise is resolved.
1765
+ * @param onRejected The callback to execute when the Promise is rejected.
1766
+ * @returns A Promise for the completion of which ever callback is executed.
1767
+ * @example
1768
+ * ```ts
1769
+ * const promise1 = createPromise((resolve, reject) => {
1770
+ * resolve('Success!');
1771
+ * });
1772
+ *
1773
+ * promise1.then((value) => {
1774
+ * console.log(value);
1775
+ * // expected output: "Success!"
1776
+ * });
1777
+ * ```
1778
+ */
1779
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): IPromise<TResult1 | TResult2>;
1780
+ /**
1781
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1782
+ * @param onResolved The callback to execute when the Promise is resolved.
1783
+ * @param onRejected The callback to execute when the Promise is rejected.
1784
+ * @returns A Promise for the completion of which ever callback is executed.
1785
+ * @example
1786
+ * ```ts
1787
+ * const promise1 = createPromise((resolve, reject) => {
1788
+ * resolve('Success!');
1789
+ * });
1790
+ *
1791
+ * promise1.then((value) => {
1792
+ * console.log(value);
1793
+ * // expected output: "Success!"
1794
+ * });
1795
+ * ```
1796
+ */
1797
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): PromiseLike<TResult1 | TResult2>;
1798
+ /**
1799
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1800
+ * @param onResolved The callback to execute when the Promise is resolved.
1801
+ * @param onRejected The callback to execute when the Promise is rejected.
1802
+ * @returns A Promise for the completion of which ever callback is executed.
1803
+ * @example
1804
+ * ```ts
1805
+ * const promise1 = createPromise((resolve, reject) => {
1806
+ * resolve('Success!');
1807
+ * });
1808
+ *
1809
+ * promise1.then((value) => {
1810
+ * console.log(value);
1811
+ * // expected output: "Success!"
1812
+ * });
1813
+ * ```
1814
+ */
1815
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): Promise<TResult1 | TResult2>;
1816
+ /**
1817
+ * Attaches a callback for only the rejection of the Promise.
1818
+ * @param onRejected The callback to execute when the Promise is rejected.
1819
+ * @returns A Promise for the completion of the callback.
1820
+ * @example
1821
+ * ```ts
1822
+ * const promise1 = createPromise((resolve, reject) => {
1823
+ * throw 'Uh-oh!';
1824
+ * });
1825
+ *
1826
+ * promise1.catch((error) => {
1827
+ * console.error(error);
1828
+ * });
1829
+ * // expected output: Uh-oh!
1830
+ * ```
1831
+ */
1832
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): IPromise<T | TResult>;
1833
+ /**
1834
+ * Attaches a callback for only the rejection of the Promise.
1835
+ * @param onRejected The callback to execute when the Promise is rejected.
1836
+ * @returns A Promise for the completion of the callback.
1837
+ * @example
1838
+ * ```ts
1839
+ * const promise1 = createPromise((resolve, reject) => {
1840
+ * throw 'Uh-oh!';
1841
+ * });
1842
+ *
1843
+ * promise1.catch((error) => {
1844
+ * console.error(error);
1845
+ * });
1846
+ * // expected output: Uh-oh!
1847
+ * ```
1848
+ */
1849
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): PromiseLike<T | TResult>;
1850
+ /**
1851
+ * Attaches a callback for only the rejection of the Promise.
1852
+ * @param onRejected The callback to execute when the Promise is rejected.
1853
+ * @returns A Promise for the completion of the callback.
1854
+ * @example
1855
+ * ```ts
1856
+ * const promise1 = createPromise((resolve, reject) => {
1857
+ * throw 'Uh-oh!';
1858
+ * });
1859
+ *
1860
+ * promise1.catch((error) => {
1861
+ * console.error(error);
1862
+ * });
1863
+ * // expected output: Uh-oh!
1864
+ * ```
1865
+ */
1866
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): Promise<T | TResult>;
1867
+ /**
1868
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
1869
+ * resolved value cannot be modified from the callback.
1870
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
1871
+ * @returns A Promise for the completion of the callback.
1872
+ * @example
1873
+ * ```ts
1874
+ * function doFunction() {
1875
+ * return createPromise((resolve, reject) => {
1876
+ * if (Math.random() > 0.5) {
1877
+ * resolve('Function has completed');
1878
+ * } else {
1879
+ * reject(new Error('Function failed to process'));
1880
+ * }
1881
+ * });
1882
+ * }
1883
+ *
1884
+ * doFunction().then((data) => {
1885
+ * console.log(data);
1886
+ * }).catch((err) => {
1887
+ * console.error(err);
1888
+ * }).finally(() => {
1889
+ * console.log('Function processing completed');
1890
+ * });
1891
+ * ```
1892
+ */
1893
+ finally(onfinally?: FinallyPromiseHandler): IPromise<T>;
1894
+ /**
1895
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
1896
+ * resolved value cannot be modified from the callback.
1897
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
1898
+ * @returns A Promise for the completion of the callback.
1899
+ * @example
1900
+ * ```ts
1901
+ * function doFunction() {
1902
+ * return createPromise((resolve, reject) => {
1903
+ * if (Math.random() > 0.5) {
1904
+ * resolve('Function has completed');
1905
+ * } else {
1906
+ * reject(new Error('Function failed to process'));
1907
+ * }
1908
+ * });
1909
+ * }
1910
+ *
1911
+ * doFunction().then((data) => {
1912
+ * console.log(data);
1913
+ * }).catch((err) => {
1914
+ * console.error(err);
1915
+ * }).finally(() => {
1916
+ * console.log('Function processing completed');
1917
+ * });
1918
+ * ```
1919
+ */
1920
+ finally(onFinally?: FinallyPromiseHandler): Promise<T>;
1921
+ }
1922
+
1923
+ interface IRequestContext {
1924
+ status?: number;
1925
+ xhr?: XMLHttpRequest;
1926
+ request?: Request;
1927
+ response?: Response | string;
1928
+ }
1929
+
1930
+ /**
1931
+ * Identifies a simple interface to allow you to override the storage mechanism used
1932
+ * to track unsent and unacknowledged events. When provided it must provide both
1933
+ * the get and set item functions.
1934
+ * @since 2.8.12
1935
+ */
1936
+ interface IStorageBuffer {
1937
+ /**
1938
+ * Retrieves the stored value for a given key
1939
+ */
1940
+ getItem(logger: IDiagnosticLogger, name: string): string;
1941
+ /**
1942
+ * Sets the stored value for a given key
1943
+ */
1944
+ setItem(logger: IDiagnosticLogger, name: string, data: string): boolean;
1945
+ }
26
1946
 
27
1947
  interface ITeeChannelConfig {
28
1948
  /**
@@ -38,6 +1958,447 @@ declare namespace ApplicationInsights {
38
1958
  ignoreCoreChannels?: boolean;
39
1959
  }
40
1960
 
1961
+ interface ITelemetryInitializerHandler extends ILegacyUnloadHook {
1962
+ remove(): void;
1963
+ }
1964
+
1965
+ /**
1966
+ * Telemety item supported in Core
1967
+ */
1968
+ interface ITelemetryItem {
1969
+ /**
1970
+ * CommonSchema Version of this SDK
1971
+ */
1972
+ ver?: string;
1973
+ /**
1974
+ * Unique name of the telemetry item
1975
+ */
1976
+ name: string;
1977
+ /**
1978
+ * Timestamp when item was sent
1979
+ */
1980
+ time?: string;
1981
+ /**
1982
+ * Identifier of the resource that uniquely identifies which resource data is sent to
1983
+ */
1984
+ iKey?: string;
1985
+ /**
1986
+ * System context properties of the telemetry item, example: ip address, city etc
1987
+ */
1988
+ ext?: {
1989
+ [key: string]: any;
1990
+ };
1991
+ /**
1992
+ * System context property extensions that are not global (not in ctx)
1993
+ */
1994
+ tags?: Tags;
1995
+ /**
1996
+ * Custom data
1997
+ */
1998
+ data?: ICustomProperties;
1999
+ /**
2000
+ * Telemetry type used for part B
2001
+ */
2002
+ baseType?: string;
2003
+ /**
2004
+ * Based on schema for part B
2005
+ */
2006
+ baseData?: {
2007
+ [key: string]: any;
2008
+ };
2009
+ }
2010
+
2011
+ /**
2012
+ * Configuration provided to SDK core
2013
+ */
2014
+ interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
2015
+ /**
2016
+ * Set next extension for telemetry processing, this is not optional as plugins should use the
2017
+ * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
2018
+ * now for backward compatibility only.
2019
+ */
2020
+ setNextPlugin?: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
2021
+ /**
2022
+ * Priority of the extension
2023
+ */
2024
+ readonly priority: number;
2025
+ }
2026
+
2027
+ /**
2028
+ * Configuration provided to SDK core
2029
+ */
2030
+ interface ITelemetryPluginChain extends ITelemetryProcessor {
2031
+ /**
2032
+ * Returns the underlying plugin that is being proxied for the processTelemetry call
2033
+ */
2034
+ getPlugin: () => ITelemetryPlugin;
2035
+ /**
2036
+ * Returns the next plugin
2037
+ */
2038
+ getNext: () => ITelemetryPluginChain;
2039
+ /**
2040
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
2041
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
2042
+ * @param unloadCtx - The unload context to use for this call.
2043
+ * @param unloadState - The details of the unload operation
2044
+ */
2045
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2046
+ }
2047
+
2048
+ interface ITelemetryProcessor {
2049
+ /**
2050
+ * Call back for telemetry processing before it it is sent
2051
+ * @param env - This is the current event being reported
2052
+ * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
2053
+ * can optionally use this to access the current core instance or define / pass additional information
2054
+ * to later plugins (vs appending items to the telemetry item)
2055
+ */
2056
+ processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2057
+ /**
2058
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
2059
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
2060
+ * the configuration has bee updated.
2061
+ * @param updateCtx - This is the context that should be used during updating.
2062
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
2063
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
2064
+ */
2065
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
2066
+ }
2067
+
2068
+ interface ITelemetryUnloadState {
2069
+ reason: TelemetryUnloadReason;
2070
+ isAsync: boolean;
2071
+ flushComplete?: boolean;
2072
+ }
2073
+
2074
+ interface ITelemetryUpdateState {
2075
+ /**
2076
+ * Identifies the reason for the update notification, this is a bitwise numeric value
2077
+ */
2078
+ reason: TelemetryUpdateReason;
2079
+ /**
2080
+ * This is a new active configuration that should be used
2081
+ */
2082
+ cfg?: IConfiguration;
2083
+ /**
2084
+ * The detected changes
2085
+ */
2086
+ oldCfg?: IConfiguration;
2087
+ /**
2088
+ * If this is a configuration update this was the previous configuration that was used
2089
+ */
2090
+ newConfig?: IConfiguration;
2091
+ /**
2092
+ * Was the new config requested to be merged with the existing config
2093
+ */
2094
+ merge?: boolean;
2095
+ /**
2096
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
2097
+ */
2098
+ added?: IPlugin[];
2099
+ /**
2100
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
2101
+ */
2102
+ removed?: IPlugin[];
2103
+ }
2104
+
2105
+ /**
2106
+ * Identifies frequency of items sent
2107
+ * Default: send data on 28th every 3 month each year
2108
+ */
2109
+ interface IThrottleInterval {
2110
+ /**
2111
+ * Identifies month interval that items can be sent
2112
+ * For example, if it is set to 2 and start date is in Jan, items will be sent out every two months (Jan, March, May etc.)
2113
+ * If both monthInterval and dayInterval are undefined, it will be set to 3
2114
+ */
2115
+ monthInterval?: number;
2116
+ /**
2117
+ * Identifies days Interval from start date that items can be sent
2118
+ * Default: undefined
2119
+ */
2120
+ dayInterval?: number;
2121
+ /**
2122
+ * Identifies days within each month that items can be sent
2123
+ * If both monthInterval and dayInterval are undefined, it will be default to [28]
2124
+ */
2125
+ daysOfMonth?: number[];
2126
+ }
2127
+
2128
+ /**
2129
+ * Identifies limit number/percentage of items sent per time
2130
+ * If both are provided, minimum number between the two will be used
2131
+ */
2132
+ interface IThrottleLimit {
2133
+ /**
2134
+ * Identifies sampling percentage of items per time
2135
+ * The percentage is set to 4 decimal places, for example: 1 means 0.0001%
2136
+ * Default: 100 (0.01%)
2137
+ */
2138
+ samplingRate?: number;
2139
+ /**
2140
+ * Identifies limit number of items per time
2141
+ * Default: 1
2142
+ */
2143
+ maxSendNumber?: number;
2144
+ }
2145
+
2146
+ /**
2147
+ * Identifies basic config
2148
+ */
2149
+ interface IThrottleMgrConfig {
2150
+ /**
2151
+ * Identifies if throttle is disabled
2152
+ * Default: false
2153
+ */
2154
+ disabled?: boolean;
2155
+ /**
2156
+ * Identifies limit number/percentage of items sent per time
2157
+ * Default: sampling percentage 0.01% with one item sent per time
2158
+ */
2159
+ limit?: IThrottleLimit;
2160
+ /**
2161
+ * Identifies frequency of items sent
2162
+ * Default: send data on 28th every 3 month each year
2163
+ */
2164
+ interval?: IThrottleInterval;
2165
+ }
2166
+
2167
+ /**
2168
+ * A Timer handler which is returned from {@link scheduleTimeout} which contains functions to
2169
+ * cancel or restart (refresh) the timeout function.
2170
+ *
2171
+ * @since 0.4.4
2172
+ * @group Timer
2173
+ */
2174
+ interface ITimerHandler {
2175
+ /**
2176
+ * Cancels a timeout that was previously scheduled, after calling this function any previously
2177
+ * scheduled timer will not execute.
2178
+ * @example
2179
+ * ```ts
2180
+ * let theTimer = scheduleTimeout(...);
2181
+ * theTimer.cancel();
2182
+ * ```
2183
+ */
2184
+ cancel(): void;
2185
+ /**
2186
+ * Reschedules the timer to call its callback at the previously specified duration
2187
+ * adjusted to the current time. This is useful for refreshing a timer without allocating
2188
+ * a new JavaScript object.
2189
+ *
2190
+ * Using this on a timer that has already called its callback will reactivate the timer.
2191
+ * Calling on a timer that has not yet executed will just reschedule the current timer.
2192
+ * @example
2193
+ * ```ts
2194
+ * let theTimer = scheduleTimeout(...);
2195
+ * // The timer will be restarted (if already executed) or rescheduled (if it has not yet executed)
2196
+ * theTimer.refresh();
2197
+ * ```
2198
+ */
2199
+ refresh(): ITimerHandler;
2200
+ /**
2201
+ * When called, requests that the event loop not exit so long when the ITimerHandler is active.
2202
+ * Calling timer.ref() multiple times will have no effect. By default, all ITimerHandler objects
2203
+ * will create "ref'ed" instances, making it normally unnecessary to call timer.ref() unless
2204
+ * timer.unref() had been called previously.
2205
+ * @since 0.7.0
2206
+ * @returns the ITimerHandler instance
2207
+ * @example
2208
+ * ```ts
2209
+ * let theTimer = createTimeout(...);
2210
+ *
2211
+ * // Make sure the timer is referenced (the default) so that the runtime (Node) does not terminate
2212
+ * // if there is a waiting referenced timer.
2213
+ * theTimer.ref();
2214
+ * ```
2215
+ */
2216
+ ref(): this;
2217
+ /**
2218
+ * When called, the any active ITimerHandler instance will not require the event loop to remain
2219
+ * active (Node.js). If there is no other activity keeping the event loop running, the process may
2220
+ * exit before the ITimerHandler instance callback is invoked. Calling timer.unref() multiple times
2221
+ * will have no effect.
2222
+ * @since 0.7.0
2223
+ * @returns the ITimerHandler instance
2224
+ * @example
2225
+ * ```ts
2226
+ * let theTimer = createTimeout(...);
2227
+ *
2228
+ * // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
2229
+ * theTimer.unref();
2230
+ * ```
2231
+ */
2232
+ unref(): this;
2233
+ /**
2234
+ * If true, any running referenced `ITimerHandler` instance will keep the Node.js event loop active.
2235
+ * @since 0.7.0
2236
+ * @example
2237
+ * ```ts
2238
+ * let theTimer = createTimeout(...);
2239
+ *
2240
+ * // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
2241
+ * theTimer.unref();
2242
+ * let hasRef = theTimer.hasRef(); // false
2243
+ *
2244
+ * theTimer.ref();
2245
+ * hasRef = theTimer.hasRef(); // true
2246
+ * ```
2247
+ */
2248
+ hasRef(): boolean;
2249
+ /**
2250
+ * Gets or Sets a flag indicating if the underlying timer is currently enabled and running.
2251
+ * Setting the enabled flag to the same as it's current value has no effect, setting to `true`
2252
+ * when already `true` will not {@link ITimerHandler.refresh | refresh}() the timer.
2253
+ * And setting to 'false` will {@link ITimerHandler.cancel | cancel}() the timer.
2254
+ * @since 0.8.1
2255
+ * @example
2256
+ * ```ts
2257
+ * let theTimer = createTimeout(...);
2258
+ *
2259
+ * // Check if enabled
2260
+ * theTimer.enabled; // false
2261
+ *
2262
+ * // Start the timer
2263
+ * theTimer.enabled = true; // Same as calling refresh()
2264
+ * theTimer.enabled; //true
2265
+ *
2266
+ * // Has no effect as it's already running
2267
+ * theTimer.enabled = true;
2268
+ *
2269
+ * // Will refresh / restart the time
2270
+ * theTimer.refresh()
2271
+ *
2272
+ * let theTimer = scheduleTimeout(...);
2273
+ *
2274
+ * // Check if enabled
2275
+ * theTimer.enabled; // true
2276
+ * ```
2277
+ */
2278
+ enabled: boolean;
2279
+ }
2280
+
2281
+ /**
2282
+ * An interface which provides automatic removal during unloading of the component
2283
+ */
2284
+ interface IUnloadHook {
2285
+ /**
2286
+ * Self remove the referenced component
2287
+ */
2288
+ rm: () => void;
2289
+ }
2290
+
2291
+ /**
2292
+ * Interface which identifiesAdd this hook so that it is automatically removed during unloading
2293
+ * @param hooks - The single hook or an array of IInstrumentHook objects
2294
+ */
2295
+ interface IUnloadHookContainer {
2296
+ add: (hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>) => void;
2297
+ run: (logger?: IDiagnosticLogger) => void;
2298
+ }
2299
+
2300
+ interface IWatchDetails<T = IConfiguration> {
2301
+ /**
2302
+ * The current config object
2303
+ */
2304
+ cfg: T;
2305
+ /**
2306
+ * Set the value against the provided config/name with the value, the property
2307
+ * will be converted to be dynamic (if not already) as long as the provided config
2308
+ * is already a tracked dynamic object.
2309
+ * @throws TypeError if the provided config is not a monitored dynamic config
2310
+ */
2311
+ set: <C, V>(theConfig: C, name: string, value: V) => V;
2312
+ /**
2313
+ * Set default values for the config if not present.
2314
+ * @param theConfig - The configuration object to set default on (if missing)
2315
+ * @param defaultValues - The default values to apply to the config
2316
+ */
2317
+ setDf: <C>(theConfig: C, defaultValues: IConfigDefaults<C>) => C;
2318
+ /**
2319
+ * Set this named property of the target as referenced, which will cause any object or array instance
2320
+ * to be updated in-place rather than being entirely replaced. All other values will continue to be replaced.
2321
+ * @returns The referenced properties current value
2322
+ */
2323
+ ref: <C, V = any>(target: C, name: string) => V;
2324
+ /**
2325
+ * Set this named property of the target as read-only, which will block this single named property from
2326
+ * ever being changed for the target instance.
2327
+ * This does NOT freeze or seal the instance, it just stops the direct re-assignment of the named property,
2328
+ * if the value is a non-primitive (ie. an object or array) it's properties will still be mutable.
2329
+ * @returns The referenced properties current value
2330
+ */
2331
+ rdOnly: <C, V = any>(target: C, name: string) => V;
2332
+ }
2333
+
2334
+ const LoggingSeverity: EnumValue<typeof eLoggingSeverity>;
2335
+
2336
+ type LoggingSeverity = number | eLoggingSeverity;
2337
+
2338
+ /**
2339
+ * This defines the handler function for when a promise is rejected.
2340
+ * @param value This is the value passed as part of resolving the Promise
2341
+ * @return This may return a value, another Promise or void. @see {@link IPromise.then} for how the value is handled.
2342
+ */
2343
+ type RejectedPromiseHandler<T = never> = (((reason: any) => T | IPromise<T> | PromiseLike<T>) | undefined | null);
2344
+
2345
+ /**
2346
+ * This defines the handler function for when a promise is resolved.
2347
+ * @param value This is the value passed as part of resolving the Promise
2348
+ * @return This may return a value, another Promise or void. @see {@link IPromise.then} for how the value is handled.
2349
+ */
2350
+ type ResolvedPromiseHandler<T, TResult1 = T> = (((value: T) => TResult1 | IPromise<TResult1> | PromiseLike<TResult1>) | undefined | null);
2351
+
2352
+ /**
2353
+ * The EventsDiscardedReason enumeration contains a set of values that specify the reason for discarding an event.
2354
+ */
2355
+ const enum SendRequestReason {
2356
+ /**
2357
+ * No specific reason was specified
2358
+ */
2359
+ Undefined = 0,
2360
+ /**
2361
+ * Events are being sent based on the normal event schedule / timer.
2362
+ */
2363
+ NormalSchedule = 1,
2364
+ /**
2365
+ * A manual flush request was received
2366
+ */
2367
+ ManualFlush = 1,
2368
+ /**
2369
+ * Unload event is being processed
2370
+ */
2371
+ Unload = 2,
2372
+ /**
2373
+ * The event(s) being sent are sync events
2374
+ */
2375
+ SyncEvent = 3,
2376
+ /**
2377
+ * The Channel was resumed
2378
+ */
2379
+ Resumed = 4,
2380
+ /**
2381
+ * The event(s) being sent as a retry
2382
+ */
2383
+ Retry = 5,
2384
+ /**
2385
+ * The SDK is unloading
2386
+ */
2387
+ SdkUnload = 6,
2388
+ /**
2389
+ * Maximum batch size would be exceeded
2390
+ */
2391
+ MaxBatchSize = 10,
2392
+ /**
2393
+ * The Maximum number of events have already been queued
2394
+ */
2395
+ MaxQueuedEvents = 20
2396
+ }
2397
+
2398
+ interface Tags {
2399
+ [key: string]: any;
2400
+ }
2401
+
41
2402
  class TeeChannel extends BaseTelemetryPlugin implements IChannelControlsHost {
42
2403
  readonly identifier: string;
43
2404
  readonly priority: number;
@@ -105,5 +2466,54 @@ declare namespace ApplicationInsights {
105
2466
  getChannel<T extends IPlugin = IPlugin>(pluginIdentifier: string): T;
106
2467
  }
107
2468
 
108
-
2469
+ type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
2470
+
2471
+ /**
2472
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
2473
+ */
2474
+ const enum TelemetryUnloadReason {
2475
+ /**
2476
+ * Teardown has been called without any context.
2477
+ */
2478
+ ManualTeardown = 0,
2479
+ /**
2480
+ * Just this plugin is being removed
2481
+ */
2482
+ PluginUnload = 1,
2483
+ /**
2484
+ * This instance of the plugin is being removed and replaced
2485
+ */
2486
+ PluginReplace = 2,
2487
+ /**
2488
+ * The entire SDK is being unloaded
2489
+ */
2490
+ SdkUnload = 50
2491
+ }
2492
+
2493
+ /**
2494
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
2495
+ */
2496
+ const enum TelemetryUpdateReason {
2497
+ /**
2498
+ * Unknown.
2499
+ */
2500
+ Unknown = 0,
2501
+ /**
2502
+ * The configuration has ben updated or changed
2503
+ */
2504
+ ConfigurationChanged = 1,
2505
+ /**
2506
+ * One or more plugins have been added
2507
+ */
2508
+ PluginAdded = 16,
2509
+ /**
2510
+ * One or more plugins have been removed
2511
+ */
2512
+ PluginRemoved = 32
2513
+ }
2514
+
2515
+ type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2516
+
2517
+ type WatcherFunction<T = IConfiguration> = (details: IWatchDetails<T>) => void;
2518
+
109
2519
  }