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