@microsoft/applicationinsights-osplugin-js 3.1.3-nightly3.2404-12

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