@microsoft/applicationinsights-core-js 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-04
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.
- package/browser/applicationinsights-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +1999 -793
- package/browser/applicationinsights-core-js.js.map +1 -1
- package/browser/applicationinsights-core-js.min.js +2 -2
- package/browser/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.api.json +16363 -9167
- package/dist/applicationinsights-core-js.api.md +425 -48
- package/dist/applicationinsights-core-js.d.ts +784 -123
- package/dist/applicationinsights-core-js.js +1999 -793
- package/dist/applicationinsights-core-js.js.map +1 -1
- package/dist/applicationinsights-core-js.min.js +2 -2
- package/dist/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.rollup.d.ts +784 -123
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +3 -69
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +496 -99
- package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +120 -21
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +202 -87
- package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +4 -4
- package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +7 -148
- package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +93 -0
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -0
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +25 -12
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +13 -12
- package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +477 -0
- package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -0
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +89 -86
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +3 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +28 -0
- package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -0
- package/dist-esm/JavaScriptSDK/NotificationManager.js +37 -42
- package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +430 -119
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +30 -4
- package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +60 -14
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +81 -0
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -0
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +33 -0
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +8 -0
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +8 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +6 -0
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +1 -0
- package/dist-esm/applicationinsights-core-js.js +12 -7
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +2 -2
- package/src/JavaScriptSDK/AppInsightsCore.ts +2 -101
- package/src/JavaScriptSDK/BaseCore.ts +696 -120
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +205 -31
- package/src/JavaScriptSDK/ChannelController.ts +242 -103
- package/src/JavaScriptSDK/CookieMgr.ts +7 -5
- package/src/JavaScriptSDK/CoreUtils.ts +8 -172
- package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
- package/src/JavaScriptSDK/DiagnosticLogger.ts +27 -12
- package/src/JavaScriptSDK/EnvUtils.ts +13 -12
- package/src/JavaScriptSDK/EventHelpers.ts +550 -0
- package/src/JavaScriptSDK/HelperFuncs.ts +123 -97
- package/src/JavaScriptSDK/InstrumentHooks.ts +4 -2
- package/src/JavaScriptSDK/InternalConstants.ts +26 -0
- package/src/JavaScriptSDK/NotificationManager.ts +34 -37
- package/src/JavaScriptSDK/PerfManager.ts +4 -7
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +543 -134
- package/src/JavaScriptSDK/RandomHelper.ts +35 -3
- package/src/JavaScriptSDK/TelemetryHelpers.ts +83 -21
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +111 -0
- package/src/JavaScriptSDK/UnloadHandlerContainer.ts +46 -0
- package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
- package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
- package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
- package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +27 -0
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +82 -2
- package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +16 -5
- package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +16 -6
- package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +94 -14
- package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +28 -10
- package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
- package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
- package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +34 -0
- package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +17 -0
- package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
- package/types/JavaScriptSDK/BaseCore.d.ts +81 -3
- package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +53 -10
- package/types/JavaScriptSDK/ChannelController.d.ts +16 -17
- package/types/JavaScriptSDK/CoreUtils.d.ts +1 -48
- package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
- package/types/JavaScriptSDK/DiagnosticLogger.d.ts +10 -0
- package/types/JavaScriptSDK/EventHelpers.d.ts +154 -0
- package/types/JavaScriptSDK/HelperFuncs.d.ts +33 -32
- package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
- package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
- package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +69 -6
- package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
- package/types/JavaScriptSDK/TelemetryHelpers.d.ts +23 -3
- package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +16 -0
- package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
- package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
- package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
- package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +21 -0
- package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +20 -0
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +72 -1
- package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +16 -5
- package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +9 -0
- package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +82 -11
- package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
- package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +25 -8
- package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
- package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
- package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +22 -0
- package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +13 -0
- package/types/applicationinsights-core-js.d.ts +18 -9
- package/types/tsdoc-metadata.json +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
- package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
- package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
- package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +0 -32
|
@@ -3,16 +3,24 @@
|
|
|
3
3
|
|
|
4
4
|
"use strict";
|
|
5
5
|
|
|
6
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
6
7
|
import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore"
|
|
7
8
|
import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
|
|
8
9
|
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
|
|
9
10
|
import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
|
|
10
11
|
import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
|
|
11
|
-
import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
|
|
12
|
+
import { IProcessTelemetryContext, IProcessTelemetryUnloadContext, IProcessTelemetryUpdateContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
|
|
12
13
|
import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
|
|
13
|
-
import {
|
|
14
|
-
import { isFunction, isNullOrUndefined, setValue } from "./HelperFuncs";
|
|
14
|
+
import { createProcessTelemetryContext, createProcessTelemetryUnloadContext, createProcessTelemetryUpdateContext } from "./ProcessTelemetryContext";
|
|
15
|
+
import { arrForEach, isArray, isFunction, isNullOrUndefined, proxyFunctionAs, setValue } from "./HelperFuncs";
|
|
15
16
|
import { strExtensionConfig } from "./Constants";
|
|
17
|
+
import { createUnloadHandlerContainer, IUnloadHandlerContainer, UnloadHandler } from "./UnloadHandlerContainer";
|
|
18
|
+
import { IInstrumentHook } from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
|
|
19
|
+
import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
|
|
20
|
+
import { TelemetryUnloadReason } from "../JavaScriptSDK.Enums/TelemetryUnloadReason";
|
|
21
|
+
import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
|
|
22
|
+
import { TelemetryUpdateReason } from "../JavaScriptSDK.Enums/TelemetryUpdateReason";
|
|
23
|
+
import { strDoTeardown, strIsInitialized, strSetNextPlugin } from "./InternalConstants";
|
|
16
24
|
|
|
17
25
|
let strGetPlugin = "getPlugin";
|
|
18
26
|
|
|
@@ -22,6 +30,16 @@ let strGetPlugin = "getPlugin";
|
|
|
22
30
|
* implementation so that new default implementations can be added without breaking all plugins.
|
|
23
31
|
*/
|
|
24
32
|
export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
33
|
+
|
|
34
|
+
public identifier: string;
|
|
35
|
+
public version?: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Holds the core instance that was used during initialization
|
|
39
|
+
*/
|
|
40
|
+
public core: IAppInsightsCore;
|
|
41
|
+
|
|
42
|
+
priority: number;
|
|
25
43
|
|
|
26
44
|
/**
|
|
27
45
|
* Call back for telemetry processing before it it is sent
|
|
@@ -35,7 +53,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
|
35
53
|
/**
|
|
36
54
|
* Set next extension for telemetry processing
|
|
37
55
|
*/
|
|
38
|
-
public setNextPlugin: (next: ITelemetryPlugin|ITelemetryPluginChain) => void;
|
|
56
|
+
public setNextPlugin: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
|
|
39
57
|
|
|
40
58
|
/**
|
|
41
59
|
* Returns the current diagnostic logger that can be used to log issues, if no logger is currently
|
|
@@ -48,16 +66,6 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
|
48
66
|
*/
|
|
49
67
|
public isInitialized: () => boolean;
|
|
50
68
|
|
|
51
|
-
public identifier: string;
|
|
52
|
-
public version?: string;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Holds the core instance that was used during initialization
|
|
56
|
-
*/
|
|
57
|
-
public core: IAppInsightsCore;
|
|
58
|
-
|
|
59
|
-
priority: number;
|
|
60
|
-
|
|
61
69
|
/**
|
|
62
70
|
* Helper to return the current IProcessTelemetryContext, if the passed argument exists this just
|
|
63
71
|
* returns that value (helps with minification for callers), otherwise it will return the configured
|
|
@@ -72,23 +80,140 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
|
72
80
|
protected setInitialized: (isInitialized: boolean) => void;
|
|
73
81
|
|
|
74
82
|
/**
|
|
75
|
-
*
|
|
83
|
+
* Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
|
|
84
|
+
* finishes it's removal.
|
|
85
|
+
* @param unloadCtx - This is the context that should be used during unloading.
|
|
86
|
+
* @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.
|
|
87
|
+
* @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.
|
|
88
|
+
* @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
|
|
89
|
+
*/
|
|
90
|
+
protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Extension hook to allow implementations to perform some additional update operations before the BaseTelemetryPlugin finishes it's removal
|
|
94
|
+
* @param updateCtx - This is the context that should be used during updating.
|
|
95
|
+
* @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
|
|
96
|
+
* @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async update operations.
|
|
97
|
+
* @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
|
|
76
98
|
*/
|
|
77
|
-
|
|
99
|
+
protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
|
|
78
100
|
|
|
79
101
|
constructor() {
|
|
80
|
-
let _self = this;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
let
|
|
102
|
+
let _self = this; // Setting _self here as it's used outside of the dynamicProto as well
|
|
103
|
+
|
|
104
|
+
// NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
|
|
105
|
+
let _isinitialized: boolean;
|
|
106
|
+
let _rootCtx: IProcessTelemetryContext; // Used as the root context, holding the current config and initialized core
|
|
107
|
+
let _nextPlugin: ITelemetryPlugin | ITelemetryPluginChain; // Used for backward compatibility where plugins don't call the main pipeline
|
|
108
|
+
let _unloadHandlerContainer: IUnloadHandlerContainer;
|
|
109
|
+
let _hooks: IInstrumentHook[];
|
|
110
|
+
|
|
111
|
+
_initDefaults();
|
|
112
|
+
|
|
113
|
+
dynamicProto(BaseTelemetryPlugin, _self, (_self) => {
|
|
114
|
+
|
|
115
|
+
_self.initialize = (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain): void => {
|
|
116
|
+
_setDefaults(config, core, pluginChain);
|
|
117
|
+
_isinitialized = true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
_self.teardown = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => {
|
|
121
|
+
// If this plugin has already been torn down (not operational) or is not initialized (core is not set)
|
|
122
|
+
// or the core being used for unload was not the same core used for initialization.
|
|
123
|
+
if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
|
|
124
|
+
// Do Nothing as either the plugin is not initialized or was not initialized by the current core
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let result: void | boolean;
|
|
129
|
+
let unloadDone = false;
|
|
130
|
+
let theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
|
|
131
|
+
let theUnloadState: ITelemetryUnloadState = unloadState || {
|
|
132
|
+
reason: TelemetryUnloadReason.ManualTeardown,
|
|
133
|
+
isAsync: false
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
function _unloadCallback() {
|
|
137
|
+
if (!unloadDone) {
|
|
138
|
+
unloadDone = true;
|
|
139
|
+
|
|
140
|
+
_unloadHandlerContainer.run(theUnloadCtx, unloadState);
|
|
141
|
+
|
|
142
|
+
// Remove all instrumentation hooks
|
|
143
|
+
arrForEach(_hooks, (fn) => {
|
|
144
|
+
fn.rm();
|
|
145
|
+
});
|
|
146
|
+
_hooks = [];
|
|
147
|
+
|
|
148
|
+
if (result === true) {
|
|
149
|
+
theUnloadCtx.processNext(theUnloadState);
|
|
150
|
+
}
|
|
84
151
|
|
|
85
|
-
|
|
152
|
+
_initDefaults();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
|
|
157
|
+
_unloadCallback();
|
|
158
|
+
} else {
|
|
159
|
+
// Tell the caller that we will be calling processNext()
|
|
160
|
+
result = true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return result;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
_self.update = (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => {
|
|
167
|
+
// If this plugin has already been torn down (not operational) or is not initialized (core is not set)
|
|
168
|
+
// or the core being used for unload was not the same core used for initialization.
|
|
169
|
+
if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
|
|
170
|
+
// Do Nothing
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
let result: void | boolean;
|
|
175
|
+
let updateDone = false;
|
|
176
|
+
let theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
|
|
177
|
+
let theUpdateState: ITelemetryUpdateState = updateState || {
|
|
178
|
+
reason: TelemetryUpdateReason.Unknown
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
function _updateCallback() {
|
|
182
|
+
if (!updateDone) {
|
|
183
|
+
updateDone = true;
|
|
184
|
+
_setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
|
|
189
|
+
_updateCallback();
|
|
190
|
+
} else {
|
|
191
|
+
result = true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return result;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
_self._addHook = (hooks: IInstrumentHook | IInstrumentHook[]) => {
|
|
198
|
+
if (hooks) {
|
|
199
|
+
if (isArray(hooks)) {
|
|
200
|
+
_hooks = _hooks.concat(hooks);
|
|
201
|
+
} else {
|
|
202
|
+
_hooks.push(hooks);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
proxyFunctionAs(_self, "_addUnloadCb", () => _unloadHandlerContainer, "add");
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// These are added after the dynamicProto so that are not moved to the prototype
|
|
86
211
|
|
|
87
212
|
_self.diagLog = (itemCtx:IProcessTelemetryContext): IDiagnosticLogger => {
|
|
88
|
-
return
|
|
213
|
+
return _getTelCtx(itemCtx).diagLog();
|
|
89
214
|
}
|
|
90
215
|
|
|
91
|
-
_self
|
|
216
|
+
_self[strIsInitialized] = () => {
|
|
92
217
|
return _isinitialized;
|
|
93
218
|
}
|
|
94
219
|
|
|
@@ -101,7 +226,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
|
101
226
|
// should use processNext() function. If you require access to the plugin use the
|
|
102
227
|
// IProcessTelemetryContext.getNext().getPlugin() while in the pipeline, Note getNext() may return null.
|
|
103
228
|
|
|
104
|
-
_self
|
|
229
|
+
_self[strSetNextPlugin] = (next: ITelemetryPlugin | ITelemetryPluginChain) => {
|
|
105
230
|
_nextPlugin = next;
|
|
106
231
|
};
|
|
107
232
|
|
|
@@ -116,10 +241,12 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
|
116
241
|
}
|
|
117
242
|
};
|
|
118
243
|
|
|
119
|
-
_self._getTelCtx =
|
|
244
|
+
_self._getTelCtx = _getTelCtx;
|
|
245
|
+
|
|
246
|
+
function _getTelCtx(currentCtx:IProcessTelemetryContext = null) {
|
|
120
247
|
let itemCtx:IProcessTelemetryContext = currentCtx;
|
|
121
248
|
if (!itemCtx) {
|
|
122
|
-
let rootCtx = _rootCtx ||
|
|
249
|
+
let rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
|
|
123
250
|
// tslint:disable-next-line: prefer-conditional-expression
|
|
124
251
|
if (_nextPlugin && _nextPlugin[strGetPlugin]) {
|
|
125
252
|
// Looks like a chain object
|
|
@@ -132,7 +259,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
|
132
259
|
return itemCtx;
|
|
133
260
|
}
|
|
134
261
|
|
|
135
|
-
|
|
262
|
+
function _setDefaults(config: IConfiguration, core: IAppInsightsCore, pluginChain: ITelemetryPluginChain) {
|
|
136
263
|
if (config) {
|
|
137
264
|
// Make sure the extensionConfig exists
|
|
138
265
|
setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
|
|
@@ -143,7 +270,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
|
143
270
|
pluginChain = core.getProcessTelContext().getNext();
|
|
144
271
|
}
|
|
145
272
|
|
|
146
|
-
let nextPlugin:IPlugin = _nextPlugin as IPlugin;
|
|
273
|
+
let nextPlugin: IPlugin = _nextPlugin as IPlugin;
|
|
147
274
|
if (_nextPlugin && _nextPlugin[strGetPlugin]) {
|
|
148
275
|
// If it looks like a proxy/chain then get the plugin
|
|
149
276
|
nextPlugin = _nextPlugin[strGetPlugin]();
|
|
@@ -151,14 +278,61 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
|
|
|
151
278
|
|
|
152
279
|
// Support legacy plugins where core was defined as a property
|
|
153
280
|
_self.core = core;
|
|
154
|
-
_rootCtx =
|
|
155
|
-
|
|
281
|
+
_rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function _initDefaults() {
|
|
285
|
+
_isinitialized = false;
|
|
286
|
+
_self.core = null;
|
|
287
|
+
_rootCtx = null;
|
|
288
|
+
_nextPlugin = null;
|
|
289
|
+
_hooks = [];
|
|
290
|
+
_unloadHandlerContainer = createUnloadHandlerContainer();
|
|
156
291
|
}
|
|
157
292
|
}
|
|
158
293
|
|
|
159
294
|
public initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain): void {
|
|
160
|
-
this
|
|
295
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
|
|
300
|
+
* therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
|
|
301
|
+
* processTelemetry calls are ignored and it just calls the processNext() with the provided context.
|
|
302
|
+
* @param unloadCtx - This is the context that should be used during unloading.
|
|
303
|
+
* @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.
|
|
304
|
+
* @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
|
|
305
|
+
*/
|
|
306
|
+
public teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean {
|
|
307
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
308
|
+
return false;
|
|
161
309
|
}
|
|
162
310
|
|
|
163
311
|
public abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* The the plugin should re-evaluate configuration and update any cached configuration settings.
|
|
315
|
+
* @param updateCtx - This is the context that should be used during updating.
|
|
316
|
+
* @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
|
|
317
|
+
* @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
|
|
318
|
+
*/
|
|
319
|
+
public update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean{
|
|
320
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Add an unload handler that will be called when the SDK is being unloaded
|
|
325
|
+
* @param handler - the handler
|
|
326
|
+
*/
|
|
327
|
+
protected _addUnloadCb(handler: UnloadHandler): void {
|
|
328
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Add this hook so that it is automatically removed during unloading
|
|
333
|
+
* @param hooks - The single hook or an array of IInstrumentHook objects
|
|
334
|
+
*/
|
|
335
|
+
protected _addHook(hooks: IInstrumentHook | IInstrumentHook[]): void {
|
|
336
|
+
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
337
|
+
}
|
|
164
338
|
}
|