@microsoft/applicationinsights-common 3.0.8 → 3.0.9

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 (96) hide show
  1. package/browser/es5/applicationinsights-common.cjs.js +64 -79
  2. package/browser/es5/applicationinsights-common.cjs.js.map +1 -1
  3. package/browser/es5/applicationinsights-common.cjs.min.js +2 -2
  4. package/browser/es5/applicationinsights-common.cjs.min.js.map +1 -1
  5. package/browser/es5/applicationinsights-common.gbl.js +66 -81
  6. package/browser/es5/applicationinsights-common.gbl.js.map +1 -1
  7. package/browser/es5/applicationinsights-common.gbl.min.js +2 -2
  8. package/browser/es5/applicationinsights-common.gbl.min.js.map +1 -1
  9. package/browser/es5/applicationinsights-common.integrity.json +25 -25
  10. package/browser/es5/applicationinsights-common.js +66 -81
  11. package/browser/es5/applicationinsights-common.js.map +1 -1
  12. package/browser/es5/applicationinsights-common.min.js +2 -2
  13. package/browser/es5/applicationinsights-common.min.js.map +1 -1
  14. package/dist/es5/applicationinsights-common.js +64 -79
  15. package/dist/es5/applicationinsights-common.js.map +1 -1
  16. package/dist/es5/applicationinsights-common.min.js +2 -2
  17. package/dist/es5/applicationinsights-common.min.js.map +1 -1
  18. package/dist-es5/ConnectionStringParser.js +1 -1
  19. package/dist-es5/Constants.js +1 -1
  20. package/dist-es5/DomHelperFuncs.js +1 -1
  21. package/dist-es5/Enums.js +1 -1
  22. package/dist-es5/HelperFuncs.js +1 -1
  23. package/dist-es5/Interfaces/ConnectionString.js +1 -1
  24. package/dist-es5/Interfaces/Context/IApplication.js +1 -1
  25. package/dist-es5/Interfaces/Context/IDevice.js +1 -1
  26. package/dist-es5/Interfaces/Context/IInternal.js +1 -1
  27. package/dist-es5/Interfaces/Context/ILocation.js +1 -1
  28. package/dist-es5/Interfaces/Context/IOperatingSystem.js +1 -1
  29. package/dist-es5/Interfaces/Context/ISample.js +1 -1
  30. package/dist-es5/Interfaces/Context/ISession.js +1 -1
  31. package/dist-es5/Interfaces/Context/ISessionManager.js +1 -1
  32. package/dist-es5/Interfaces/Context/ITelemetryTrace.js +1 -1
  33. package/dist-es5/Interfaces/Context/IUser.js +1 -1
  34. package/dist-es5/Interfaces/Context/IWeb.js +1 -1
  35. package/dist-es5/Interfaces/Contracts/AvailabilityData.js +1 -1
  36. package/dist-es5/Interfaces/Contracts/ContextTagKeys.js +1 -1
  37. package/dist-es5/Interfaces/Contracts/DataPointType.js +1 -1
  38. package/dist-es5/Interfaces/Contracts/DependencyKind.js +1 -1
  39. package/dist-es5/Interfaces/Contracts/DependencySourceType.js +1 -1
  40. package/dist-es5/Interfaces/Contracts/IBase.js +1 -1
  41. package/dist-es5/Interfaces/Contracts/IData.js +1 -1
  42. package/dist-es5/Interfaces/Contracts/IDataPoint.js +1 -1
  43. package/dist-es5/Interfaces/Contracts/IDomain.js +1 -1
  44. package/dist-es5/Interfaces/Contracts/IEnvelope.js +1 -1
  45. package/dist-es5/Interfaces/Contracts/IEventData.js +1 -1
  46. package/dist-es5/Interfaces/Contracts/IExceptionData.js +1 -1
  47. package/dist-es5/Interfaces/Contracts/IExceptionDetails.js +1 -1
  48. package/dist-es5/Interfaces/Contracts/IMessageData.js +1 -1
  49. package/dist-es5/Interfaces/Contracts/IMetricData.js +1 -1
  50. package/dist-es5/Interfaces/Contracts/IPageViewData.js +1 -1
  51. package/dist-es5/Interfaces/Contracts/IPageViewPerfData.js +1 -1
  52. package/dist-es5/Interfaces/Contracts/IRemoteDependencyData.js +1 -1
  53. package/dist-es5/Interfaces/Contracts/IStackFrame.js +1 -1
  54. package/dist-es5/Interfaces/Contracts/RequestData.js +1 -1
  55. package/dist-es5/Interfaces/Contracts/SeverityLevel.js +1 -1
  56. package/dist-es5/Interfaces/IAppInsights.js +1 -1
  57. package/dist-es5/Interfaces/IConfig.js +1 -1
  58. package/dist-es5/Interfaces/ICorrelationConfig.js +1 -1
  59. package/dist-es5/Interfaces/IDependencyTelemetry.js +1 -1
  60. package/dist-es5/Interfaces/IEventTelemetry.js +1 -1
  61. package/dist-es5/Interfaces/IExceptionTelemetry.js +1 -1
  62. package/dist-es5/Interfaces/IMetricTelemetry.js +1 -1
  63. package/dist-es5/Interfaces/IPageViewPerformanceTelemetry.js +1 -1
  64. package/dist-es5/Interfaces/IPageViewTelemetry.js +1 -1
  65. package/dist-es5/Interfaces/IPartC.js +1 -1
  66. package/dist-es5/Interfaces/IPropertiesPlugin.js +1 -1
  67. package/dist-es5/Interfaces/IRequestContext.js +1 -1
  68. package/dist-es5/Interfaces/IStorageBuffer.js +1 -1
  69. package/dist-es5/Interfaces/ITelemetryContext.js +1 -1
  70. package/dist-es5/Interfaces/IThrottleMgr.js +1 -1
  71. package/dist-es5/Interfaces/ITraceTelemetry.js +1 -1
  72. package/dist-es5/Interfaces/PartAExtensions.js +1 -1
  73. package/dist-es5/Interfaces/Telemetry/IEnvelope.js +1 -1
  74. package/dist-es5/Interfaces/Telemetry/ISerializable.js +1 -1
  75. package/dist-es5/RequestResponseHeaders.js +1 -1
  76. package/dist-es5/StorageHelperFuncs.js +1 -1
  77. package/dist-es5/Telemetry/Common/Data.js +1 -1
  78. package/dist-es5/Telemetry/Common/DataPoint.js +1 -1
  79. package/dist-es5/Telemetry/Common/DataSanitizer.js +1 -1
  80. package/dist-es5/Telemetry/Common/Envelope.js +1 -1
  81. package/dist-es5/Telemetry/Event.js +1 -1
  82. package/dist-es5/Telemetry/Exception.js +1 -1
  83. package/dist-es5/Telemetry/Metric.js +1 -1
  84. package/dist-es5/Telemetry/PageView.js +1 -1
  85. package/dist-es5/Telemetry/PageViewPerformance.js +1 -1
  86. package/dist-es5/Telemetry/RemoteDependencyData.js +1 -1
  87. package/dist-es5/Telemetry/Trace.js +1 -1
  88. package/dist-es5/TelemetryItemCreator.js +1 -1
  89. package/dist-es5/ThrottleMgr.js +1 -1
  90. package/dist-es5/UrlHelperFuncs.js +1 -1
  91. package/dist-es5/Util.js +1 -1
  92. package/dist-es5/__DynamicConstants.js +1 -1
  93. package/dist-es5/applicationinsights-common.js +1 -1
  94. package/package.json +66 -63
  95. package/types/applicationinsights-common.d.ts +12 -2
  96. package/types/applicationinsights-common.namespaced.d.ts +1975 -65
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights Common JavaScript Library, 3.0.8
2
+ * Microsoft Application Insights Common JavaScript Library, 3.0.9
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -7,28 +7,6 @@
7
7
  */
8
8
 
9
9
  declare namespace ApplicationInsights {
10
- import { createTraceParent } from '@microsoft/applicationinsights-core-js';
11
- import { _eInternalMessageId } from '@microsoft/applicationinsights-core-js';
12
- import { eLoggingSeverity } from '@microsoft/applicationinsights-core-js';
13
- import { EnumValue } from '@microsoft/applicationinsights-core-js';
14
- import { findW3cTraceParent } from '@microsoft/applicationinsights-core-js';
15
- import { formatTraceParent } from '@microsoft/applicationinsights-core-js';
16
- import { IAppInsightsCore } from '@microsoft/applicationinsights-core-js';
17
- import { IConfiguration } from '@microsoft/applicationinsights-core-js';
18
- import { ICookieMgr } from '@microsoft/applicationinsights-core-js';
19
- import { ICustomProperties } from '@microsoft/applicationinsights-core-js';
20
- import { IDiagnosticLogger } from '@microsoft/applicationinsights-core-js';
21
- import { IDistributedTraceContext } from '@microsoft/applicationinsights-core-js';
22
- import { IPlugin } from '@microsoft/applicationinsights-core-js';
23
- import { isBeaconsSupported as isBeaconApiSupported } from '@microsoft/applicationinsights-core-js';
24
- import { isSampledFlag } from '@microsoft/applicationinsights-core-js';
25
- import { isValidSpanId } from '@microsoft/applicationinsights-core-js';
26
- import { isValidTraceId } from '@microsoft/applicationinsights-core-js';
27
- import { isValidTraceParent } from '@microsoft/applicationinsights-core-js';
28
- import { ITelemetryItem } from '@microsoft/applicationinsights-core-js';
29
- import { ITraceParent } from '@microsoft/applicationinsights-core-js';
30
- import { parseTraceParent } from '@microsoft/applicationinsights-core-js';
31
-
32
10
  /**
33
11
  * Data struct to contain only C section with custom fields.
34
12
  */
@@ -125,7 +103,16 @@ declare namespace ApplicationInsights {
125
103
  [key: string]: any;
126
104
  }): ITelemetryItem;
127
105
 
128
-
106
+ /**
107
+ * Create a new ITraceParent instance using the provided values.
108
+ * @param traceId - The traceId to use, when invalid a new random W3C id will be generated.
109
+ * @param spanId - The parent/span id to use, a new random value will be generated if it is invalid.
110
+ * @param flags - The traceFlags to use, defaults to zero (0) if not supplied or invalid
111
+ * @param version - The version to used, defaults to version "01" if not supplied or invalid.
112
+ * @returns
113
+ */
114
+ function createTraceParent(traceId?: string, spanId?: string, flags?: number, version?: string): ITraceParent;
115
+
129
116
  let CtxTagKeys: ContextTagKeys;
130
117
 
131
118
  class Data<TDomain> implements AIData<TDomain>, ISerializable {
@@ -290,6 +277,133 @@ declare namespace ApplicationInsights {
290
277
  W3C = 2
291
278
  }
292
279
 
280
+ const enum _eInternalMessageId {
281
+ BrowserDoesNotSupportLocalStorage = 0,
282
+ BrowserCannotReadLocalStorage = 1,
283
+ BrowserCannotReadSessionStorage = 2,
284
+ BrowserCannotWriteLocalStorage = 3,
285
+ BrowserCannotWriteSessionStorage = 4,
286
+ BrowserFailedRemovalFromLocalStorage = 5,
287
+ BrowserFailedRemovalFromSessionStorage = 6,
288
+ CannotSendEmptyTelemetry = 7,
289
+ ClientPerformanceMathError = 8,
290
+ ErrorParsingAISessionCookie = 9,
291
+ ErrorPVCalc = 10,
292
+ ExceptionWhileLoggingError = 11,
293
+ FailedAddingTelemetryToBuffer = 12,
294
+ FailedMonitorAjaxAbort = 13,
295
+ FailedMonitorAjaxDur = 14,
296
+ FailedMonitorAjaxOpen = 15,
297
+ FailedMonitorAjaxRSC = 16,
298
+ FailedMonitorAjaxSend = 17,
299
+ FailedMonitorAjaxGetCorrelationHeader = 18,
300
+ FailedToAddHandlerForOnBeforeUnload = 19,
301
+ FailedToSendQueuedTelemetry = 20,
302
+ FailedToReportDataLoss = 21,
303
+ FlushFailed = 22,
304
+ MessageLimitPerPVExceeded = 23,
305
+ MissingRequiredFieldSpecification = 24,
306
+ NavigationTimingNotSupported = 25,
307
+ OnError = 26,
308
+ SessionRenewalDateIsZero = 27,
309
+ SenderNotInitialized = 28,
310
+ StartTrackEventFailed = 29,
311
+ StopTrackEventFailed = 30,
312
+ StartTrackFailed = 31,
313
+ StopTrackFailed = 32,
314
+ TelemetrySampledAndNotSent = 33,
315
+ TrackEventFailed = 34,
316
+ TrackExceptionFailed = 35,
317
+ TrackMetricFailed = 36,
318
+ TrackPVFailed = 37,
319
+ TrackPVFailedCalc = 38,
320
+ TrackTraceFailed = 39,
321
+ TransmissionFailed = 40,
322
+ FailedToSetStorageBuffer = 41,
323
+ FailedToRestoreStorageBuffer = 42,
324
+ InvalidBackendResponse = 43,
325
+ FailedToFixDepricatedValues = 44,
326
+ InvalidDurationValue = 45,
327
+ TelemetryEnvelopeInvalid = 46,
328
+ CreateEnvelopeError = 47,
329
+ MaxUnloadHookExceeded = 48,
330
+ CannotSerializeObject = 48,
331
+ CannotSerializeObjectNonSerializable = 49,
332
+ CircularReferenceDetected = 50,
333
+ ClearAuthContextFailed = 51,
334
+ ExceptionTruncated = 52,
335
+ IllegalCharsInName = 53,
336
+ ItemNotInArray = 54,
337
+ MaxAjaxPerPVExceeded = 55,
338
+ MessageTruncated = 56,
339
+ NameTooLong = 57,
340
+ SampleRateOutOfRange = 58,
341
+ SetAuthContextFailed = 59,
342
+ SetAuthContextFailedAccountName = 60,
343
+ StringValueTooLong = 61,
344
+ StartCalledMoreThanOnce = 62,
345
+ StopCalledWithoutStart = 63,
346
+ TelemetryInitializerFailed = 64,
347
+ TrackArgumentsNotSpecified = 65,
348
+ UrlTooLong = 66,
349
+ SessionStorageBufferFull = 67,
350
+ CannotAccessCookie = 68,
351
+ IdTooLong = 69,
352
+ InvalidEvent = 70,
353
+ FailedMonitorAjaxSetRequestHeader = 71,
354
+ SendBrowserInfoOnUserInit = 72,
355
+ PluginException = 73,
356
+ NotificationException = 74,
357
+ SnippetScriptLoadFailure = 99,
358
+ InvalidInstrumentationKey = 100,
359
+ CannotParseAiBlobValue = 101,
360
+ InvalidContentBlob = 102,
361
+ TrackPageActionEventFailed = 103,
362
+ FailedAddingCustomDefinedRequestContext = 104,
363
+ InMemoryStorageBufferFull = 105,
364
+ InstrumentationKeyDeprecation = 106,
365
+ ConfigWatcherException = 107,
366
+ DynamicConfigException = 108,
367
+ DefaultThrottleMsgKey = 109,
368
+ CdnDeprecation = 110,
369
+ SdkLdrUpdate = 111
370
+ }
371
+
372
+ const enum eLoggingSeverity {
373
+ /**
374
+ * No Logging will be enabled
375
+ */
376
+ DISABLED = 0,
377
+ /**
378
+ * Error will be sent as internal telemetry
379
+ */
380
+ CRITICAL = 1,
381
+ /**
382
+ * Error will NOT be sent as internal telemetry, and will only be shown in browser console
383
+ */
384
+ WARNING = 2,
385
+ /**
386
+ * The Error will NOT be sent as an internal telemetry, and will only be shown in the browser
387
+ * console if the logging level allows it.
388
+ */
389
+ DEBUG = 3
390
+ }
391
+
392
+ /**
393
+ * A type that identifies an enum class generated from a constant enum.
394
+ * @group Enum
395
+ * @typeParam E - The constant enum type
396
+ *
397
+ * Returned from {@link createEnum}
398
+ */
399
+ type EnumCls<E = any> = {
400
+ readonly [key in keyof E extends string | number | symbol ? keyof E : never]: key extends string ? E[key] : key;
401
+ } & {
402
+ readonly [key in keyof E]: E[key];
403
+ };
404
+
405
+ type EnumValue<E = any> = EnumCls<E>;
406
+
293
407
  class Envelope implements IEnvelope {
294
408
  /**
295
409
  * The data contract for serializing this object.
@@ -452,6 +566,21 @@ declare namespace ApplicationInsights {
452
566
  SDKExt: string;
453
567
  };
454
568
 
569
+ const enum FeatureOptInMode {
570
+ /**
571
+ * not set, completely depends on cdn cfg
572
+ */
573
+ none = 1,
574
+ /**
575
+ * try to not apply config from cdn
576
+ */
577
+ disable = 2,
578
+ /**
579
+ * try to apply config from cdn
580
+ */
581
+ enable = 3
582
+ }
583
+
455
584
  /**
456
585
  * Enum is used in aiDataContract to describe how fields are serialized.
457
586
  * For instance: (Fieldtype.Required | FieldType.Array) will mark the field as required and indicate it's an array
@@ -463,14 +592,34 @@ declare namespace ApplicationInsights {
463
592
  Hidden = 4
464
593
  }
465
594
 
466
-
595
+ /**
596
+ * This defines the handler function that is called via the finally when the promise is resolved or rejected
597
+ */
598
+ type FinallyPromiseHandler = (() => void) | undefined | null;
599
+
600
+ /**
601
+ * Helper function to fetch the passed traceparent from the page, looking for it as a meta-tag or a Server-Timing header.
602
+ * @param selectIdx - If the found value is comma separated which is the preferred entry to select, defaults to the first
603
+ * @returns
604
+ */
605
+ function findW3cTraceParent(selectIdx?: number): ITraceParent;
606
+
467
607
  /**
468
608
  * Formats the provided errorObj for display and reporting, it may be a String, Object, integer or undefined depending on the browser.
469
609
  * @param errorObj - The supplied errorObj
470
610
  */
471
611
  function _formatErrorCode(errorObj: any): any;
472
612
 
473
-
613
+ /**
614
+ * Format the ITraceParent value as a string using the supported and know version formats.
615
+ * So even if the passed traceParent is a later version the string value returned from this
616
+ * function will convert it to only the known version formats.
617
+ * This currently only supports version "00" and invalid "ff"
618
+ * @param value - The parsed traceParent value
619
+ * @returns
620
+ */
621
+ function formatTraceParent(value: ITraceParent): string;
622
+
474
623
  function getExtensionByName(extensions: IPlugin[], identifier: string): IPlugin | null;
475
624
 
476
625
  const HttpMethod = "http.method";
@@ -506,6 +655,150 @@ declare namespace ApplicationInsights {
506
655
  }): void;
507
656
  }
508
657
 
658
+ interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider {
659
+ readonly config: CfgType;
660
+ /**
661
+ * The current logger instance for this instance.
662
+ */
663
+ readonly logger: IDiagnosticLogger;
664
+ /**
665
+ * An array of the installed plugins that provide a version
666
+ */
667
+ readonly pluginVersionStringArr: string[];
668
+ /**
669
+ * The formatted string of the installed plugins that contain a version number
670
+ */
671
+ readonly pluginVersionString: string;
672
+ /**
673
+ * Returns a value that indicates whether the instance has already been previously initialized.
674
+ */
675
+ isInitialized?: () => boolean;
676
+ initialize(config: CfgType, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
677
+ getChannels(): IChannelControls[];
678
+ track(telemetryItem: ITelemetryItem): void;
679
+ /**
680
+ * Get the current notification manager
681
+ */
682
+ getNotifyMgr(): INotificationManager;
683
+ /**
684
+ * Get the current cookie manager for this instance
685
+ */
686
+ getCookieMgr(): ICookieMgr;
687
+ /**
688
+ * Set the current cookie manager for this instance
689
+ * @param cookieMgr - The manager, if set to null/undefined will cause the default to be created
690
+ */
691
+ setCookieMgr(cookieMgr: ICookieMgr): void;
692
+ /**
693
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
694
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
695
+ * called.
696
+ * @param listener - An INotificationListener object.
697
+ */
698
+ addNotificationListener?(listener: INotificationListener): void;
699
+ /**
700
+ * Removes all instances of the listener.
701
+ * @param listener - INotificationListener to remove.
702
+ */
703
+ removeNotificationListener?(listener: INotificationListener): void;
704
+ /**
705
+ * Add a telemetry processor to decorate or drop telemetry events.
706
+ * @param telemetryInitializer - The Telemetry Initializer function
707
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
708
+ */
709
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler;
710
+ pollInternalLogs?(eventName?: string): ITimerHandler;
711
+ stopPollingInternalLogs?(): void;
712
+ /**
713
+ * Return a new instance of the IProcessTelemetryContext for processing events
714
+ */
715
+ getProcessTelContext(): IProcessTelemetryContext;
716
+ /**
717
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
718
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
719
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
720
+ * approach is to create a new instance and initialize that instance.
721
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
722
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
723
+ * 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)
724
+ * will be returned which will resolve once the unload is complete. The actual implementation of the `IPromise`
725
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
726
+ * @param isAsync - Can the unload be performed asynchronously (default)
727
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
728
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the
729
+ * unload. Defaults to 5 seconds.
730
+ * @return Nothing or if occurring asynchronously a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
731
+ * which will be resolved once the unload is complete, the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
732
+ * will only be returned when no callback is provided and isAsync is true
733
+ */
734
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void | IPromise<ITelemetryUnloadState>;
735
+ /**
736
+ * Find and return the (first) plugin with the specified identifier if present
737
+ * @param pluginIdentifier
738
+ */
739
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
740
+ /**
741
+ * Add a new plugin to the installation
742
+ * @param plugin - The new plugin to add
743
+ * @param replaceExisting - should any existing plugin be replaced, default is false
744
+ * @param doAsync - Should the add be performed asynchronously
745
+ * @param addCb - [Optional] callback to call after the plugin has been added
746
+ */
747
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
748
+ /**
749
+ * Update the configuration used and broadcast the changes to all loaded plugins, this does NOT support updating, adding or removing
750
+ * any the plugins (extensions or channels). It will notify each plugin (if supported) that the configuration has changed but it will
751
+ * not remove or add any new plugins, you need to call addPlugin or getPlugin(identifier).remove();
752
+ * @param newConfig - The new configuration is apply
753
+ * @param mergeExisting - Should the new configuration merge with the existing or just replace it. Default is to merge.
754
+ */
755
+ updateCfg(newConfig: CfgType, mergeExisting?: boolean): void;
756
+ /**
757
+ * Returns the unique event namespace that should be used when registering events
758
+ */
759
+ evtNamespace(): string;
760
+ /**
761
+ * Add a handler that will be called when the SDK is being unloaded
762
+ * @param handler - the handler
763
+ */
764
+ addUnloadCb(handler: UnloadHandler): void;
765
+ /**
766
+ * Add this hook so that it is automatically removed during unloading
767
+ * @param hooks - The single hook or an array of IInstrumentHook objects
768
+ */
769
+ addUnloadHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>): void;
770
+ /**
771
+ * Flush and send any batched / cached data immediately
772
+ * @param async - send data asynchronously when true (defaults to true)
773
+ * @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.
774
+ * If the caller doesn't return true the caller should assume that it may never be called.
775
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
776
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
777
+ * @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
778
+ */
779
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
780
+ /**
781
+ * Gets the current distributed trace context for this instance if available
782
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
783
+ */
784
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
785
+ /**
786
+ * Sets the current distributed trace context for this instance if available
787
+ */
788
+ setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
789
+ /**
790
+ * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
791
+ * handler will be recalled.
792
+ * @param handler
793
+ * @returns A watcher handler instance that can be used to remove itself when being unloaded
794
+ */
795
+ onCfgChange(handler: WatcherFunction<CfgType>): IUnloadHook;
796
+ /**
797
+ * Function used to identify the get w parameter used to identify status bit to some channels
798
+ */
799
+ getWParam: () => number;
800
+ }
801
+
509
802
  interface IApplication {
510
803
  /**
511
804
  * The application version.
@@ -579,6 +872,106 @@ declare namespace ApplicationInsights {
579
872
  errorSrc?: string;
580
873
  }
581
874
 
875
+ interface IBaseProcessingContext {
876
+ /**
877
+ * The current core instance for the request
878
+ */
879
+ core: () => IAppInsightsCore;
880
+ /**
881
+ * THe current diagnostic logger for the request
882
+ */
883
+ diagLog: () => IDiagnosticLogger;
884
+ /**
885
+ * Gets the current core config instance
886
+ */
887
+ getCfg: () => IConfiguration;
888
+ /**
889
+ * Gets the named extension config
890
+ */
891
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
892
+ /**
893
+ * Gets the named config from either the named identifier extension or core config if neither exist then the
894
+ * default value is returned
895
+ * @param identifier - The named extension identifier
896
+ * @param field - The config field name
897
+ * @param defaultValue - The default value to return if no defined config exists
898
+ */
899
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
900
+ /**
901
+ * Helper to allow plugins to check and possibly shortcut executing code only
902
+ * required if there is a nextPlugin
903
+ */
904
+ hasNext: () => boolean;
905
+ /**
906
+ * Returns the next configured plugin proxy
907
+ */
908
+ getNext: () => ITelemetryPluginChain;
909
+ /**
910
+ * Helper to set the next plugin proxy
911
+ */
912
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
913
+ /**
914
+ * Synchronously iterate over the context chain running the callback for each plugin, once
915
+ * every plugin has been executed via the callback, any associated onComplete will be called.
916
+ * @param callback - The function call for each plugin in the context chain
917
+ */
918
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
919
+ /**
920
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
921
+ * @param onComplete - The onComplete to call
922
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
923
+ * @param args - Any additional arguments to pass to the onComplete function
924
+ */
925
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
926
+ /**
927
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
928
+ * @param plugins - The execution order to process the plugins, if null or not supplied
929
+ * then the current execution order will be copied.
930
+ * @param startAt - The plugin to start processing from, if missing from the execution
931
+ * order then the next plugin will be NOT set.
932
+ */
933
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
934
+ }
935
+
936
+ /**
937
+ * Provides data transmission capabilities
938
+ */
939
+ interface IChannelControls extends ITelemetryPlugin {
940
+ /**
941
+ * Pause sending data
942
+ */
943
+ pause?(): void;
944
+ /**
945
+ * Resume sending data
946
+ */
947
+ resume?(): void;
948
+ /**
949
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
950
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
951
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
952
+ * @param unloadCtx - This is the context that should be used during unloading.
953
+ * @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.
954
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
955
+ */
956
+ teardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
957
+ /**
958
+ * Flush to send data immediately; channel should default to sending data asynchronously. If executing asynchronously and
959
+ * you DO NOT pass a callback function then a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
960
+ * will be returned which will resolve once the flush is complete. The actual implementation of the `IPromise`
961
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
962
+ * @param async - send data asynchronously when true
963
+ * @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.
964
+ * If the caller doesn't return true the caller should assume that it may never be called.
965
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
966
+ * @returns - If a callback is provided `true` to indicate that callback will be called after the flush is complete otherwise the caller
967
+ * should assume that any provided callback will never be called, Nothing or if occurring asynchronously a
968
+ * [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) which will be resolved once the unload is complete,
969
+ * the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) will only be returned when no callback is provided
970
+ * and async is true.
971
+ */
972
+ flush?(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void | IPromise<boolean>;
973
+ }
974
+
582
975
  /**
583
976
  * Configuration settings for how telemetry is sent
584
977
  * @export
@@ -894,6 +1287,237 @@ declare namespace ApplicationInsights {
894
1287
  };
895
1288
  }
896
1289
 
1290
+ /**
1291
+ * The type to identify whether the default value should be applied in preference to the provided value.
1292
+ */
1293
+ type IConfigCheckFn<V> = (value: V) => boolean;
1294
+
1295
+ /**
1296
+ * The default values with a check function
1297
+ */
1298
+ interface IConfigDefaultCheck<T, V, C = IConfiguration> {
1299
+ /**
1300
+ * Callback function to check if the user-supplied value is valid, if not the default will be applied
1301
+ */
1302
+ isVal?: IConfigCheckFn<V>;
1303
+ /**
1304
+ * Optional function to allow converting and setting of the default value
1305
+ */
1306
+ set?: IConfigSetFn<T, V>;
1307
+ /**
1308
+ * The default value to apply if the user-supplied value is not valid
1309
+ */
1310
+ v?: V | IConfigDefaults<V, T>;
1311
+ /**
1312
+ * The default fallback key if the main key is not present, this is the key value from the config
1313
+ */
1314
+ fb?: keyof T | keyof C | Array<keyof T | keyof C>;
1315
+ /**
1316
+ * Use this check to determine the default fallback, default only checked whether the property isDefined,
1317
+ * therefore `null`; `""` are considered to be valid values.
1318
+ */
1319
+ dfVal?: (value: any) => boolean;
1320
+ /**
1321
+ * Specify that any provided value should have the default value(s) merged into the value rather than
1322
+ * just using either the default of user provided values. Mergeed objects will automatically be marked
1323
+ * as referenced.
1324
+ */
1325
+ mrg?: boolean;
1326
+ /**
1327
+ * Set this field of the target as referenced, which will cause any object or array instance
1328
+ * to be updated in-place rather than being entirely replaced. All other values will continue to be replaced.
1329
+ * This is required for nested default objects to avoid multiple repetitive updates to listeners
1330
+ * @returns The referenced properties current value
1331
+ */
1332
+ ref?: boolean;
1333
+ /**
1334
+ * Set this field of the target as read-only, which will block this single named property from
1335
+ * ever being changed for the target instance.
1336
+ * This does NOT freeze or seal the instance, it just stops the direct re-assignment of the named property,
1337
+ * if the value is a non-primitive (ie. an object or array) it's properties will still be mutable.
1338
+ * @returns The referenced properties current value
1339
+ */
1340
+ rdOnly?: boolean;
1341
+ /**
1342
+ * Block the value associated with this property from having it's properties / values converted into
1343
+ * dynamic properties, this is generally used to block objects or arrays provided by external libraries
1344
+ * which may be a plain object with readonly (non-configurable) or const properties.
1345
+ */
1346
+ blkVal?: boolean;
1347
+ }
1348
+
1349
+ /**
1350
+ * The Type definition to define default values to be applied to the config
1351
+ * The value may be either the direct value or a ConfigDefaultCheck definition
1352
+ */
1353
+ type IConfigDefaults<T, C = IConfiguration> = {
1354
+ [key in keyof T]: T[key] | IConfigDefaultCheck<T, T[key], C>;
1355
+ };
1356
+
1357
+ /**
1358
+ * The type which identifies the function use to validate the user supplied value
1359
+ */
1360
+ type IConfigSetFn<T, V> = (value: any, defValue: V, theConfig: T) => V;
1361
+
1362
+ /**
1363
+ * Configuration provided to SDK core
1364
+ */
1365
+ interface IConfiguration {
1366
+ /**
1367
+ * Instrumentation key of resource. Either this or connectionString must be specified.
1368
+ */
1369
+ instrumentationKey?: string;
1370
+ /**
1371
+ * Connection string of resource. Either this or instrumentationKey must be specified.
1372
+ */
1373
+ connectionString?: string;
1374
+ /**
1375
+ * Set the timer interval (in ms) for internal logging queue, this is the
1376
+ * amount of time to wait after logger.queue messages are detected to be sent.
1377
+ * Note: since 3.0.1 and 2.8.13 the diagnostic logger timer is a normal timeout timer
1378
+ * and not an interval timer. So this now represents the timer "delay" and not
1379
+ * the frequency at which the events are sent.
1380
+ */
1381
+ diagnosticLogInterval?: number;
1382
+ /**
1383
+ * Maximum number of iKey transmitted logging telemetry per page view
1384
+ */
1385
+ maxMessageLimit?: number;
1386
+ /**
1387
+ * Console logging level. All logs with a severity level higher
1388
+ * than the configured level will be printed to console. Otherwise
1389
+ * they are suppressed. ie Level 2 will print both CRITICAL and
1390
+ * WARNING logs to console, level 1 prints only CRITICAL.
1391
+ *
1392
+ * Note: Logs sent as telemetry to instrumentation key will also
1393
+ * be logged to console if their severity meets the configured loggingConsoleLevel
1394
+ *
1395
+ * 0: ALL console logging off
1396
+ * 1: logs to console: severity >= CRITICAL
1397
+ * 2: logs to console: severity >= WARNING
1398
+ */
1399
+ loggingLevelConsole?: number;
1400
+ /**
1401
+ * Telemtry logging level to instrumentation key. All logs with a severity
1402
+ * level higher than the configured level will sent as telemetry data to
1403
+ * the configured instrumentation key.
1404
+ *
1405
+ * 0: ALL iKey logging off
1406
+ * 1: logs to iKey: severity >= CRITICAL
1407
+ * 2: logs to iKey: severity >= WARNING
1408
+ */
1409
+ loggingLevelTelemetry?: number;
1410
+ /**
1411
+ * If enabled, uncaught exceptions will be thrown to help with debugging
1412
+ */
1413
+ enableDebug?: boolean;
1414
+ /**
1415
+ * Endpoint where telemetry data is sent
1416
+ */
1417
+ endpointUrl?: string;
1418
+ /**
1419
+ * Extension configs loaded in SDK
1420
+ */
1421
+ extensionConfig?: {
1422
+ [key: string]: any;
1423
+ };
1424
+ /**
1425
+ * Additional plugins that should be loaded by core at runtime
1426
+ */
1427
+ readonly extensions?: ITelemetryPlugin[];
1428
+ /**
1429
+ * Channel queues that is setup by caller in desired order.
1430
+ * If channels are provided here, core will ignore any channels that are already setup, example if there is a SKU with an initialized channel
1431
+ */
1432
+ readonly channels?: IChannelControls[][];
1433
+ /**
1434
+ * @type {boolean}
1435
+ * Flag that disables the Instrumentation Key validation.
1436
+ */
1437
+ disableInstrumentationKeyValidation?: boolean;
1438
+ /**
1439
+ * [Optional] When enabled this will create local perfEvents based on sections of the code that have been instrumented
1440
+ * to emit perfEvents (via the doPerf()) when this is enabled. This can be used to identify performance issues within
1441
+ * the SDK, the way you are using it or optionally your own instrumented code.
1442
+ * The provided IPerfManager implementation does NOT send any additional telemetry events to the server it will only fire
1443
+ * the new perfEvent() on the INotificationManager which you can listen to.
1444
+ * This also does not use the window.performance API, so it will work in environments where this API is not supported.
1445
+ */
1446
+ enablePerfMgr?: boolean;
1447
+ /**
1448
+ * [Optional] Callback function that will be called to create a the IPerfManager instance when required and ```enablePerfMgr```
1449
+ * is enabled, this enables you to override the default creation of a PerfManager() without needing to ```setPerfMgr()```
1450
+ * after initialization.
1451
+ */
1452
+ createPerfMgr?: (core: IAppInsightsCore, notificationManager: INotificationManager) => IPerfManager;
1453
+ /**
1454
+ * [Optional] Fire every single performance event not just the top level root performance event. Defaults to false.
1455
+ */
1456
+ perfEvtsSendAll?: boolean;
1457
+ /**
1458
+ * [Optional] Identifies the default length used to generate random session and user id's if non currently exists for the user / session.
1459
+ * Defaults to 22, previous default value was 5, if you need to keep the previous maximum length you should set this value to 5.
1460
+ */
1461
+ idLength?: number;
1462
+ /**
1463
+ * @description Custom cookie domain. This is helpful if you want to share Application Insights cookies across subdomains. It
1464
+ * can be set here or as part of the cookieCfg.domain, the cookieCfg takes precedence if both are specified.
1465
+ * @type {string}
1466
+ * @defaultValue ""
1467
+ */
1468
+ cookieDomain?: string;
1469
+ /**
1470
+ * @description Custom cookie path. This is helpful if you want to share Application Insights cookies behind an application
1471
+ * gateway. It can be set here or as part of the cookieCfg.domain, the cookieCfg takes precedence if both are specified.
1472
+ * @type {string}
1473
+ * @defaultValue ""
1474
+ */
1475
+ cookiePath?: string;
1476
+ /**
1477
+ * [Optional] A boolean that indicated whether to disable the use of cookies by the SDK. If true, the SDK will not store or
1478
+ * read any data from cookies. Cookie usage can be re-enabled after initialization via the core.getCookieMgr().enable().
1479
+ */
1480
+ disableCookiesUsage?: boolean;
1481
+ /**
1482
+ * [Optional] A Cookie Manager configuration which includes hooks to allow interception of the get, set and delete cookie
1483
+ * operations. If this configuration is specified any specified enabled and domain properties will take precedence over the
1484
+ * cookieDomain and disableCookiesUsage values.
1485
+ */
1486
+ cookieCfg?: ICookieMgrConfig;
1487
+ /**
1488
+ * [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
1489
+ * 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.
1490
+ * Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide"
1491
+ */
1492
+ disablePageUnloadEvents?: string[];
1493
+ /**
1494
+ * [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
1495
+ * 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.
1496
+ * Page Show events include "pageshow" and "visibilitychange" (with 'visible' state)
1497
+ */
1498
+ disablePageShowEvents?: string[];
1499
+ /**
1500
+ * [Optional] A flag for performance optimization to disable attempting to use the Chrome Debug Extension, if disabled and the extension is installed
1501
+ * this will not send any notifications.
1502
+ */
1503
+ disableDbgExt?: boolean;
1504
+ /**
1505
+ * Add "&w=0" parameter to support UA Parsing when web-workers don't have access to Document.
1506
+ * Default is false
1507
+ */
1508
+ enableWParam?: boolean;
1509
+ /**
1510
+ * Custom optional value that will be added as a prefix for storage name.
1511
+ * @defaultValue undefined
1512
+ */
1513
+ storagePrefix?: string;
1514
+ /**
1515
+ * Custom optional value to opt in features
1516
+ * @defaultValue undefined
1517
+ */
1518
+ featureOptIn?: IFeatureOptIn;
1519
+ }
1520
+
897
1521
  interface IContextTagKeys {
898
1522
  /**
899
1523
  * Application version. Information in the application context fields is always about the application that is sending the telemetry.
@@ -1065,46 +1689,154 @@ declare namespace ApplicationInsights {
1065
1689
  readonly internalSdkSrc: string;
1066
1690
  }
1067
1691
 
1068
- interface ICorrelationConfig {
1069
- enableCorsCorrelation: boolean;
1070
- correlationHeaderExcludedDomains: string[];
1071
- correlationHeaderExcludePatterns?: RegExp[];
1072
- disableCorrelationHeaders: boolean;
1073
- distributedTracingMode: DistributedTracingModes;
1074
- maxAjaxCallsPerView: number;
1075
- disableAjaxTracking: boolean;
1076
- disableFetchTracking: boolean;
1077
- appId?: string;
1078
- enableRequestHeaderTracking?: boolean;
1079
- enableResponseHeaderTracking?: boolean;
1080
- enableAjaxErrorStatusText?: boolean;
1692
+ interface ICookieMgr {
1081
1693
  /**
1082
- * Flag to enable looking up and including additional browser window.performance timings
1083
- * in the reported ajax (XHR and fetch) reported metrics.
1084
- * Defaults to false.
1694
+ * Enable or Disable the usage of cookies
1085
1695
  */
1086
- enableAjaxPerfTracking?: boolean;
1696
+ setEnabled(value: boolean): void;
1087
1697
  /**
1088
- * The maximum number of times to look for the window.performance timings (if available), this
1089
- * is required as not all browsers populate the window.performance before reporting the
1090
- * end of the XHR request and for fetch requests this is added after its complete
1091
- * Defaults to 3
1698
+ * Can the system use cookies, if this returns false then all cookie setting and access functions will return nothing
1092
1699
  */
1093
- maxAjaxPerfLookupAttempts?: number;
1700
+ isEnabled(): boolean;
1094
1701
  /**
1095
- * The amount of time to wait before re-attempting to find the windows.performance timings
1096
- * for an ajax request, time is in milliseconds and is passed directly to setTimeout()
1097
- * Defaults to 25.
1702
+ * Set the named cookie with the value and optional domain and optional
1703
+ * @param name - The name of the cookie
1704
+ * @param value - The value of the cookie (Must already be encoded)
1705
+ * @param maxAgeSec - [optional] The maximum number of SECONDS that this cookie should survive
1706
+ * @param domain - [optional] The domain to set for the cookie
1707
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
1708
+ * @returns - True if the cookie was set otherwise false (Because cookie usage is not enabled or available)
1098
1709
  */
1099
- ajaxPerfLookupDelay?: number;
1100
- correlationHeaderDomains?: string[];
1710
+ set(name: string, value: string, maxAgeSec?: number, domain?: string, path?: string): boolean;
1101
1711
  /**
1102
- * Response and request headers to be excluded from ajax tracking data.
1712
+ * Get the value of the named cookie
1713
+ * @param name - The name of the cookie
1103
1714
  */
1104
- ignoreHeaders?: string[];
1715
+ get(name: string): string;
1105
1716
  /**
1106
- * Provide a way to exclude specific route from automatic tracking for XMLHttpRequest or Fetch request.
1107
- * For an ajax / fetch request that the request url matches with the regex patterns, auto tracking is turned off.
1717
+ * Delete/Remove the named cookie if cookie support is available and enabled.
1718
+ * Note: Not using "delete" as the name because it's a reserved word which would cause issues on older browsers
1719
+ * @param name - The name of the cookie
1720
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
1721
+ * @returns - True if the cookie was marked for deletion otherwise false (Because cookie usage is not enabled or available)
1722
+ */
1723
+ del(name: string, path?: string): boolean;
1724
+ /**
1725
+ * Purge the cookie from the system if cookie support is available, this function ignores the enabled setting of the manager
1726
+ * so any cookie will be removed.
1727
+ * Note: Not using "delete" as the name because it's a reserved word which would cause issues on older browsers
1728
+ * @param name - The name of the cookie
1729
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
1730
+ * @returns - True if the cookie was marked for deletion otherwise false (Because cookie usage is not available)
1731
+ */
1732
+ purge(name: string, path?: string): boolean;
1733
+ /**
1734
+ * Optional Callback hook to allow the cookie manager to update it's configuration, not generally implemented now that
1735
+ * dynamic configuration is supported
1736
+ * @param updateState
1737
+ */
1738
+ update?(updateState: ITelemetryUpdateState): void;
1739
+ /**
1740
+ * Unload and remove any state that this ICookieMgr may be holding, this is generally called when the
1741
+ * owning SDK is being unloaded.
1742
+ * @param isAsync - Can the unload be performed asynchronously (default)
1743
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1744
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1745
+ * / Promise to allow any listeners to wait for the operation to complete.
1746
+ */
1747
+ unload?(isAsync?: boolean): void | IPromise<void>;
1748
+ }
1749
+
1750
+ /**
1751
+ * Configuration definition for instance based cookie management configuration
1752
+ */
1753
+ interface ICookieMgrConfig {
1754
+ /**
1755
+ * Defaults to true, A boolean that indicates whether the use of cookies by the SDK is enabled by the current instance.
1756
+ * If false, the instance of the SDK initialized by this configuration will not store or read any data from cookies
1757
+ */
1758
+ enabled?: boolean;
1759
+ /**
1760
+ * Custom cookie domain. This is helpful if you want to share Application Insights cookies across subdomains.
1761
+ */
1762
+ domain?: string;
1763
+ /**
1764
+ * Specifies the path to use for the cookie, defaults to '/'
1765
+ */
1766
+ path?: string;
1767
+ /**
1768
+ * Specify the cookie name(s) to be ignored, this will cause any matching cookie name to never be read or written.
1769
+ * They may still be explicitly purged or deleted. You do not need to repeat the name in the `blockedCookies`
1770
+ * configuration.(Since v2.8.8)
1771
+ */
1772
+ ignoreCookies?: string[];
1773
+ /**
1774
+ * Specify the cookie name(s) to never be written, this will cause any cookie name to never be created or updated,
1775
+ * they will still be read unless also included in the ignoreCookies and may still be explicitly purged or deleted.
1776
+ * If not provided defaults to the same list provided in ignoreCookies. (Since v2.8.8)
1777
+ */
1778
+ blockedCookies?: string[];
1779
+ /**
1780
+ * Hook function to fetch the named cookie value.
1781
+ * @param name - The name of the cookie
1782
+ */
1783
+ getCookie?: (name: string) => string;
1784
+ /**
1785
+ * Hook function to set the named cookie with the specified value.
1786
+ * @param name - The name of the cookie
1787
+ * @param value - The value to set for the cookie
1788
+ */
1789
+ setCookie?: (name: string, value: string) => void;
1790
+ /**
1791
+ * Hook function to delete the named cookie with the specified value, separated from
1792
+ * setCookie to avoid the need to parse the value to determine whether the cookie is being
1793
+ * added or removed.
1794
+ * @param name - The name of the cookie
1795
+ * @param cookieValue - The value to set to expire the cookie
1796
+ */
1797
+ delCookie?: (name: string, cookieValue: string) => void;
1798
+ }
1799
+
1800
+ interface ICorrelationConfig {
1801
+ enableCorsCorrelation: boolean;
1802
+ correlationHeaderExcludedDomains: string[];
1803
+ correlationHeaderExcludePatterns?: RegExp[];
1804
+ disableCorrelationHeaders: boolean;
1805
+ distributedTracingMode: DistributedTracingModes;
1806
+ maxAjaxCallsPerView: number;
1807
+ disableAjaxTracking: boolean;
1808
+ disableFetchTracking: boolean;
1809
+ appId?: string;
1810
+ enableRequestHeaderTracking?: boolean;
1811
+ enableResponseHeaderTracking?: boolean;
1812
+ enableAjaxErrorStatusText?: boolean;
1813
+ /**
1814
+ * Flag to enable looking up and including additional browser window.performance timings
1815
+ * in the reported ajax (XHR and fetch) reported metrics.
1816
+ * Defaults to false.
1817
+ */
1818
+ enableAjaxPerfTracking?: boolean;
1819
+ /**
1820
+ * The maximum number of times to look for the window.performance timings (if available), this
1821
+ * is required as not all browsers populate the window.performance before reporting the
1822
+ * end of the XHR request and for fetch requests this is added after its complete
1823
+ * Defaults to 3
1824
+ */
1825
+ maxAjaxPerfLookupAttempts?: number;
1826
+ /**
1827
+ * The amount of time to wait before re-attempting to find the windows.performance timings
1828
+ * for an ajax request, time is in milliseconds and is passed directly to setTimeout()
1829
+ * Defaults to 25.
1830
+ */
1831
+ ajaxPerfLookupDelay?: number;
1832
+ correlationHeaderDomains?: string[];
1833
+ /**
1834
+ * Response and request headers to be excluded from ajax tracking data.
1835
+ */
1836
+ ignoreHeaders?: string[];
1837
+ /**
1838
+ * Provide a way to exclude specific route from automatic tracking for XMLHttpRequest or Fetch request.
1839
+ * For an ajax / fetch request that the request url matches with the regex patterns, auto tracking is turned off.
1108
1840
  * Default is undefined.
1109
1841
  */
1110
1842
  excludeRequestFromAutoTrackingPatterns?: string[] | RegExp[];
@@ -1122,6 +1854,10 @@ declare namespace ApplicationInsights {
1122
1854
  addIntEndpoints?: boolean;
1123
1855
  }
1124
1856
 
1857
+ interface ICustomProperties {
1858
+ [key: string]: any;
1859
+ }
1860
+
1125
1861
  /**
1126
1862
  * Metric data single measurement.
1127
1863
  */
@@ -1196,6 +1932,110 @@ declare namespace ApplicationInsights {
1196
1932
  ip: string;
1197
1933
  }
1198
1934
 
1935
+ interface IDiagnosticLogger {
1936
+ /**
1937
+ * 0: OFF
1938
+ * 1: only critical (default)
1939
+ * 2: critical + info
1940
+ */
1941
+ consoleLoggingLevel: () => number;
1942
+ /**
1943
+ * The internal logging queue
1944
+ */
1945
+ queue: _InternalLogMessage[];
1946
+ /**
1947
+ * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
1948
+ * @param severity - The severity of the log message
1949
+ * @param message - The log message.
1950
+ */
1951
+ throwInternal(severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
1952
+ /**
1953
+ * This will write a debug message to the console if possible
1954
+ * @param message - {string} - The debug message
1955
+ */
1956
+ debugToConsole?(message: string): void;
1957
+ /**
1958
+ * This will write a warning to the console if possible
1959
+ * @param message - The warning message
1960
+ */
1961
+ warnToConsole(message: string): void;
1962
+ /**
1963
+ * This will write an error to the console if possible.
1964
+ * Provided by the default DiagnosticLogger instance, and internally the SDK will fall back to warnToConsole, however,
1965
+ * direct callers MUST check for its existence on the logger as you can provide your own IDiagnosticLogger instance.
1966
+ * @param message - The error message
1967
+ */
1968
+ errorToConsole?(message: string): void;
1969
+ /**
1970
+ * Resets the internal message count
1971
+ */
1972
+ resetInternalMessageCount(): void;
1973
+ /**
1974
+ * Logs a message to the internal queue.
1975
+ * @param severity - The severity of the log message
1976
+ * @param message - The message to log.
1977
+ */
1978
+ logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
1979
+ /**
1980
+ * Optional Callback hook to allow the diagnostic logger to update it's configuration
1981
+ * @param updateState
1982
+ */
1983
+ update?(updateState: ITelemetryUpdateState): void;
1984
+ /**
1985
+ * Unload and remove any state that this IDiagnosticLogger may be holding, this is generally called when the
1986
+ * owning SDK is being unloaded.
1987
+ * @param isAsync - Can the unload be performed asynchronously (default)
1988
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1989
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1990
+ * / Promise to allow any listeners to wait for the operation to complete.
1991
+ */
1992
+ unload?(isAsync?: boolean): void | IPromise<void>;
1993
+ }
1994
+
1995
+ interface IDistributedTraceContext {
1996
+ /**
1997
+ * Returns the current name of the page
1998
+ */
1999
+ getName(): string;
2000
+ /**
2001
+ * Sets the current name of the page
2002
+ * @param pageName
2003
+ */
2004
+ setName(pageName: string): void;
2005
+ /**
2006
+ * Returns the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
2007
+ * Must be read from incoming headers or generated according to the W3C TraceContext specification,
2008
+ * in a hex representation of 16-byte array. A.k.a. trace-id, TraceID or Distributed TraceID
2009
+ */
2010
+ getTraceId(): string;
2011
+ /**
2012
+ * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
2013
+ * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
2014
+ * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
2015
+ */
2016
+ setTraceId(newValue: string): void;
2017
+ /**
2018
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
2019
+ * Also know as the parentId, used to link requests together
2020
+ */
2021
+ getSpanId(): string;
2022
+ /**
2023
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
2024
+ * Also know as the parentId, used to link requests together
2025
+ * https://www.w3.org/TR/trace-context/#parent-id
2026
+ */
2027
+ setSpanId(newValue: string): void;
2028
+ /**
2029
+ * An integer representation of the W3C TraceContext trace-flags.
2030
+ */
2031
+ getTraceFlags(): number | undefined;
2032
+ /**
2033
+ * https://www.w3.org/TR/trace-context/#trace-flags
2034
+ * @param newValue
2035
+ */
2036
+ setTraceFlags(newValue?: number): void;
2037
+ }
2038
+
1199
2039
  /**
1200
2040
  * The abstract common base of all domains.
1201
2041
  */
@@ -1396,6 +2236,41 @@ declare namespace ApplicationInsights {
1396
2236
  severityLevel?: SeverityLevel | number;
1397
2237
  }
1398
2238
 
2239
+ interface IFeatureOptIn {
2240
+ [feature: string]: IFeatureOptInDetails;
2241
+ }
2242
+
2243
+ interface IFeatureOptInDetails {
2244
+ /**
2245
+ * sets feature opt-in mode
2246
+ * @default undefined
2247
+ */
2248
+ mode?: FeatureOptInMode;
2249
+ /**
2250
+ * Identifies configuration override values when given feature is enabled
2251
+ * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
2252
+ * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: {["extensionConfig.Analytics.disableAjaxTrackig"]:1}
2253
+ * Default: undefined
2254
+ */
2255
+ onCfg?: {
2256
+ [field: string]: any;
2257
+ };
2258
+ /**
2259
+ * Identifies configuration override values when given feature is disabled
2260
+ * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
2261
+ * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: {["extensionConfig.Analytics.disableAjaxTrackig"]:1}
2262
+ * Default: undefined
2263
+ */
2264
+ offCfg?: {
2265
+ [field: string]: any;
2266
+ };
2267
+ /**
2268
+ * define if should block any changes from cdn cfg, if set to true, cfgValue will be applied under all scenarios
2269
+ * @default false
2270
+ */
2271
+ blockCdnCfg?: boolean;
2272
+ }
2273
+
1399
2274
  interface IInternal {
1400
2275
  /**
1401
2276
  * The SDK version used to create this telemetry item.
@@ -1420,6 +2295,34 @@ declare namespace ApplicationInsights {
1420
2295
  sdkSrc: string;
1421
2296
  }
1422
2297
 
2298
+ /**
2299
+ * An alternate interface which provides automatic removal during unloading of the component
2300
+ */
2301
+ interface ILegacyUnloadHook {
2302
+ /**
2303
+ * Legacy Self remove the referenced component
2304
+ */
2305
+ remove: () => void;
2306
+ }
2307
+
2308
+ interface ILoadedPlugin<T extends IPlugin> {
2309
+ plugin: T;
2310
+ /**
2311
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
2312
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
2313
+ * @returns boolean = true if the plugin is in a state where it is operational.
2314
+ */
2315
+ isEnabled: () => boolean;
2316
+ /**
2317
+ * You can optionally enable / disable a plugin from processing events.
2318
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
2319
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
2320
+ * (unless it's also been re-initialized)
2321
+ */
2322
+ setEnabled: (isEnabled: boolean) => void;
2323
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
2324
+ }
2325
+
1423
2326
  interface ILocation {
1424
2327
  /**
1425
2328
  * Client IP address for reverse lookup
@@ -1521,6 +2424,105 @@ declare namespace ApplicationInsights {
1521
2424
  iKey?: string;
1522
2425
  }
1523
2426
 
2427
+ /**
2428
+ * An interface used for the notification listener.
2429
+ * @interface
2430
+ */
2431
+ interface INotificationListener {
2432
+ /**
2433
+ * [Optional] A function called when events are sent.
2434
+ * @param events - The array of events that have been sent.
2435
+ */
2436
+ eventsSent?: (events: ITelemetryItem[]) => void;
2437
+ /**
2438
+ * [Optional] A function called when events are discarded.
2439
+ * @param events - The array of events that have been discarded.
2440
+ * @param reason - The reason for discarding the events. The EventsDiscardedReason
2441
+ * constant should be used to check the different values.
2442
+ */
2443
+ eventsDiscarded?: (events: ITelemetryItem[], reason: number) => void;
2444
+ /**
2445
+ * [Optional] A function called when the events have been requested to be sent to the sever.
2446
+ * @param sendReason - The reason why the event batch is being sent.
2447
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
2448
+ */
2449
+ eventsSendRequest?: (sendReason: number, isAsync?: boolean) => void;
2450
+ /**
2451
+ * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
2452
+ * the event can be displayed via the debug plugin extension.
2453
+ * @param perfEvent
2454
+ */
2455
+ perfEvent?: (perfEvent: IPerfEvent) => void;
2456
+ /**
2457
+ * Unload and remove any state that this INotificationListener may be holding, this is generally called when the
2458
+ * owning Manager is being unloaded.
2459
+ * @param isAsync - Can the unload be performed asynchronously (default)
2460
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
2461
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
2462
+ * / Promise to allow any listeners to wait for the operation to complete.
2463
+ */
2464
+ unload?(isAsync?: boolean): void | IPromise<void>;
2465
+ }
2466
+
2467
+ /**
2468
+ * Class to manage sending notifications to all the listeners.
2469
+ */
2470
+ interface INotificationManager {
2471
+ listeners: INotificationListener[];
2472
+ /**
2473
+ * Adds a notification listener.
2474
+ * @param listener - The notification listener to be added.
2475
+ */
2476
+ addNotificationListener(listener: INotificationListener): void;
2477
+ /**
2478
+ * Removes all instances of the listener.
2479
+ * @param listener - AWTNotificationListener to remove.
2480
+ */
2481
+ removeNotificationListener(listener: INotificationListener): void;
2482
+ /**
2483
+ * Notification for events sent.
2484
+ * @param events - The array of events that have been sent.
2485
+ */
2486
+ eventsSent(events: ITelemetryItem[]): void;
2487
+ /**
2488
+ * Notification for events being discarded.
2489
+ * @param events - The array of events that have been discarded by the SDK.
2490
+ * @param reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
2491
+ * constant should be used to check the different values.
2492
+ */
2493
+ eventsDiscarded(events: ITelemetryItem[], reason: number): void;
2494
+ /**
2495
+ * [Optional] A function called when the events have been requested to be sent to the sever.
2496
+ * @param sendReason - The reason why the event batch is being sent.
2497
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
2498
+ */
2499
+ eventsSendRequest?(sendReason: number, isAsync: boolean): void;
2500
+ /**
2501
+ * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
2502
+ * the event can be displayed via the debug plugin extension.
2503
+ * @param perfEvent - The perf event details
2504
+ */
2505
+ perfEvent?(perfEvent: IPerfEvent): void;
2506
+ /**
2507
+ * Unload and remove any state that this INotificationManager may be holding, this is generally called when the
2508
+ * owning SDK is being unloaded.
2509
+ * @param isAsync - Can the unload be performed asynchronously (default)
2510
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
2511
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
2512
+ * / Promise to allow any listeners to wait for the operation to complete.
2513
+ */
2514
+ unload?(isAsync?: boolean): void | IPromise<void>;
2515
+ }
2516
+
2517
+ class _InternalLogMessage {
2518
+ static dataType: string;
2519
+ message: string;
2520
+ messageId: _InternalMessageId;
2521
+ constructor(msgId: _InternalMessageId, msg: string, isUserAct?: boolean, properties?: Object);
2522
+ }
2523
+
2524
+ type _InternalMessageId = number | _eInternalMessageId;
2525
+
1524
2526
  interface IOperatingSystem {
1525
2527
  name: string;
1526
2528
  }
@@ -1701,6 +2703,420 @@ declare namespace ApplicationInsights {
1701
2703
  };
1702
2704
  }
1703
2705
 
2706
+ /**
2707
+ * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
2708
+ */
2709
+ interface IPerfEvent {
2710
+ /**
2711
+ * The name of the performance event
2712
+ */
2713
+ name: string;
2714
+ /**
2715
+ * The start time of the performance event
2716
+ */
2717
+ start: number;
2718
+ /**
2719
+ * The payload (contents) of the perfEvent, may be null or only set after the event has completed depending on
2720
+ * the runtime environment.
2721
+ */
2722
+ payload: any;
2723
+ /**
2724
+ * Is this occurring from an asynchronous event
2725
+ */
2726
+ isAsync: boolean;
2727
+ /**
2728
+ * Identifies the total inclusive time spent for this event, including the time spent for child events,
2729
+ * this will be undefined until the event is completed
2730
+ */
2731
+ time?: number;
2732
+ /**
2733
+ * Identifies the exclusive time spent in for this event (not including child events),
2734
+ * this will be undefined until the event is completed.
2735
+ */
2736
+ exTime?: number;
2737
+ /**
2738
+ * The Parent event that was started before this event was created
2739
+ */
2740
+ parent?: IPerfEvent;
2741
+ /**
2742
+ * The child perf events that are contained within the total time of this event.
2743
+ */
2744
+ childEvts?: IPerfEvent[];
2745
+ /**
2746
+ * Identifies whether this event is a child event of a parent
2747
+ */
2748
+ isChildEvt: () => boolean;
2749
+ /**
2750
+ * Get the names additional context associated with this perf event
2751
+ */
2752
+ getCtx?: (key: string) => any;
2753
+ /**
2754
+ * Set the named additional context to be associated with this perf event, this will replace any existing value
2755
+ */
2756
+ setCtx?: (key: string, value: any) => void;
2757
+ /**
2758
+ * Mark this event as completed, calculating the total execution time.
2759
+ */
2760
+ complete: () => void;
2761
+ }
2762
+
2763
+ /**
2764
+ * This defines an internal performance manager for tracking and reporting the internal performance of the SDK -- It does
2765
+ * not represent or report any event to the server.
2766
+ */
2767
+ interface IPerfManager {
2768
+ /**
2769
+ * Create a new event and start timing, the manager may return null/undefined to indicate that it does not
2770
+ * want to monitor this source event.
2771
+ * @param src - The source name of the event
2772
+ * @param payloadDetails - An optional callback function to fetch the payload details for the event.
2773
+ * @param isAsync - Is the event occurring from a async event
2774
+ */
2775
+ create(src: string, payloadDetails?: () => any, isAsync?: boolean): IPerfEvent | null | undefined;
2776
+ /**
2777
+ * Complete the perfEvent and fire any notifications.
2778
+ * @param perfEvent - Fire the event which will also complete the passed event
2779
+ */
2780
+ fire(perfEvent: IPerfEvent): void;
2781
+ /**
2782
+ * Set an execution context value
2783
+ * @param key - The context key name
2784
+ * @param value - The value
2785
+ */
2786
+ setCtx(key: string, value: any): void;
2787
+ /**
2788
+ * Get the execution context value
2789
+ * @param key - The context key
2790
+ */
2791
+ getCtx(key: string): any;
2792
+ }
2793
+
2794
+ /**
2795
+ * Identifies an interface to a host that can provide an IPerfManager implementation
2796
+ */
2797
+ interface IPerfManagerProvider {
2798
+ /**
2799
+ * Get the current performance manager
2800
+ */
2801
+ getPerfMgr(): IPerfManager;
2802
+ /**
2803
+ * Set the current performance manager
2804
+ * @param perfMgr - The performance manager
2805
+ */
2806
+ setPerfMgr(perfMgr: IPerfManager): void;
2807
+ }
2808
+
2809
+ interface IPlugin {
2810
+ /**
2811
+ * Initialize plugin loaded by SDK
2812
+ * @param config - The config for the plugin to use
2813
+ * @param core - The current App Insights core to use for initializing this plugin instance
2814
+ * @param extensions - The complete set of extensions to be used for initializing the plugin
2815
+ * @param pluginChain - [Optional] specifies the current plugin chain which identifies the
2816
+ * set of plugins and the order they should be executed for the current request.
2817
+ */
2818
+ initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) => void;
2819
+ /**
2820
+ * Returns a value that indicates whether the plugin has already been previously initialized.
2821
+ * New plugins should implement this method to avoid being initialized more than once.
2822
+ */
2823
+ isInitialized?: () => boolean;
2824
+ /**
2825
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
2826
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
2827
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
2828
+ * @param unloadCtx - This is the context that should be used during unloading.
2829
+ * @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.
2830
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
2831
+ */
2832
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
2833
+ /**
2834
+ * Extension name
2835
+ */
2836
+ readonly identifier: string;
2837
+ /**
2838
+ * Plugin version (available in data.properties.version in common schema)
2839
+ */
2840
+ readonly version?: string;
2841
+ /**
2842
+ * The App Insights core to use for backward compatibility.
2843
+ * Therefore the interface will be able to access the core without needing to cast to "any".
2844
+ * [optional] any 3rd party plugins which are already implementing this interface don't fail to compile.
2845
+ */
2846
+ core?: IAppInsightsCore;
2847
+ }
2848
+
2849
+ /**
2850
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
2851
+ * between multiple AppInsights instances
2852
+ */
2853
+ interface IProcessTelemetryContext extends IBaseProcessingContext {
2854
+ /**
2855
+ * Call back for telemetry processing before it it is sent
2856
+ * @param env - This is the current event being reported
2857
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
2858
+ */
2859
+ processNext: (env: ITelemetryItem) => boolean | void;
2860
+ /**
2861
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
2862
+ * @param plugins - The execution order to process the plugins, if null or not supplied
2863
+ * then the current execution order will be copied.
2864
+ * @param startAt - The plugin to start processing from, if missing from the execution
2865
+ * order then the next plugin will be NOT set.
2866
+ */
2867
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
2868
+ }
2869
+
2870
+ /**
2871
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
2872
+ * or the SDK is being unloaded.
2873
+ */
2874
+ interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
2875
+ /**
2876
+ * This Plugin has finished unloading, so unload the next one
2877
+ * @param uploadState - The state of the unload process
2878
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
2879
+ */
2880
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
2881
+ /**
2882
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
2883
+ * @param plugins - The execution order to process the plugins, if null or not supplied
2884
+ * then the current execution order will be copied.
2885
+ * @param startAt - The plugin to start processing from, if missing from the execution
2886
+ * order then the next plugin will be NOT set.
2887
+ */
2888
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
2889
+ }
2890
+
2891
+ /**
2892
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
2893
+ * for when plugins are added, removed or the configuration was changed.
2894
+ */
2895
+ interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
2896
+ /**
2897
+ * This Plugin has finished unloading, so unload the next one
2898
+ * @param updateState - The update State
2899
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
2900
+ */
2901
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
2902
+ /**
2903
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
2904
+ * @param plugins - The execution order to process the plugins, if null or not supplied
2905
+ * then the current execution order will be copied.
2906
+ * @param startAt - The plugin to start processing from, if missing from the execution
2907
+ * order then the next plugin will be NOT set.
2908
+ */
2909
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
2910
+ }
2911
+
2912
+ /**
2913
+ * Create a Promise object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
2914
+ * This interface definition, closely mirrors the typescript / javascript PromiseLike<T> and Promise<T> definitions as well as providing
2915
+ * simular functions as that provided by jQuery deferred objects.
2916
+ *
2917
+ * The returned Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers
2918
+ * with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous
2919
+ * methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point
2920
+ * in the future.
2921
+ *
2922
+ * A Promise is in one of these states:
2923
+ * <ul>
2924
+ * <li> pending: initial state, neither fulfilled nor rejected.
2925
+ * <li> fulfilled: meaning that the operation was completed successfully.
2926
+ * <li> rejected: meaning that the operation failed.
2927
+ * </ul>
2928
+ *
2929
+ * A pending promise can either be fulfilled with a value or rejected with a reason (error). When either of these options happens, the
2930
+ * associated handlers queued up by a promise's then method are called synchronously. If the promise has already been fulfilled or rejected
2931
+ * when a corresponding handler is attached, the handler will be called synchronously, so there is no race condition between an asynchronous
2932
+ * operation completing and its handlers being attached.
2933
+ *
2934
+ * As the `then()` and `catch()` methods return promises, they can be chained.
2935
+ * @typeParam T - Identifies the expected return type from the promise
2936
+ */
2937
+ interface IPromise<T> extends PromiseLike<T>, Promise<T> {
2938
+ /**
2939
+ * Returns a string representation of the current state of the promise. The promise can be in one of four states.
2940
+ * <ul>
2941
+ * <li> <b>"pending"</b>: The promise is not yet in a completed state (neither "rejected"; or "resolved").</li>
2942
+ * <li> <b>"resolved"</b>: The promise is in the resolved state.</li>
2943
+ * <li> <b>"rejected"</b>: The promise is in the rejected state.</li>
2944
+ * </ul>
2945
+ * @example
2946
+ * ```ts
2947
+ * let doResolve;
2948
+ * let promise: IPromise<any> = createSyncPromise((resolve) => {
2949
+ * doResolve = resolve;
2950
+ * });
2951
+ *
2952
+ * let state: string = promise.state();
2953
+ * console.log("State: " + state); // State: pending
2954
+ * doResolve(true); // Promise will resolve synchronously as it's a synchronous promise
2955
+ * console.log("State: " + state); // State: resolved
2956
+ * ```
2957
+ */
2958
+ state?: string;
2959
+ /**
2960
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
2961
+ * @param onResolved The callback to execute when the Promise is resolved.
2962
+ * @param onRejected The callback to execute when the Promise is rejected.
2963
+ * @returns A Promise for the completion of which ever callback is executed.
2964
+ * @example
2965
+ * ```ts
2966
+ * const promise1 = createPromise((resolve, reject) => {
2967
+ * resolve('Success!');
2968
+ * });
2969
+ *
2970
+ * promise1.then((value) => {
2971
+ * console.log(value);
2972
+ * // expected output: "Success!"
2973
+ * });
2974
+ * ```
2975
+ */
2976
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): IPromise<TResult1 | TResult2>;
2977
+ /**
2978
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
2979
+ * @param onResolved The callback to execute when the Promise is resolved.
2980
+ * @param onRejected The callback to execute when the Promise is rejected.
2981
+ * @returns A Promise for the completion of which ever callback is executed.
2982
+ * @example
2983
+ * ```ts
2984
+ * const promise1 = createPromise((resolve, reject) => {
2985
+ * resolve('Success!');
2986
+ * });
2987
+ *
2988
+ * promise1.then((value) => {
2989
+ * console.log(value);
2990
+ * // expected output: "Success!"
2991
+ * });
2992
+ * ```
2993
+ */
2994
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): PromiseLike<TResult1 | TResult2>;
2995
+ /**
2996
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
2997
+ * @param onResolved The callback to execute when the Promise is resolved.
2998
+ * @param onRejected The callback to execute when the Promise is rejected.
2999
+ * @returns A Promise for the completion of which ever callback is executed.
3000
+ * @example
3001
+ * ```ts
3002
+ * const promise1 = createPromise((resolve, reject) => {
3003
+ * resolve('Success!');
3004
+ * });
3005
+ *
3006
+ * promise1.then((value) => {
3007
+ * console.log(value);
3008
+ * // expected output: "Success!"
3009
+ * });
3010
+ * ```
3011
+ */
3012
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): Promise<TResult1 | TResult2>;
3013
+ /**
3014
+ * Attaches a callback for only the rejection of the Promise.
3015
+ * @param onRejected The callback to execute when the Promise is rejected.
3016
+ * @returns A Promise for the completion of the callback.
3017
+ * @example
3018
+ * ```ts
3019
+ * const promise1 = createPromise((resolve, reject) => {
3020
+ * throw 'Uh-oh!';
3021
+ * });
3022
+ *
3023
+ * promise1.catch((error) => {
3024
+ * console.error(error);
3025
+ * });
3026
+ * // expected output: Uh-oh!
3027
+ * ```
3028
+ */
3029
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): IPromise<T | TResult>;
3030
+ /**
3031
+ * Attaches a callback for only the rejection of the Promise.
3032
+ * @param onRejected The callback to execute when the Promise is rejected.
3033
+ * @returns A Promise for the completion of the callback.
3034
+ * @example
3035
+ * ```ts
3036
+ * const promise1 = createPromise((resolve, reject) => {
3037
+ * throw 'Uh-oh!';
3038
+ * });
3039
+ *
3040
+ * promise1.catch((error) => {
3041
+ * console.error(error);
3042
+ * });
3043
+ * // expected output: Uh-oh!
3044
+ * ```
3045
+ */
3046
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): PromiseLike<T | TResult>;
3047
+ /**
3048
+ * Attaches a callback for only the rejection of the Promise.
3049
+ * @param onRejected The callback to execute when the Promise is rejected.
3050
+ * @returns A Promise for the completion of the callback.
3051
+ * @example
3052
+ * ```ts
3053
+ * const promise1 = createPromise((resolve, reject) => {
3054
+ * throw 'Uh-oh!';
3055
+ * });
3056
+ *
3057
+ * promise1.catch((error) => {
3058
+ * console.error(error);
3059
+ * });
3060
+ * // expected output: Uh-oh!
3061
+ * ```
3062
+ */
3063
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): Promise<T | TResult>;
3064
+ /**
3065
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
3066
+ * resolved value cannot be modified from the callback.
3067
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
3068
+ * @returns A Promise for the completion of the callback.
3069
+ * @example
3070
+ * ```ts
3071
+ * function doFunction() {
3072
+ * return createPromise((resolve, reject) => {
3073
+ * if (Math.random() > 0.5) {
3074
+ * resolve('Function has completed');
3075
+ * } else {
3076
+ * reject(new Error('Function failed to process'));
3077
+ * }
3078
+ * });
3079
+ * }
3080
+ *
3081
+ * doFunction().then((data) => {
3082
+ * console.log(data);
3083
+ * }).catch((err) => {
3084
+ * console.error(err);
3085
+ * }).finally(() => {
3086
+ * console.log('Function processing completed');
3087
+ * });
3088
+ * ```
3089
+ */
3090
+ finally(onfinally?: FinallyPromiseHandler): IPromise<T>;
3091
+ /**
3092
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
3093
+ * resolved value cannot be modified from the callback.
3094
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
3095
+ * @returns A Promise for the completion of the callback.
3096
+ * @example
3097
+ * ```ts
3098
+ * function doFunction() {
3099
+ * return createPromise((resolve, reject) => {
3100
+ * if (Math.random() > 0.5) {
3101
+ * resolve('Function has completed');
3102
+ * } else {
3103
+ * reject(new Error('Function failed to process'));
3104
+ * }
3105
+ * });
3106
+ * }
3107
+ *
3108
+ * doFunction().then((data) => {
3109
+ * console.log(data);
3110
+ * }).catch((err) => {
3111
+ * console.error(err);
3112
+ * }).finally(() => {
3113
+ * console.log('Function processing completed');
3114
+ * });
3115
+ * ```
3116
+ */
3117
+ finally(onFinally?: FinallyPromiseHandler): Promise<T>;
3118
+ }
3119
+
1704
3120
  interface IPropertiesPlugin {
1705
3121
  readonly context: ITelemetryContext;
1706
3122
  }
@@ -1808,7 +3224,14 @@ declare namespace ApplicationInsights {
1808
3224
  isSampledIn(envelope: ITelemetryItem): boolean;
1809
3225
  }
1810
3226
 
1811
-
3227
+ /**
3228
+ * Checks if HTML5 Beacons are supported in the current environment.
3229
+ * @param useCached - [Optional] used for testing to bypass the cached lookup, when `true` this will
3230
+ * cause the cached global to be reset.
3231
+ * @returns True if supported, false otherwise.
3232
+ */
3233
+ function isBeaconApiSupported(useCached?: boolean): boolean;
3234
+
1812
3235
  function isCrossOriginError(message: string | Event, url: string, lineNumber: number, columnNumber: number, error: Error | Event): boolean;
1813
3236
 
1814
3237
  interface ISerializable {
@@ -1862,7 +3285,13 @@ declare namespace ApplicationInsights {
1862
3285
 
1863
3286
  function isInternalApplicationInsightsEndpoint(endpointUrl: string): boolean;
1864
3287
 
1865
-
3288
+ /**
3289
+ * Is the parsed traceParent indicating that the trace is currently sampled.
3290
+ * @param value - The parsed traceParent value
3291
+ * @returns
3292
+ */
3293
+ function isSampledFlag(value: ITraceParent): boolean;
3294
+
1866
3295
  interface IStackDetails {
1867
3296
  src: string;
1868
3297
  obj: string[];
@@ -1911,9 +3340,31 @@ declare namespace ApplicationInsights {
1911
3340
  setItem(logger: IDiagnosticLogger, name: string, data: string): boolean;
1912
3341
  }
1913
3342
 
1914
-
1915
-
1916
-
3343
+ /**
3344
+ * Is the provided W3c span id (aka. parent id) a valid string representation, it must be a 16-character
3345
+ * string of lowercase hexadecimal characters, for example, 00f067aa0ba902b7.
3346
+ * If all characters are zero (0000000000000000) this is considered an invalid value.
3347
+ * @param value - The W3c span id to be validated
3348
+ * @returns true if valid otherwise false
3349
+ */
3350
+ function isValidSpanId(value: string): boolean;
3351
+
3352
+ /**
3353
+ * Is the provided W3c Trace Id a valid string representation, it must be a 32-character string
3354
+ * of lowercase hexadecimal characters for example, 4bf92f3577b34da6a3ce929d0e0e4736.
3355
+ * If all characters as zero (00000000000000000000000000000000) it will be considered an invalid value.
3356
+ * @param value - The W3c trace Id to be validated
3357
+ * @returns true if valid otherwise false
3358
+ */
3359
+ function isValidTraceId(value: string): boolean;
3360
+
3361
+ /**
3362
+ * Validates that the provided ITraceParent instance conforms to the currently supported specifications
3363
+ * @param value
3364
+ * @returns
3365
+ */
3366
+ function isValidTraceParent(value: ITraceParent): boolean;
3367
+
1917
3368
  interface ITelemetryContext {
1918
3369
  /**
1919
3370
  * The object describing a component tracked by this object.
@@ -1965,6 +3416,113 @@ declare namespace ApplicationInsights {
1965
3416
  getSessionId: () => string;
1966
3417
  }
1967
3418
 
3419
+ interface ITelemetryInitializerHandler extends ILegacyUnloadHook {
3420
+ remove(): void;
3421
+ }
3422
+
3423
+ /**
3424
+ * Telemety item supported in Core
3425
+ */
3426
+ interface ITelemetryItem {
3427
+ /**
3428
+ * CommonSchema Version of this SDK
3429
+ */
3430
+ ver?: string;
3431
+ /**
3432
+ * Unique name of the telemetry item
3433
+ */
3434
+ name: string;
3435
+ /**
3436
+ * Timestamp when item was sent
3437
+ */
3438
+ time?: string;
3439
+ /**
3440
+ * Identifier of the resource that uniquely identifies which resource data is sent to
3441
+ */
3442
+ iKey?: string;
3443
+ /**
3444
+ * System context properties of the telemetry item, example: ip address, city etc
3445
+ */
3446
+ ext?: {
3447
+ [key: string]: any;
3448
+ };
3449
+ /**
3450
+ * System context property extensions that are not global (not in ctx)
3451
+ */
3452
+ tags?: Tags & Tags[];
3453
+ /**
3454
+ * Custom data
3455
+ */
3456
+ data?: ICustomProperties;
3457
+ /**
3458
+ * Telemetry type used for part B
3459
+ */
3460
+ baseType?: string;
3461
+ /**
3462
+ * Based on schema for part B
3463
+ */
3464
+ baseData?: {
3465
+ [key: string]: any;
3466
+ };
3467
+ }
3468
+
3469
+ /**
3470
+ * Configuration provided to SDK core
3471
+ */
3472
+ interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
3473
+ /**
3474
+ * Set next extension for telemetry processing, this is not optional as plugins should use the
3475
+ * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
3476
+ * now for backward compatibility only.
3477
+ */
3478
+ setNextPlugin?: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
3479
+ /**
3480
+ * Priority of the extension
3481
+ */
3482
+ readonly priority: number;
3483
+ }
3484
+
3485
+ /**
3486
+ * Configuration provided to SDK core
3487
+ */
3488
+ interface ITelemetryPluginChain extends ITelemetryProcessor {
3489
+ /**
3490
+ * Returns the underlying plugin that is being proxied for the processTelemetry call
3491
+ */
3492
+ getPlugin: () => ITelemetryPlugin;
3493
+ /**
3494
+ * Returns the next plugin
3495
+ */
3496
+ getNext: () => ITelemetryPluginChain;
3497
+ /**
3498
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
3499
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
3500
+ * @param unloadCtx - The unload context to use for this call.
3501
+ * @param unloadState - The details of the unload operation
3502
+ */
3503
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
3504
+ }
3505
+
3506
+ interface ITelemetryProcessor {
3507
+ /**
3508
+ * Call back for telemetry processing before it it is sent
3509
+ * @param env - This is the current event being reported
3510
+ * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
3511
+ * can optionally use this to access the current core instance or define / pass additional information
3512
+ * to later plugins (vs appending items to the telemetry item)
3513
+ */
3514
+ processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
3515
+ /**
3516
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
3517
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
3518
+ * the configuration has bee updated.
3519
+ * @param updateCtx - This is the context that should be used during updating.
3520
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
3521
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
3522
+ */
3523
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
3524
+ }
3525
+
1968
3526
  interface ITelemetryTrace {
1969
3527
  /**
1970
3528
  * Trace id
@@ -1989,6 +3547,43 @@ declare namespace ApplicationInsights {
1989
3547
  name?: string;
1990
3548
  }
1991
3549
 
3550
+ interface ITelemetryUnloadState {
3551
+ reason: TelemetryUnloadReason;
3552
+ isAsync: boolean;
3553
+ flushComplete?: boolean;
3554
+ }
3555
+
3556
+ interface ITelemetryUpdateState {
3557
+ /**
3558
+ * Identifies the reason for the update notification, this is a bitwise numeric value
3559
+ */
3560
+ reason: TelemetryUpdateReason;
3561
+ /**
3562
+ * This is a new active configuration that should be used
3563
+ */
3564
+ cfg?: IConfiguration;
3565
+ /**
3566
+ * The detected changes
3567
+ */
3568
+ oldCfg?: IConfiguration;
3569
+ /**
3570
+ * If this is a configuration update this was the previous configuration that was used
3571
+ */
3572
+ newConfig?: IConfiguration;
3573
+ /**
3574
+ * Was the new config requested to be merged with the existing config
3575
+ */
3576
+ merge?: boolean;
3577
+ /**
3578
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
3579
+ */
3580
+ added?: IPlugin[];
3581
+ /**
3582
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
3583
+ */
3584
+ removed?: IPlugin[];
3585
+ }
3586
+
1992
3587
  /**
1993
3588
  * Identifies frequency of items sent
1994
3589
  * Default: send data on 28th every 3 month each year
@@ -2084,7 +3679,153 @@ declare namespace ApplicationInsights {
2084
3679
  throttleNum: number;
2085
3680
  }
2086
3681
 
2087
-
3682
+ /**
3683
+ * A Timer handler which is returned from {@link scheduleTimeout} which contains functions to
3684
+ * cancel or restart (refresh) the timeout function.
3685
+ *
3686
+ * @since 0.4.4
3687
+ * @group Timer
3688
+ */
3689
+ interface ITimerHandler {
3690
+ /**
3691
+ * Cancels a timeout that was previously scheduled, after calling this function any previously
3692
+ * scheduled timer will not execute.
3693
+ * @example
3694
+ * ```ts
3695
+ * let theTimer = scheduleTimeout(...);
3696
+ * theTimer.cancel();
3697
+ * ```
3698
+ */
3699
+ cancel(): void;
3700
+ /**
3701
+ * Reschedules the timer to call its callback at the previously specified duration
3702
+ * adjusted to the current time. This is useful for refreshing a timer without allocating
3703
+ * a new JavaScript object.
3704
+ *
3705
+ * Using this on a timer that has already called its callback will reactivate the timer.
3706
+ * Calling on a timer that has not yet executed will just reschedule the current timer.
3707
+ * @example
3708
+ * ```ts
3709
+ * let theTimer = scheduleTimeout(...);
3710
+ * // The timer will be restarted (if already executed) or rescheduled (if it has not yet executed)
3711
+ * theTimer.refresh();
3712
+ * ```
3713
+ */
3714
+ refresh(): ITimerHandler;
3715
+ /**
3716
+ * When called, requests that the event loop not exit so long when the ITimerHandler is active.
3717
+ * Calling timer.ref() multiple times will have no effect. By default, all ITimerHandler objects
3718
+ * will create "ref'ed" instances, making it normally unnecessary to call timer.ref() unless
3719
+ * timer.unref() had been called previously.
3720
+ * @since 0.7.0
3721
+ * @returns the ITimerHandler instance
3722
+ * @example
3723
+ * ```ts
3724
+ * let theTimer = createTimeout(...);
3725
+ *
3726
+ * // Make sure the timer is referenced (the default) so that the runtime (Node) does not terminate
3727
+ * // if there is a waiting referenced timer.
3728
+ * theTimer.ref();
3729
+ * ```
3730
+ */
3731
+ ref(): this;
3732
+ /**
3733
+ * When called, the any active ITimerHandler instance will not require the event loop to remain
3734
+ * active (Node.js). If there is no other activity keeping the event loop running, the process may
3735
+ * exit before the ITimerHandler instance callback is invoked. Calling timer.unref() multiple times
3736
+ * will have no effect.
3737
+ * @since 0.7.0
3738
+ * @returns the ITimerHandler instance
3739
+ * @example
3740
+ * ```ts
3741
+ * let theTimer = createTimeout(...);
3742
+ *
3743
+ * // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
3744
+ * theTimer.unref();
3745
+ * ```
3746
+ */
3747
+ unref(): this;
3748
+ /**
3749
+ * If true, any running referenced `ITimerHandler` instance will keep the Node.js event loop active.
3750
+ * @since 0.7.0
3751
+ * @example
3752
+ * ```ts
3753
+ * let theTimer = createTimeout(...);
3754
+ *
3755
+ * // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
3756
+ * theTimer.unref();
3757
+ * let hasRef = theTimer.hasRef(); // false
3758
+ *
3759
+ * theTimer.ref();
3760
+ * hasRef = theTimer.hasRef(); // true
3761
+ * ```
3762
+ */
3763
+ hasRef(): boolean;
3764
+ /**
3765
+ * Gets or Sets a flag indicating if the underlying timer is currently enabled and running.
3766
+ * Setting the enabled flag to the same as it's current value has no effect, setting to `true`
3767
+ * when already `true` will not {@link ITimerHandler.refresh | refresh}() the timer.
3768
+ * And setting to 'false` will {@link ITimerHandler.cancel | cancel}() the timer.
3769
+ * @since 0.8.1
3770
+ * @example
3771
+ * ```ts
3772
+ * let theTimer = createTimeout(...);
3773
+ *
3774
+ * // Check if enabled
3775
+ * theTimer.enabled; // false
3776
+ *
3777
+ * // Start the timer
3778
+ * theTimer.enabled = true; // Same as calling refresh()
3779
+ * theTimer.enabled; //true
3780
+ *
3781
+ * // Has no effect as it's already running
3782
+ * theTimer.enabled = true;
3783
+ *
3784
+ * // Will refresh / restart the time
3785
+ * theTimer.refresh()
3786
+ *
3787
+ * let theTimer = scheduleTimeout(...);
3788
+ *
3789
+ * // Check if enabled
3790
+ * theTimer.enabled; // true
3791
+ * ```
3792
+ */
3793
+ enabled: boolean;
3794
+ }
3795
+
3796
+ /**
3797
+ * This interface represents the components of a W3C traceparent header
3798
+ */
3799
+ interface ITraceParent {
3800
+ /**
3801
+ * The version of the definition, this MUST be a string with a length of 2 and only contain lowercase
3802
+ * hexadecimal characters. A value of 'ff' is considered to be an invalid version.
3803
+ */
3804
+ version: string;
3805
+ /**
3806
+ * This is the ID of the whole trace forest and is used to uniquely identify a distributed trace
3807
+ * through a system. It is represented as a 32-character string of lowercase hexadecimal characters,
3808
+ * for example, 4bf92f3577b34da6a3ce929d0e0e4736.
3809
+ * All characters as zero (00000000000000000000000000000000) is considered an invalid value.
3810
+ */
3811
+ traceId: string;
3812
+ /**
3813
+ * This is the ID of the current request as known by the caller (in some tracing systems, this is also
3814
+ * known as the parent-id, where a span is the execution of a client request). It is represented as an
3815
+ * 16-character string of lowercase hexadecimal characters, for example, 00f067aa0ba902b7.
3816
+ * All bytes as zero (0000000000000000) is considered an invalid value.
3817
+ */
3818
+ spanId: string;
3819
+ /**
3820
+ * An 8-bit value of flags that controls tracing such as sampling, trace level, etc. These flags are
3821
+ * recommendations given by the caller rather than strict rules to follow.
3822
+ * As this is a bit field, you cannot interpret flags by decoding the hex value and looking at the resulting
3823
+ * number. For example, a flag 00000001 could be encoded as 01 in hex, or 09 in hex if present with the flag
3824
+ * 00001000. A common mistake in bit fields is forgetting to mask when interpreting flags.
3825
+ */
3826
+ traceFlags: number;
3827
+ }
3828
+
2088
3829
  interface ITraceState {
2089
3830
  }
2090
3831
 
@@ -2109,6 +3850,16 @@ declare namespace ApplicationInsights {
2109
3850
  iKey?: string;
2110
3851
  }
2111
3852
 
3853
+ /**
3854
+ * An interface which provides automatic removal during unloading of the component
3855
+ */
3856
+ interface IUnloadHook {
3857
+ /**
3858
+ * Self remove the referenced component
3859
+ */
3860
+ rm: () => void;
3861
+ }
3862
+
2112
3863
  interface IUser {
2113
3864
  /**
2114
3865
  * The telemetry configuration.
@@ -2150,6 +3901,40 @@ declare namespace ApplicationInsights {
2150
3901
  update(userId?: string): void;
2151
3902
  }
2152
3903
 
3904
+ interface IWatchDetails<T = IConfiguration> {
3905
+ /**
3906
+ * The current config object
3907
+ */
3908
+ cfg: T;
3909
+ /**
3910
+ * Set the value against the provided config/name with the value, the property
3911
+ * will be converted to be dynamic (if not already) as long as the provided config
3912
+ * is already a tracked dynamic object.
3913
+ * @throws TypeError if the provided config is not a monitored dynamic config
3914
+ */
3915
+ set: <C, V>(theConfig: C, name: string, value: V) => V;
3916
+ /**
3917
+ * Set default values for the config if not present.
3918
+ * @param theConfig - The configuration object to set default on (if missing)
3919
+ * @param defaultValues - The default values to apply to the config
3920
+ */
3921
+ setDf: <C>(theConfig: C, defaultValues: IConfigDefaults<C>) => C;
3922
+ /**
3923
+ * Set this named property of the target as referenced, which will cause any object or array instance
3924
+ * to be updated in-place rather than being entirely replaced. All other values will continue to be replaced.
3925
+ * @returns The referenced properties current value
3926
+ */
3927
+ ref: <C, V = any>(target: C, name: string) => V;
3928
+ /**
3929
+ * Set this named property of the target as read-only, which will block this single named property from
3930
+ * ever being changed for the target instance.
3931
+ * This does NOT freeze or seal the instance, it just stops the direct re-assignment of the named property,
3932
+ * if the value is a non-primitive (ie. an object or array) it's properties will still be mutable.
3933
+ * @returns The referenced properties current value
3934
+ */
3935
+ rdOnly: <C, V = any>(target: C, name: string) => V;
3936
+ }
3937
+
2153
3938
  interface IWeb {
2154
3939
  /**
2155
3940
  * Browser name, set at ingestion
@@ -2181,6 +3966,10 @@ declare namespace ApplicationInsights {
2181
3966
  domain: string;
2182
3967
  }
2183
3968
 
3969
+ const LoggingSeverity: EnumValue<typeof eLoggingSeverity>;
3970
+
3971
+ type LoggingSeverity = number | eLoggingSeverity;
3972
+
2184
3973
  class Metric implements IMetricData, ISerializable {
2185
3974
  static envelopeType: string;
2186
3975
  static dataType: string;
@@ -2344,11 +4133,26 @@ declare namespace ApplicationInsights {
2344
4133
 
2345
4134
  function parseConnectionString(connectionString?: string): ConnectionString;
2346
4135
 
2347
-
4136
+ /**
4137
+ * Attempt to parse the provided string as a W3C TraceParent header value (https://www.w3.org/TR/trace-context/#traceparent-header)
4138
+ *
4139
+ * @param value - The value to be parsed
4140
+ * @param selectIdx - If the found value is comma separated which is the preferred entry to select, defaults to the first
4141
+ * @returns
4142
+ */
4143
+ function parseTraceParent(value: string, selectIdx?: number): ITraceParent;
4144
+
2348
4145
  const ProcessLegacy = "ProcessLegacy";
2349
4146
 
2350
4147
  const PropertiesPluginIdentifier = "AppInsightsPropertiesPlugin";
2351
4148
 
4149
+ /**
4150
+ * This defines the handler function for when a promise is rejected.
4151
+ * @param value This is the value passed as part of resolving the Promise
4152
+ * @return This may return a value, another Promise or void. @see {@link IPromise.then} for how the value is handled.
4153
+ */
4154
+ type RejectedPromiseHandler<T = never> = (((reason: any) => T | IPromise<T> | PromiseLike<T>) | undefined | null);
4155
+
2352
4156
  class RemoteDependencyData implements IRemoteDependencyData, ISerializable {
2353
4157
  static envelopeType: string;
2354
4158
  static dataType: string;
@@ -2446,8 +4250,61 @@ declare namespace ApplicationInsights {
2446
4250
  8: "request-context";
2447
4251
  };
2448
4252
 
4253
+ /**
4254
+ * This defines the handler function for when a promise is resolved.
4255
+ * @param value This is the value passed as part of resolving the Promise
4256
+ * @return This may return a value, another Promise or void. @see {@link IPromise.then} for how the value is handled.
4257
+ */
4258
+ type ResolvedPromiseHandler<T, TResult1 = T> = (((value: T) => TResult1 | IPromise<TResult1> | PromiseLike<TResult1>) | undefined | null);
4259
+
2449
4260
  const SampleRate = "sampleRate";
2450
4261
 
4262
+ /**
4263
+ * The EventsDiscardedReason enumeration contains a set of values that specify the reason for discarding an event.
4264
+ */
4265
+ const enum SendRequestReason {
4266
+ /**
4267
+ * No specific reason was specified
4268
+ */
4269
+ Undefined = 0,
4270
+ /**
4271
+ * Events are being sent based on the normal event schedule / timer.
4272
+ */
4273
+ NormalSchedule = 1,
4274
+ /**
4275
+ * A manual flush request was received
4276
+ */
4277
+ ManualFlush = 1,
4278
+ /**
4279
+ * Unload event is being processed
4280
+ */
4281
+ Unload = 2,
4282
+ /**
4283
+ * The event(s) being sent are sync events
4284
+ */
4285
+ SyncEvent = 3,
4286
+ /**
4287
+ * The Channel was resumed
4288
+ */
4289
+ Resumed = 4,
4290
+ /**
4291
+ * The event(s) being sent as a retry
4292
+ */
4293
+ Retry = 5,
4294
+ /**
4295
+ * The SDK is unloading
4296
+ */
4297
+ SdkUnload = 6,
4298
+ /**
4299
+ * Maximum batch size would be exceeded
4300
+ */
4301
+ MaxBatchSize = 10,
4302
+ /**
4303
+ * The Maximum number of events have already been queued
4304
+ */
4305
+ MaxQueuedEvents = 20
4306
+ }
4307
+
2451
4308
  /**
2452
4309
  * Defines the level of severity for the event.
2453
4310
  */
@@ -2459,6 +4316,12 @@ declare namespace ApplicationInsights {
2459
4316
 
2460
4317
  const strNotSpecified = "not_specified";
2461
4318
 
4319
+ interface Tags {
4320
+ [key: string]: any;
4321
+ }
4322
+
4323
+ type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
4324
+
2462
4325
  class TelemetryItemCreator {
2463
4326
  /**
2464
4327
  * Create a telemetry item that the 1DS channel understands
@@ -2472,6 +4335,50 @@ declare namespace ApplicationInsights {
2472
4335
  static create: typeof createTelemetryItem;
2473
4336
  }
2474
4337
 
4338
+ /**
4339
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
4340
+ */
4341
+ const enum TelemetryUnloadReason {
4342
+ /**
4343
+ * Teardown has been called without any context.
4344
+ */
4345
+ ManualTeardown = 0,
4346
+ /**
4347
+ * Just this plugin is being removed
4348
+ */
4349
+ PluginUnload = 1,
4350
+ /**
4351
+ * This instance of the plugin is being removed and replaced
4352
+ */
4353
+ PluginReplace = 2,
4354
+ /**
4355
+ * The entire SDK is being unloaded
4356
+ */
4357
+ SdkUnload = 50
4358
+ }
4359
+
4360
+ /**
4361
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
4362
+ */
4363
+ const enum TelemetryUpdateReason {
4364
+ /**
4365
+ * Unknown.
4366
+ */
4367
+ Unknown = 0,
4368
+ /**
4369
+ * The configuration has ben updated or changed
4370
+ */
4371
+ ConfigurationChanged = 1,
4372
+ /**
4373
+ * One or more plugins have been added
4374
+ */
4375
+ PluginAdded = 16,
4376
+ /**
4377
+ * One or more plugins have been removed
4378
+ */
4379
+ PluginRemoved = 32
4380
+ }
4381
+
2475
4382
  class ThrottleMgr {
2476
4383
  canThrottle: (msgId: _eInternalMessageId | number) => boolean;
2477
4384
  sendMessage: (msgId: _eInternalMessageId, message: string, severity?: eLoggingSeverity) => IThrottleResult | null;
@@ -2522,6 +4429,8 @@ declare namespace ApplicationInsights {
2522
4429
  });
2523
4430
  }
2524
4431
 
4432
+ type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
4433
+
2525
4434
  function urlGetAbsoluteUrl(url: string): string;
2526
4435
 
2527
4436
  function urlGetCompleteUrl(method: string, absoluteUrl: string): string;
@@ -2569,5 +4478,6 @@ declare namespace ApplicationInsights {
2569
4478
 
2570
4479
  function utlSetStoragePrefix(storagePrefix: string): void;
2571
4480
 
2572
-
4481
+ type WatcherFunction<T = IConfiguration> = (details: IWatchDetails<T>) => void;
4482
+
2573
4483
  }