@microsoft/applicationinsights-web 2.8.0-beta.2202-07 → 2.8.0-beta.2203-03

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 (51) hide show
  1. package/README.md +1 -0
  2. package/browser/{ai.2.8.0-beta.2202-07.cjs.js → ai.2.8.0-beta.2203-03.cjs.js} +1069 -522
  3. package/browser/ai.2.8.0-beta.2203-03.cjs.js.map +1 -0
  4. package/browser/ai.2.8.0-beta.2203-03.cjs.min.js +6 -0
  5. package/browser/ai.2.8.0-beta.2203-03.cjs.min.js.map +1 -0
  6. package/browser/{ai.2.8.0-beta.2202-07.gbl.js → ai.2.8.0-beta.2203-03.gbl.js} +1069 -522
  7. package/browser/ai.2.8.0-beta.2203-03.gbl.js.map +1 -0
  8. package/browser/ai.2.8.0-beta.2203-03.gbl.min.js +6 -0
  9. package/browser/ai.2.8.0-beta.2203-03.gbl.min.js.map +1 -0
  10. package/browser/ai.2.8.0-beta.2203-03.integrity.json +66 -0
  11. package/browser/{ai.2.8.0-beta.2202-07.js → ai.2.8.0-beta.2203-03.js} +1069 -522
  12. package/browser/ai.2.8.0-beta.2203-03.js.map +1 -0
  13. package/browser/ai.2.8.0-beta.2203-03.min.js +6 -0
  14. package/browser/ai.2.8.0-beta.2203-03.min.js.map +1 -0
  15. package/browser/ai.2.cjs.js +1068 -521
  16. package/browser/ai.2.cjs.js.map +1 -1
  17. package/browser/ai.2.cjs.min.js +2 -2
  18. package/browser/ai.2.cjs.min.js.map +1 -1
  19. package/browser/ai.2.gbl.js +1068 -521
  20. package/browser/ai.2.gbl.js.map +1 -1
  21. package/browser/ai.2.gbl.min.js +2 -2
  22. package/browser/ai.2.gbl.min.js.map +1 -1
  23. package/browser/ai.2.js +1068 -521
  24. package/browser/ai.2.js.map +1 -1
  25. package/browser/ai.2.min.js +2 -2
  26. package/browser/ai.2.min.js.map +1 -1
  27. package/dist/applicationinsights-web.api.json +925 -660
  28. package/dist/applicationinsights-web.api.md +53 -32
  29. package/dist/applicationinsights-web.d.ts +358 -93
  30. package/dist/applicationinsights-web.js +1134 -585
  31. package/dist/applicationinsights-web.js.map +1 -1
  32. package/dist/applicationinsights-web.min.js +2 -2
  33. package/dist/applicationinsights-web.min.js.map +1 -1
  34. package/dist/applicationinsights-web.rollup.d.ts +358 -93
  35. package/dist-esm/ApplicationInsightsContainer.js +1 -1
  36. package/dist-esm/ApplicationInsightsDeprecated.js +1 -1
  37. package/dist-esm/Init.js +1 -1
  38. package/dist-esm/Initialization.js +1 -1
  39. package/dist-esm/applicationinsights-web.js +1 -1
  40. package/package.json +7 -7
  41. package/types/Initialization.d.ts +6 -2
  42. package/browser/ai.2.8.0-beta.2202-07.cjs.js.map +0 -1
  43. package/browser/ai.2.8.0-beta.2202-07.cjs.min.js +0 -6
  44. package/browser/ai.2.8.0-beta.2202-07.cjs.min.js.map +0 -1
  45. package/browser/ai.2.8.0-beta.2202-07.gbl.js.map +0 -1
  46. package/browser/ai.2.8.0-beta.2202-07.gbl.min.js +0 -6
  47. package/browser/ai.2.8.0-beta.2202-07.gbl.min.js.map +0 -1
  48. package/browser/ai.2.8.0-beta.2202-07.integrity.json +0 -66
  49. package/browser/ai.2.8.0-beta.2202-07.js.map +0 -1
  50. package/browser/ai.2.8.0-beta.2202-07.min.js +0 -6
  51. package/browser/ai.2.8.0-beta.2202-07.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft.ApplicationInsights, 2.8.0-beta.2202-07
2
+ * Microsoft.ApplicationInsights, 2.8.0-beta.2203-03
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -417,7 +417,26 @@ declare namespace ApplicationInsights {
417
417
  * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
418
418
  */
419
419
  addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
420
+ /**
421
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
422
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
423
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
424
+ * approach is to create a new instance and initialize that instance.
425
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
426
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
427
+ */
428
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
420
429
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
430
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
431
+ /**
432
+ * Returns the unique event namespace that should be used
433
+ */
434
+ evtNamespace(): string;
435
+ /**
436
+ * Add an unload handler that will be called when the SDK is being unloaded
437
+ * @param handler - the handler
438
+ */
439
+ addUnloadCb(handler: UnloadHandler): void;
421
440
  protected releaseQueue(): void;
422
441
  }
423
442
 
@@ -466,9 +485,32 @@ declare namespace ApplicationInsights {
466
485
  * Internal helper to allow setting of the internal initialized setting for inherited instances and unit testing
467
486
  */
468
487
  protected setInitialized: (isInitialized: boolean) => void;
488
+ /**
489
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
490
+ * finishes it's removal.
491
+ * @param unloadCtx - This is the context that should be used during unloading.
492
+ * @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.
493
+ * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async unload/teardown operations.
494
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
495
+ */
496
+ protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
469
497
  constructor();
470
498
  initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
499
+ /**
500
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
501
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
502
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
503
+ * @param unloadCtx - This is the context that should be used during unloading.
504
+ * @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.
505
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
506
+ */
507
+ teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
471
508
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
509
+ /**
510
+ * Add an unload handler that will be called when the SDK is being unloaded
511
+ * @param handler - the handler
512
+ */
513
+ protected _addUnloadCb(handler: UnloadHandler): void;
472
514
  /**
473
515
  * Add this hook so that it is automatically removed during unloading
474
516
  * @param hooks - The single hook or an array of IInstrumentHook objects
@@ -579,7 +621,6 @@ declare namespace ApplicationInsights {
579
621
  priority: number;
580
622
  constructor();
581
623
  initialize(config: IConfiguration & IConfig, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
582
- teardown(): void;
583
624
  processTelemetry(item: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
584
625
  /**
585
626
  * Logs dependency call
@@ -602,20 +643,13 @@ declare namespace ApplicationInsights {
602
643
  }): void;
603
644
  }
604
645
 
605
- enum DistributedTracingModes {
606
- /**
607
- * (Default) Send Application Insights correlation headers
608
- */
609
- AI = 0,
610
- /**
611
- * Send both W3C Trace Context headers and back-compatibility Application Insights headers
612
- */
613
- AI_AND_W3C = 1,
614
- /**
615
- * Send W3C Trace Context headers
616
- */
617
- W3C = 2
618
- }
646
+ const DistributedTracingModes: {
647
+ AI: number;
648
+ AI_AND_W3C: number;
649
+ W3C: number;
650
+ };
651
+
652
+ type DistributedTracingModes = number | eDistributedTracingModes;
619
653
 
620
654
  /**
621
655
  * The abstract common base of all domains.
@@ -633,6 +667,117 @@ declare namespace ApplicationInsights {
633
667
  */
634
668
  function doPerf<T>(mgrSource: IPerfManagerProvider | IPerfManager, getSource: () => string, func: (perfEvt?: IPerfEvent) => T, details?: () => any, isAsync?: boolean): T;
635
669
 
670
+ const enum eDistributedTracingModes {
671
+ /**
672
+ * (Default) Send Application Insights correlation headers
673
+ */
674
+ AI = 0,
675
+ /**
676
+ * Send both W3C Trace Context headers and back-compatibility Application Insights headers
677
+ */
678
+ AI_AND_W3C = 1,
679
+ /**
680
+ * Send W3C Trace Context headers
681
+ */
682
+ W3C = 2
683
+ }
684
+
685
+ const enum _eInternalMessageId {
686
+ BrowserDoesNotSupportLocalStorage = 0,
687
+ BrowserCannotReadLocalStorage = 1,
688
+ BrowserCannotReadSessionStorage = 2,
689
+ BrowserCannotWriteLocalStorage = 3,
690
+ BrowserCannotWriteSessionStorage = 4,
691
+ BrowserFailedRemovalFromLocalStorage = 5,
692
+ BrowserFailedRemovalFromSessionStorage = 6,
693
+ CannotSendEmptyTelemetry = 7,
694
+ ClientPerformanceMathError = 8,
695
+ ErrorParsingAISessionCookie = 9,
696
+ ErrorPVCalc = 10,
697
+ ExceptionWhileLoggingError = 11,
698
+ FailedAddingTelemetryToBuffer = 12,
699
+ FailedMonitorAjaxAbort = 13,
700
+ FailedMonitorAjaxDur = 14,
701
+ FailedMonitorAjaxOpen = 15,
702
+ FailedMonitorAjaxRSC = 16,
703
+ FailedMonitorAjaxSend = 17,
704
+ FailedMonitorAjaxGetCorrelationHeader = 18,
705
+ FailedToAddHandlerForOnBeforeUnload = 19,
706
+ FailedToSendQueuedTelemetry = 20,
707
+ FailedToReportDataLoss = 21,
708
+ FlushFailed = 22,
709
+ MessageLimitPerPVExceeded = 23,
710
+ MissingRequiredFieldSpecification = 24,
711
+ NavigationTimingNotSupported = 25,
712
+ OnError = 26,
713
+ SessionRenewalDateIsZero = 27,
714
+ SenderNotInitialized = 28,
715
+ StartTrackEventFailed = 29,
716
+ StopTrackEventFailed = 30,
717
+ StartTrackFailed = 31,
718
+ StopTrackFailed = 32,
719
+ TelemetrySampledAndNotSent = 33,
720
+ TrackEventFailed = 34,
721
+ TrackExceptionFailed = 35,
722
+ TrackMetricFailed = 36,
723
+ TrackPVFailed = 37,
724
+ TrackPVFailedCalc = 38,
725
+ TrackTraceFailed = 39,
726
+ TransmissionFailed = 40,
727
+ FailedToSetStorageBuffer = 41,
728
+ FailedToRestoreStorageBuffer = 42,
729
+ InvalidBackendResponse = 43,
730
+ FailedToFixDepricatedValues = 44,
731
+ InvalidDurationValue = 45,
732
+ TelemetryEnvelopeInvalid = 46,
733
+ CreateEnvelopeError = 47,
734
+ CannotSerializeObject = 48,
735
+ CannotSerializeObjectNonSerializable = 49,
736
+ CircularReferenceDetected = 50,
737
+ ClearAuthContextFailed = 51,
738
+ ExceptionTruncated = 52,
739
+ IllegalCharsInName = 53,
740
+ ItemNotInArray = 54,
741
+ MaxAjaxPerPVExceeded = 55,
742
+ MessageTruncated = 56,
743
+ NameTooLong = 57,
744
+ SampleRateOutOfRange = 58,
745
+ SetAuthContextFailed = 59,
746
+ SetAuthContextFailedAccountName = 60,
747
+ StringValueTooLong = 61,
748
+ StartCalledMoreThanOnce = 62,
749
+ StopCalledWithoutStart = 63,
750
+ TelemetryInitializerFailed = 64,
751
+ TrackArgumentsNotSpecified = 65,
752
+ UrlTooLong = 66,
753
+ SessionStorageBufferFull = 67,
754
+ CannotAccessCookie = 68,
755
+ IdTooLong = 69,
756
+ InvalidEvent = 70,
757
+ FailedMonitorAjaxSetRequestHeader = 71,
758
+ SendBrowserInfoOnUserInit = 72,
759
+ PluginException = 73,
760
+ NotificationException = 74,
761
+ SnippetScriptLoadFailure = 99,
762
+ InvalidInstrumentationKey = 100,
763
+ CannotParseAiBlobValue = 101,
764
+ InvalidContentBlob = 102,
765
+ TrackPageActionEventFailed = 103,
766
+ FailedAddingCustomDefinedRequestContext = 104,
767
+ InMemoryStorageBufferFull = 105
768
+ }
769
+
770
+ const enum eLoggingSeverity {
771
+ /**
772
+ * Error will be sent as internal telemetry
773
+ */
774
+ CRITICAL = 1,
775
+ /**
776
+ * Error will NOT be sent as internal telemetry, and will only be shown in browser console
777
+ */
778
+ WARNING = 2
779
+ }
780
+
636
781
  class Envelope extends Envelope_2 implements IEnvelope {
637
782
  /**
638
783
  * The data contract for serializing this object.
@@ -925,11 +1070,36 @@ declare namespace ApplicationInsights {
925
1070
  * Return a new instance of the IProcessTelemetryContext for processing events
926
1071
  */
927
1072
  getProcessTelContext(): IProcessTelemetryContext;
1073
+ /**
1074
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
1075
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
1076
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
1077
+ * approach is to create a new instance and initialize that instance.
1078
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
1079
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
1080
+ */
1081
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
928
1082
  /**
929
1083
  * Find and return the (first) plugin with the specified identifier if present
930
1084
  * @param pluginIdentifier
931
1085
  */
932
1086
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
1087
+ /**
1088
+ * Add a new plugin to the installation
1089
+ * @param plugin - The new plugin to add
1090
+ * @param replaceExisting - should any existing plugin be replaced
1091
+ * @param doAsync - Should the add be performed asynchronously
1092
+ */
1093
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
1094
+ /**
1095
+ * Returns the unique event namespace that should be used when registering events
1096
+ */
1097
+ evtNamespace(): string;
1098
+ /**
1099
+ * Add a handler that will be called when the SDK is being unloaded
1100
+ * @param handler - the handler
1101
+ */
1102
+ addUnloadCb(handler: UnloadHandler): void;
933
1103
  }
934
1104
 
935
1105
  interface IAppInsightsDeprecated {
@@ -1183,6 +1353,67 @@ declare namespace ApplicationInsights {
1183
1353
  readonly appId?: string;
1184
1354
  }
1185
1355
 
1356
+ interface IBaseProcessingContext {
1357
+ /**
1358
+ * The current core instance for the request
1359
+ */
1360
+ core: () => IAppInsightsCore;
1361
+ /**
1362
+ * THe current diagnostic logger for the request
1363
+ */
1364
+ diagLog: () => IDiagnosticLogger;
1365
+ /**
1366
+ * Gets the current core config instance
1367
+ */
1368
+ getCfg: () => IConfiguration;
1369
+ /**
1370
+ * Gets the named extension config
1371
+ */
1372
+ getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
1373
+ /**
1374
+ * Gets the named config from either the named identifier extension or core config if neither exist then the
1375
+ * default value is returned
1376
+ * @param identifier The named extension identifier
1377
+ * @param field The config field name
1378
+ * @param defaultValue The default value to return if no defined config exists
1379
+ */
1380
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
1381
+ /**
1382
+ * Helper to allow plugins to check and possibly shortcut executing code only
1383
+ * required if there is a nextPlugin
1384
+ */
1385
+ hasNext: () => boolean;
1386
+ /**
1387
+ * Returns the next configured plugin proxy
1388
+ */
1389
+ getNext: () => ITelemetryPluginChain;
1390
+ /**
1391
+ * Helper to set the next plugin proxy
1392
+ */
1393
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
1394
+ /**
1395
+ * Synchronously iterate over the context chain running the callback for each plugin, once
1396
+ * every plugin has been executed via the callback, any associated onComplete will be called.
1397
+ * @param callback - The function call for each plugin in the context chain
1398
+ */
1399
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
1400
+ /**
1401
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
1402
+ * @param onComplete - The onComplete to call
1403
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
1404
+ * @param args - Any additional arguments to pass to the onComplete function
1405
+ */
1406
+ onComplete: (onComplete: Function, that?: any, ...args: any[]) => void;
1407
+ /**
1408
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1409
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1410
+ * then the current execution order will be copied.
1411
+ * @param startAt - The plugin to start processing from, if missing from the execution
1412
+ * order then the next plugin will be NOT set.
1413
+ */
1414
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
1415
+ }
1416
+
1186
1417
  /**
1187
1418
  * Provides data transmission capabilities
1188
1419
  */
@@ -1196,9 +1427,14 @@ declare namespace ApplicationInsights {
1196
1427
  */
1197
1428
  resume(): void;
1198
1429
  /**
1199
- * Tear down transmission pipeline
1430
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
1431
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
1432
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
1433
+ * @param unloadCtx - This is the context that should be used during unloading.
1434
+ * @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.
1435
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
1200
1436
  */
1201
- teardown(): void;
1437
+ teardown: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
1202
1438
  /**
1203
1439
  * Flush to send data immediately; channel should default to sending data asynchronously
1204
1440
  * @param async - send data asynchronously when true
@@ -2053,7 +2289,7 @@ declare namespace ApplicationInsights {
2053
2289
  * @param callback {any} - The callback function that needs to be executed for the given event
2054
2290
  * @return {boolean} - true if the handler was successfully added
2055
2291
  */
2056
- addEventHandler: (eventName: string, callback: any) => boolean;
2292
+ addEventHandler: (eventName: string, callback: any, evtNamespace?: string | string[]) => boolean;
2057
2293
  /**
2058
2294
  * Return the current time via the Date now() function (if available) and falls back to (new Date()).getTime() if now() is unavailable (IE8 or less)
2059
2295
  * https://caniuse.com/#search=Date.now
@@ -2528,6 +2764,20 @@ declare namespace ApplicationInsights {
2528
2764
 
2529
2765
  interface ILoadedPlugin<T extends IPlugin> {
2530
2766
  plugin: T;
2767
+ /**
2768
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
2769
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
2770
+ * @returns boolean = true if the plugin is in a state where it is operational.
2771
+ */
2772
+ isEnabled: () => boolean;
2773
+ /**
2774
+ * You can optionally enable / disable a plugin from processing events.
2775
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
2776
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
2777
+ * (unless it's also been re-initialized)
2778
+ */
2779
+ setEnabled: (isEnabled: boolean) => void;
2780
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
2531
2781
  }
2532
2782
 
2533
2783
  interface ILocation {
@@ -2756,7 +3006,7 @@ declare namespace ApplicationInsights {
2756
3006
  InMemoryStorageBufferFull: number;
2757
3007
  };
2758
3008
 
2759
- type _InternalMessageId = number | typeof _InternalMessageId;
3009
+ type _InternalMessageId = number | _eInternalMessageId;
2760
3010
 
2761
3011
  interface IOperatingSystem {
2762
3012
  name: string;
@@ -3009,10 +3259,14 @@ declare namespace ApplicationInsights {
3009
3259
  */
3010
3260
  isInitialized?: () => boolean;
3011
3261
  /**
3012
- * Tear down the plugin and remove any hooked value, the plugin should remove that it is no longer initialized and
3013
- * therefore can be re-initialized after being torn down.
3262
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
3263
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
3264
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
3265
+ * @param unloadCtx - This is the context that should be used during unloading.
3266
+ * @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.
3267
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
3014
3268
  */
3015
- teardown?: () => void;
3269
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
3016
3270
  /**
3017
3271
  * Extension name
3018
3272
  */
@@ -3027,67 +3281,42 @@ declare namespace ApplicationInsights {
3027
3281
  * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
3028
3282
  * between multiple AppInsights instances
3029
3283
  */
3030
- interface IProcessTelemetryContext {
3031
- /**
3032
- * The current core instance for the request
3033
- */
3034
- core: () => IAppInsightsCore;
3035
- /**
3036
- * THe current diagnostic logger for the request
3037
- */
3038
- diagLog: () => IDiagnosticLogger;
3039
- /**
3040
- * Gets the current core config instance
3041
- */
3042
- getCfg: () => IConfiguration;
3043
- /**
3044
- * Gets the named extension config
3045
- */
3046
- getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
3047
- /**
3048
- * Gets the named config from either the named identifier extension or core config if neither exist then the
3049
- * default value is returned
3050
- * @param identifier The named extension identifier
3051
- * @param field The config field name
3052
- * @param defaultValue The default value to return if no defined config exists
3053
- */
3054
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
3055
- /**
3056
- * Helper to allow plugins to check and possibly shortcut executing code only
3057
- * required if there is a nextPlugin
3058
- */
3059
- hasNext: () => boolean;
3060
- /**
3061
- * Returns the next configured plugin proxy
3062
- */
3063
- getNext: () => ITelemetryPluginChain;
3064
- /**
3065
- * Helper to set the next plugin proxy
3066
- */
3067
- setNext: (nextCtx: ITelemetryPluginChain) => void;
3284
+ interface IProcessTelemetryContext extends IBaseProcessingContext {
3068
3285
  /**
3069
3286
  * Call back for telemetry processing before it it is sent
3070
3287
  * @param env - This is the current event being reported
3288
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
3071
3289
  */
3072
- processNext: (env: ITelemetryItem) => void;
3290
+ processNext: (env: ITelemetryItem) => boolean | void;
3073
3291
  /**
3074
- * Synchronously iterate over the context chain running the callback for each plugin, once
3075
- * every plugin has been executed via the callback, any associated onComplete will be called.
3076
- * @param callback - The function call for each plugin in the context chain
3077
- */
3078
- iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
3079
- /**
3080
- * Create a new context using the core and config from the current instance
3292
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
3081
3293
  * @param plugins - The execution order to process the plugins, if null or not supplied
3082
3294
  * then the current execution order will be copied.
3083
3295
  * @param startAt - The plugin to start processing from, if missing from the execution
3084
3296
  * order then the next plugin will be NOT set.
3085
3297
  */
3086
3298
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
3299
+ }
3300
+
3301
+ /**
3302
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
3303
+ * between multiple AppInsights instances
3304
+ */
3305
+ interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
3087
3306
  /**
3088
- * Set the function to call when the current chain has executed all processNext or unloadNext items.
3307
+ * This Plugin has finished unloading, so unload the next one
3308
+ * @param uploadState - The state of the unload process
3309
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
3310
+ */
3311
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
3312
+ /**
3313
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
3314
+ * @param plugins - The execution order to process the plugins, if null or not supplied
3315
+ * then the current execution order will be copied.
3316
+ * @param startAt - The plugin to start processing from, if missing from the execution
3317
+ * order then the next plugin will be NOT set.
3089
3318
  */
3090
- onComplete: (onComplete: () => void) => void;
3319
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
3091
3320
  }
3092
3321
 
3093
3322
  interface IPropertiesPlugin {
@@ -3443,15 +3672,7 @@ declare namespace ApplicationInsights {
3443
3672
  /**
3444
3673
  * Configuration provided to SDK core
3445
3674
  */
3446
- interface ITelemetryPlugin extends IPlugin {
3447
- /**
3448
- * Call back for telemetry processing before it it is sent
3449
- * @param env - This is the current event being reported
3450
- * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
3451
- * can optionally use this to access the current core instance or define / pass additional information
3452
- * to later plugins (vs appending items to the telemetry item)
3453
- */
3454
- processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
3675
+ interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
3455
3676
  /**
3456
3677
  * Set next extension for telemetry processing, this is not optional as plugins should use the
3457
3678
  * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
@@ -3467,7 +3688,7 @@ declare namespace ApplicationInsights {
3467
3688
  /**
3468
3689
  * Configuration provided to SDK core
3469
3690
  */
3470
- interface ITelemetryPluginChain {
3691
+ interface ITelemetryPluginChain extends ITelemetryProcessor {
3471
3692
  /**
3472
3693
  * Returns the underlying plugin that is being proxied for the processTelemetry call
3473
3694
  */
@@ -3476,6 +3697,16 @@ declare namespace ApplicationInsights {
3476
3697
  * Returns the next plugin
3477
3698
  */
3478
3699
  getNext: () => ITelemetryPluginChain;
3700
+ /**
3701
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
3702
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
3703
+ * @param unloadCtx - The unload context to use for this call.
3704
+ * @param unloadState - The details of the unload operation
3705
+ */
3706
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
3707
+ }
3708
+
3709
+ interface ITelemetryProcessor {
3479
3710
  /**
3480
3711
  * Call back for telemetry processing before it it is sent
3481
3712
  * @param env - This is the current event being reported
@@ -3483,7 +3714,7 @@ declare namespace ApplicationInsights {
3483
3714
  * can optionally use this to access the current core instance or define / pass additional information
3484
3715
  * to later plugins (vs appending items to the telemetry item)
3485
3716
  */
3486
- processTelemetry: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
3717
+ processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
3487
3718
  }
3488
3719
 
3489
3720
  interface ITelemetryTrace {
@@ -3505,6 +3736,12 @@ declare namespace ApplicationInsights {
3505
3736
  name?: string;
3506
3737
  }
3507
3738
 
3739
+ interface ITelemetryUnloadState {
3740
+ reason: TelemetryUnloadReason;
3741
+ isAsync: boolean;
3742
+ flushComplete?: boolean;
3743
+ }
3744
+
3508
3745
  interface ITraceState {
3509
3746
  }
3510
3747
 
@@ -3778,16 +4015,12 @@ declare namespace ApplicationInsights {
3778
4015
  domain: string;
3779
4016
  }
3780
4017
 
3781
- enum LoggingSeverity {
3782
- /**
3783
- * Error will be sent as internal telemetry
3784
- */
3785
- CRITICAL = 1,
3786
- /**
3787
- * Error will NOT be sent as internal telemetry, and will only be shown in browser console
3788
- */
3789
- WARNING = 2
3790
- }
4018
+ const LoggingSeverity: {
4019
+ CRITICAL: number;
4020
+ WARNING: number;
4021
+ };
4022
+
4023
+ type LoggingSeverity = number | eLoggingSeverity;
3791
4024
 
3792
4025
  /**
3793
4026
  * Instances of Message represent printf-like trace statements that are text-searched. Log4Net, NLog and other text-based log file entries are translated into intances of this type. The message does not have measurements.
@@ -4413,6 +4646,10 @@ declare namespace ApplicationInsights {
4413
4646
  * The event(s) being sent as a retry
4414
4647
  */
4415
4648
  Retry = 5,
4649
+ /**
4650
+ * The SDK is unloading
4651
+ */
4652
+ SdkUnload = 6,
4416
4653
  /**
4417
4654
  * Maximum batch size would be exceeded
4418
4655
  */
@@ -4565,7 +4802,11 @@ declare namespace ApplicationInsights {
4565
4802
  SessionExt: string;
4566
4803
  SDKExt: string;
4567
4804
  };
4568
- DistributedTracingModes: typeof DistributedTracingModes;
4805
+ DistributedTracingModes: {
4806
+ AI: number;
4807
+ AI_AND_W3C: number;
4808
+ W3C: number;
4809
+ };
4569
4810
  };
4570
4811
 
4571
4812
  type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
@@ -4587,6 +4828,28 @@ declare namespace ApplicationInsights {
4587
4828
  }): ITelemetryItem;
4588
4829
  }
4589
4830
 
4831
+ /**
4832
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
4833
+ */
4834
+ const enum TelemetryUnloadReason {
4835
+ /**
4836
+ * Teardown has been called without any context.
4837
+ */
4838
+ ManualTeardown = 0,
4839
+ /**
4840
+ * Just this plugin is being removed
4841
+ */
4842
+ PluginUnload = 1,
4843
+ /**
4844
+ * This instance of the plugin is being removed and replaced
4845
+ */
4846
+ PluginReplace = 2,
4847
+ /**
4848
+ * The entire SDK is being unloaded
4849
+ */
4850
+ SdkUnload = 50
4851
+ }
4852
+
4590
4853
  class Trace extends MessageData implements ISerializable {
4591
4854
  static envelopeType: string;
4592
4855
  static dataType: string;
@@ -4604,6 +4867,8 @@ declare namespace ApplicationInsights {
4604
4867
  });
4605
4868
  }
4606
4869
 
4870
+ type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
4871
+
4607
4872
  const Util: IUtil;
4608
4873
 
4609
4874
  interface XDomainRequest extends XMLHttpRequestEventTarget {