@microsoft/applicationinsights-core-js 3.0.0-beta.2303-03 → 3.0.0-beta.2303-05
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 +2 -2
- 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 +113 -206
- package/dist/applicationinsights-core-js.api.md +11 -14
- package/dist/applicationinsights-core-js.d.ts +15 -13
- package/dist/applicationinsights-core-js.js +2 -2
- 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 +15 -13
- package/dist-esm/Config/ConfigDefaultHelpers.js +1 -1
- package/dist-esm/Config/ConfigDefaults.js +1 -1
- package/dist-esm/Config/DynamicConfig.js +1 -1
- package/dist-esm/Config/DynamicProperty.js +1 -1
- package/dist-esm/Config/DynamicState.js +1 -1
- package/dist-esm/Config/DynamicSupport.js +1 -1
- package/dist-esm/Config/IConfigDefaults.js +1 -1
- package/dist-esm/Config/IDynamicConfigHandler.js +1 -1
- package/dist-esm/Config/IDynamicPropertyHandler.js +1 -1
- package/dist-esm/Config/IDynamicWatcher.js +1 -1
- package/dist-esm/Config/_IDynamicConfigHandlerState.js +1 -1
- package/dist-esm/JavaScriptSDK/AggregationError.js +1 -1
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
- package/dist-esm/JavaScriptSDK/UnloadHookContainer.js +1 -1
- package/dist-esm/JavaScriptSDK/W3cTraceParent.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +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/IDistributedTraceContext.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 +1 -1
- 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 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadHook.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
- package/dist-esm/__DynamicConstants.js +1 -1
- package/dist-esm/applicationinsights-core-js.js +1 -1
- package/package.json +1 -1
- package/types/JavaScriptSDK/AppInsightsCore.d.ts +5 -6
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +9 -6
- package/src/JavaScriptSDK/AggregationError.ts +0 -36
- package/src/JavaScriptSDK/AppInsightsCore.ts +0 -1322
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +0 -343
- package/src/JavaScriptSDK/Constants.ts +0 -4
- package/src/JavaScriptSDK/CookieMgr.ts +0 -449
- package/src/JavaScriptSDK/CoreUtils.ts +0 -58
- package/src/JavaScriptSDK/DataCacheHelper.ts +0 -107
- package/src/JavaScriptSDK/DbgExtensionUtils.ts +0 -56
- package/src/JavaScriptSDK/DiagnosticLogger.ts +0 -380
- package/src/JavaScriptSDK/EnvUtils.ts +0 -312
- package/src/JavaScriptSDK/EventHelpers.ts +0 -550
- package/src/JavaScriptSDK/HelperFuncs.ts +0 -351
- package/src/JavaScriptSDK/InstrumentHooks.ts +0 -280
- package/src/JavaScriptSDK/InternalConstants.ts +0 -31
- package/src/JavaScriptSDK/NotificationManager.ts +0 -165
- package/src/JavaScriptSDK/PerfManager.ts +0 -288
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +0 -674
- package/src/JavaScriptSDK/RandomHelper.ts +0 -145
- package/src/JavaScriptSDK/TelemetryHelpers.ts +0 -184
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +0 -112
- package/src/JavaScriptSDK/UnloadHandlerContainer.ts +0 -45
- package/src/JavaScriptSDK/UnloadHookContainer.ts +0 -52
- package/src/JavaScriptSDK/W3cTraceParent.ts +0 -197
- package/src/JavaScriptSDK.Enums/EnumHelperFuncs.ts +0 -24
- package/src/JavaScriptSDK.Enums/EventsDiscardedReason.ts +0 -71
- package/src/JavaScriptSDK.Enums/LoggingEnums.ts +0 -121
- package/src/JavaScriptSDK.Enums/SendRequestReason.ts +0 -56
- package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +0 -27
- package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +0 -27
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +0 -216
- package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +0 -46
- package/src/JavaScriptSDK.Interfaces/IConfiguration.ts +0 -176
- package/src/JavaScriptSDK.Interfaces/ICookieMgr.ts +0 -116
- package/src/JavaScriptSDK.Interfaces/IDbgExtension.ts +0 -14
- package/src/JavaScriptSDK.Interfaces/IDiagnosticLogger.ts +0 -75
- package/src/JavaScriptSDK.Interfaces/IDistributedTraceContext.ts +0 -54
- package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +0 -100
- package/src/JavaScriptSDK.Interfaces/INotificationListener.ts +0 -39
- package/src/JavaScriptSDK.Interfaces/INotificationManager.ts +0 -52
- package/src/JavaScriptSDK.Interfaces/IPerfEvent.ts +0 -69
- package/src/JavaScriptSDK.Interfaces/IPerfManager.ts +0 -53
- package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +0 -157
- package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +0 -17
- package/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts +0 -62
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +0 -94
- package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +0 -30
- package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +0 -10
- package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +0 -44
- package/src/JavaScriptSDK.Interfaces/ITraceParent.ts +0 -38
- package/src/JavaScriptSDK.Interfaces/IUnloadHook.ts +0 -22
- package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +0 -17
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { utcNow } from "@nevware21/ts-utils";
|
|
4
|
-
import { getCrypto, getMsCrypto, isIE } from "./EnvUtils";
|
|
5
|
-
import { STR_EMPTY } from "./InternalConstants";
|
|
6
|
-
|
|
7
|
-
const UInt32Mask = 0x100000000;
|
|
8
|
-
const MaxUInt32 = 0xffffffff;
|
|
9
|
-
|
|
10
|
-
// MWC based Random generator (for IE)
|
|
11
|
-
let _mwcSeeded = false;
|
|
12
|
-
let _mwcW = 123456789;
|
|
13
|
-
var _mwcZ = 987654321;
|
|
14
|
-
|
|
15
|
-
// Takes any integer
|
|
16
|
-
function _mwcSeed(seedValue: number) {
|
|
17
|
-
if (seedValue < 0) {
|
|
18
|
-
// Make sure we end up with a positive number and not -ve one.
|
|
19
|
-
seedValue >>>= 0;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
_mwcW = (123456789 + seedValue) & MaxUInt32;
|
|
23
|
-
_mwcZ = (987654321 - seedValue) & MaxUInt32;
|
|
24
|
-
_mwcSeeded = true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function _autoSeedMwc() {
|
|
28
|
-
// Simple initialization using default Math.random() - So we inherit any entropy from the browser
|
|
29
|
-
// and bitwise XOR with the current milliseconds
|
|
30
|
-
try {
|
|
31
|
-
const now = utcNow() & 0x7fffffff;
|
|
32
|
-
_mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
|
|
33
|
-
} catch (e) {
|
|
34
|
-
// Don't crash if something goes wrong
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Generate a random value between 0 and maxValue, max value should be limited to a 32-bit maximum.
|
|
40
|
-
* So maxValue(16) will produce a number from 0..16 (range of 17)
|
|
41
|
-
* @param maxValue
|
|
42
|
-
*/
|
|
43
|
-
export function randomValue(maxValue: number) {
|
|
44
|
-
if (maxValue > 0) {
|
|
45
|
-
return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* generate a random 32-bit number (0x000000..0xFFFFFFFF) or (-0x80000000..0x7FFFFFFF), defaults un-unsigned.
|
|
53
|
-
* @param signed - True to return a signed 32-bit number (-0x80000000..0x7FFFFFFF) otherwise an unsigned one (0x000000..0xFFFFFFFF)
|
|
54
|
-
*/
|
|
55
|
-
export function random32(signed?: boolean) {
|
|
56
|
-
let value = 0;
|
|
57
|
-
let c = getCrypto() || getMsCrypto();
|
|
58
|
-
if (c && c.getRandomValues) {
|
|
59
|
-
// Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)
|
|
60
|
-
value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (value === 0 && isIE()) {
|
|
64
|
-
// For IE 6, 7, 8 (especially on XP) Math.random is not very random
|
|
65
|
-
if (!_mwcSeeded) {
|
|
66
|
-
// Set the seed for the Mwc algorithm
|
|
67
|
-
_autoSeedMwc();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Don't use Math.random for IE
|
|
71
|
-
// Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)
|
|
72
|
-
value = mwcRandom32() & MaxUInt32;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (value === 0) {
|
|
76
|
-
// Make sure the number is converted into the specified range (-0x80000000..0x7FFFFFFF)
|
|
77
|
-
value = Math.floor((UInt32Mask * Math.random()) | 0);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!signed) {
|
|
81
|
-
// Make sure we end up with a positive number and not -ve one.
|
|
82
|
-
value >>>= 0;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return value;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Seed the MWC random number generator with the specified seed or a random value
|
|
90
|
-
* @param value - optional the number to used as the seed, if undefined, null or zero a random value will be chosen
|
|
91
|
-
*/
|
|
92
|
-
export function mwcRandomSeed(value?: number) {
|
|
93
|
-
if (!value) {
|
|
94
|
-
_autoSeedMwc();
|
|
95
|
-
} else {
|
|
96
|
-
_mwcSeed(value);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Generate a random 32-bit number between (0x000000..0xFFFFFFFF) or (-0x80000000..0x7FFFFFFF), using MWC (Multiply with carry)
|
|
102
|
-
* instead of Math.random() defaults to un-signed.
|
|
103
|
-
* Used as a replacement random generator for IE to avoid issues with older IE instances.
|
|
104
|
-
* @param signed - True to return a signed 32-bit number (-0x80000000..0x7FFFFFFF) otherwise an unsigned one (0x000000..0xFFFFFFFF)
|
|
105
|
-
*/
|
|
106
|
-
export function mwcRandom32(signed?: boolean) {
|
|
107
|
-
_mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
|
|
108
|
-
_mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
|
|
109
|
-
|
|
110
|
-
let value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
|
|
111
|
-
|
|
112
|
-
if (!signed) {
|
|
113
|
-
// Make sure we end up with a positive number and not -ve one.
|
|
114
|
-
value >>>= 0;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return value;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Generate random base64 id string.
|
|
122
|
-
* The default length is 22 which is 132-bits so almost the same as a GUID but as base64 (the previous default was 5)
|
|
123
|
-
* @param maxLength - Optional value to specify the length of the id to be generated, defaults to 22
|
|
124
|
-
*/
|
|
125
|
-
export function newId(maxLength = 22): string {
|
|
126
|
-
const base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
127
|
-
|
|
128
|
-
// Start with an initial random number, consuming the value in reverse byte order
|
|
129
|
-
let number = random32() >>> 0; // Make sure it's a +ve number
|
|
130
|
-
let chars = 0;
|
|
131
|
-
let result = STR_EMPTY;
|
|
132
|
-
while (result.length < maxLength) {
|
|
133
|
-
chars ++;
|
|
134
|
-
result += base64chars.charAt(number & 0x3F);
|
|
135
|
-
number >>>= 6; // Zero fill with right shift
|
|
136
|
-
if (chars === 5) {
|
|
137
|
-
// 5 base64 characters === 30 bits so we don't have enough bits for another base64 char
|
|
138
|
-
// So add on another 30 bits and make sure it's +ve
|
|
139
|
-
number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
|
|
140
|
-
chars = 0; // We need to reset the number every 5 chars (30 bits)
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return result;
|
|
145
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
"use strict";
|
|
4
|
-
|
|
5
|
-
import { arrForEach, isFunction } from "@nevware21/ts-utils";
|
|
6
|
-
import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
|
|
7
|
-
import { IDistributedTraceContext } from "../JavaScriptSDK.Interfaces/IDistributedTraceContext";
|
|
8
|
-
import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
|
|
9
|
-
import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
|
|
10
|
-
import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
|
|
11
|
-
import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
|
|
12
|
-
import { ITraceParent } from "../JavaScriptSDK.Interfaces/ITraceParent";
|
|
13
|
-
import { IUnloadableComponent } from "../JavaScriptSDK.Interfaces/IUnloadableComponent";
|
|
14
|
-
import { createElmNodeData } from "./DataCacheHelper";
|
|
15
|
-
import { STR_CORE, STR_PRIORITY, STR_PROCESS_TELEMETRY } from "./InternalConstants";
|
|
16
|
-
import { isValidSpanId, isValidTraceId } from "./W3cTraceParent";
|
|
17
|
-
|
|
18
|
-
export interface IPluginState {
|
|
19
|
-
core?: IAppInsightsCore;
|
|
20
|
-
isInitialized?: boolean;
|
|
21
|
-
teardown?: boolean;
|
|
22
|
-
disabled?: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const pluginStateData = createElmNodeData("plugin");
|
|
26
|
-
|
|
27
|
-
export function _getPluginState(plugin: IPlugin): IPluginState {
|
|
28
|
-
return pluginStateData.get<IPluginState>(plugin, "state", {}, true)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Initialize the queue of plugins
|
|
33
|
-
* @param plugins - The array of plugins to initialize and setting of the next plugin
|
|
34
|
-
* @param config - The current config for the instance
|
|
35
|
-
* @param core - THe current core instance
|
|
36
|
-
* @param extensions - The extensions
|
|
37
|
-
*/
|
|
38
|
-
export function initializePlugins(processContext: IProcessTelemetryContext, extensions: IPlugin[]) {
|
|
39
|
-
|
|
40
|
-
// Set the next plugin and identified the uninitialized plugins
|
|
41
|
-
let initPlugins: ITelemetryPlugin[] = [];
|
|
42
|
-
let lastPlugin: ITelemetryPlugin = null;
|
|
43
|
-
let proxy: ITelemetryPluginChain = processContext.getNext();
|
|
44
|
-
let pluginState: IPluginState;
|
|
45
|
-
|
|
46
|
-
while (proxy) {
|
|
47
|
-
let thePlugin = proxy.getPlugin();
|
|
48
|
-
if (thePlugin) {
|
|
49
|
-
if (lastPlugin && lastPlugin.setNextPlugin && thePlugin.processTelemetry) {
|
|
50
|
-
// Set this plugin as the next for the previous one
|
|
51
|
-
lastPlugin.setNextPlugin(thePlugin);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
pluginState = _getPluginState(thePlugin);
|
|
55
|
-
|
|
56
|
-
let isInitialized = !!pluginState.isInitialized;
|
|
57
|
-
if (thePlugin.isInitialized) {
|
|
58
|
-
isInitialized = thePlugin.isInitialized();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!isInitialized) {
|
|
62
|
-
initPlugins.push(thePlugin);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
lastPlugin = thePlugin;
|
|
66
|
-
proxy = proxy.getNext();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Now initialize the plugins
|
|
71
|
-
arrForEach(initPlugins, thePlugin => {
|
|
72
|
-
let core = processContext.core();
|
|
73
|
-
|
|
74
|
-
thePlugin.initialize(
|
|
75
|
-
processContext.getCfg(),
|
|
76
|
-
core,
|
|
77
|
-
extensions,
|
|
78
|
-
processContext.getNext());
|
|
79
|
-
|
|
80
|
-
pluginState = _getPluginState(thePlugin);
|
|
81
|
-
|
|
82
|
-
// Only add the core to the state if the plugin didn't set it (doesn't extend from BaseTelemetryPlugin)
|
|
83
|
-
if (!thePlugin[STR_CORE] && !pluginState[STR_CORE]) {
|
|
84
|
-
pluginState[STR_CORE] = core;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
pluginState.isInitialized = true;
|
|
88
|
-
delete pluginState.teardown;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function sortPlugins<T = IPlugin>(plugins:T[]) {
|
|
93
|
-
// Sort by priority
|
|
94
|
-
return plugins.sort((extA, extB) => {
|
|
95
|
-
let result = 0;
|
|
96
|
-
if (extB) {
|
|
97
|
-
let bHasProcess = extB[STR_PROCESS_TELEMETRY];
|
|
98
|
-
if (extA[STR_PROCESS_TELEMETRY]) {
|
|
99
|
-
result = bHasProcess ? extA[STR_PRIORITY] - extB[STR_PRIORITY] : 1;
|
|
100
|
-
} else if (bHasProcess) {
|
|
101
|
-
result = -1;
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
result = extA ? 1 : -1;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return result;
|
|
108
|
-
});
|
|
109
|
-
// sort complete
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Teardown / Unload helper to perform teardown/unloading operations for the provided components synchronously or asynchronously, this will call any
|
|
114
|
-
* _doTeardown() or _doUnload() functions on the provided components to allow them to finish removal.
|
|
115
|
-
* @param components - The components you want to unload
|
|
116
|
-
* @param unloadCtx - This is the context that should be used during unloading.
|
|
117
|
-
* @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.
|
|
118
|
-
* @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.
|
|
119
|
-
* @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
|
|
120
|
-
*/
|
|
121
|
-
export function unloadComponents(components: any | IUnloadableComponent[], unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean {
|
|
122
|
-
let idx = 0;
|
|
123
|
-
|
|
124
|
-
function _doUnload(): void | boolean {
|
|
125
|
-
while (idx < components.length) {
|
|
126
|
-
let component = components[idx++];
|
|
127
|
-
if (component) {
|
|
128
|
-
let func = component._doUnload || component._doTeardown;
|
|
129
|
-
if (isFunction(func)) {
|
|
130
|
-
if (func.call(component, unloadCtx, unloadState, _doUnload) === true) {
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return _doUnload();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Creates a IDistributedTraceContext which optionally also "sets" the value on a parent
|
|
144
|
-
* @param parentCtx - An optional parent distributed trace instance
|
|
145
|
-
* @returns A new IDistributedTraceContext instance that uses an internal temporary object
|
|
146
|
-
*/
|
|
147
|
-
export function createDistributedTraceContext(parentCtx?: IDistributedTraceContext): IDistributedTraceContext {
|
|
148
|
-
let trace: ITraceParent = {} as ITraceParent;
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
getName: (): string => {
|
|
152
|
-
return (trace as any).name;
|
|
153
|
-
},
|
|
154
|
-
setName: (newValue: string): void => {
|
|
155
|
-
parentCtx && parentCtx.setName(newValue);
|
|
156
|
-
(trace as any).name = newValue;
|
|
157
|
-
},
|
|
158
|
-
getTraceId: (): string => {
|
|
159
|
-
return trace.traceId;
|
|
160
|
-
},
|
|
161
|
-
setTraceId: (newValue: string): void => {
|
|
162
|
-
parentCtx && parentCtx.setTraceId(newValue);
|
|
163
|
-
if (isValidTraceId(newValue)) {
|
|
164
|
-
trace.traceId = newValue
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
getSpanId: (): string => {
|
|
168
|
-
return trace.spanId;
|
|
169
|
-
},
|
|
170
|
-
setSpanId: (newValue: string): void => {
|
|
171
|
-
parentCtx && parentCtx.setSpanId(newValue);
|
|
172
|
-
if (isValidSpanId(newValue)) {
|
|
173
|
-
trace.spanId = newValue
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
getTraceFlags: (): number => {
|
|
177
|
-
return trace.traceFlags;
|
|
178
|
-
},
|
|
179
|
-
setTraceFlags: (newTraceFlags?: number): void => {
|
|
180
|
-
parentCtx && parentCtx.setTraceFlags(newTraceFlags);
|
|
181
|
-
trace.traceFlags = newTraceFlags
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// // Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// // Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
5
|
-
import { arrForEach, dumpObj } from "@nevware21/ts-utils";
|
|
6
|
-
import { _eInternalMessageId, eLoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
|
|
7
|
-
import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
|
|
8
|
-
import {
|
|
9
|
-
ITelemetryInitializerContainer, ITelemetryInitializerHandler, TelemetryInitializerFunction
|
|
10
|
-
} from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
|
|
11
|
-
import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
|
|
12
|
-
import { BaseTelemetryPlugin } from "./BaseTelemetryPlugin";
|
|
13
|
-
import { _throwInternal } from "./DiagnosticLogger";
|
|
14
|
-
import { getExceptionName } from "./HelperFuncs";
|
|
15
|
-
|
|
16
|
-
interface _IInternalTelemetryInitializerHandler {
|
|
17
|
-
id: number;
|
|
18
|
-
fn: TelemetryInitializerFunction;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class TelemetryInitializerPlugin extends BaseTelemetryPlugin implements ITelemetryInitializerContainer {
|
|
22
|
-
|
|
23
|
-
public identifier: string = "TelemetryInitializerPlugin";
|
|
24
|
-
priority: number = 199;
|
|
25
|
-
|
|
26
|
-
constructor() {
|
|
27
|
-
super();
|
|
28
|
-
|
|
29
|
-
// NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
|
|
30
|
-
let _id: number;
|
|
31
|
-
let _initializers: _IInternalTelemetryInitializerHandler[];
|
|
32
|
-
|
|
33
|
-
_initDefaults();
|
|
34
|
-
|
|
35
|
-
dynamicProto(TelemetryInitializerPlugin, this, (_self, _base) => {
|
|
36
|
-
|
|
37
|
-
_self.addTelemetryInitializer = (telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler => {
|
|
38
|
-
let theInitializer = {
|
|
39
|
-
id: _id++,
|
|
40
|
-
fn: telemetryInitializer
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
_initializers.push(theInitializer);
|
|
44
|
-
|
|
45
|
-
let handler: ITelemetryInitializerHandler = {
|
|
46
|
-
remove: () => {
|
|
47
|
-
arrForEach(_initializers, (initializer, idx) => {
|
|
48
|
-
if (initializer.id === theInitializer.id) {
|
|
49
|
-
_initializers.splice(idx, 1);
|
|
50
|
-
return -1;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return handler;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
_self.processTelemetry = (item: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void => {
|
|
60
|
-
var doNotSendItem = false;
|
|
61
|
-
var telemetryInitializersCount = _initializers.length;
|
|
62
|
-
for (var i = 0; i < telemetryInitializersCount; ++i) {
|
|
63
|
-
var telemetryInitializer = _initializers[i];
|
|
64
|
-
if (telemetryInitializer) {
|
|
65
|
-
try {
|
|
66
|
-
if (telemetryInitializer.fn.apply(null, [item]) === false) {
|
|
67
|
-
doNotSendItem = true;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
} catch (e) {
|
|
71
|
-
// log error but dont stop executing rest of the telemetry initializers
|
|
72
|
-
// doNotSendItem = true;
|
|
73
|
-
_throwInternal(
|
|
74
|
-
itemCtx.diagLog(),
|
|
75
|
-
eLoggingSeverity.WARNING,
|
|
76
|
-
_eInternalMessageId.TelemetryInitializerFailed,
|
|
77
|
-
"Telemetry initializer failed: " + getExceptionName(e),
|
|
78
|
-
{ exception: dumpObj(e) }, true);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!doNotSendItem) {
|
|
84
|
-
_self.processNext(item, itemCtx);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
_self._doTeardown = () => {
|
|
89
|
-
_initDefaults();
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
function _initDefaults() {
|
|
94
|
-
_id = 0;
|
|
95
|
-
_initializers = [];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Add a telemetry processor to decorate or drop telemetry events.
|
|
101
|
-
* @param telemetryInitializer - The Telemetry Initializer function
|
|
102
|
-
* @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
|
|
103
|
-
*/
|
|
104
|
-
public addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler {
|
|
105
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void {
|
|
110
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { arrForEach, dumpObj } from "@nevware21/ts-utils";
|
|
5
|
-
import { _eInternalMessageId, eLoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
|
|
6
|
-
import { IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
|
|
7
|
-
import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
|
|
8
|
-
import { _throwInternal } from "./DiagnosticLogger";
|
|
9
|
-
|
|
10
|
-
export type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
|
|
11
|
-
|
|
12
|
-
export interface IUnloadHandlerContainer {
|
|
13
|
-
add: (handler: UnloadHandler) => void;
|
|
14
|
-
run: (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function createUnloadHandlerContainer(): IUnloadHandlerContainer {
|
|
18
|
-
let handlers: UnloadHandler[] = [];
|
|
19
|
-
|
|
20
|
-
function _addHandler(handler: UnloadHandler) {
|
|
21
|
-
if (handler) {
|
|
22
|
-
handlers.push(handler);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function _runHandlers(unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) {
|
|
27
|
-
arrForEach(handlers, (handler) => {
|
|
28
|
-
try {
|
|
29
|
-
handler(unloadCtx, unloadState);
|
|
30
|
-
} catch (e) {
|
|
31
|
-
_throwInternal(
|
|
32
|
-
unloadCtx.diagLog(),
|
|
33
|
-
eLoggingSeverity.WARNING,
|
|
34
|
-
_eInternalMessageId.PluginException,
|
|
35
|
-
"Unexpected error calling unload handler - " + dumpObj(e));
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
handlers = [];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
add: _addHandler,
|
|
43
|
-
run: _runHandlers
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { arrAppend, arrForEach, dumpObj } from "@nevware21/ts-utils";
|
|
5
|
-
import { eLoggingSeverity, _eInternalMessageId } from "../JavaScriptSDK.Enums/LoggingEnums";
|
|
6
|
-
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
|
|
7
|
-
import { ILegacyUnloadHook, IUnloadHook } from "../JavaScriptSDK.Interfaces/IUnloadHook";
|
|
8
|
-
import { _throwInternal } from "./DiagnosticLogger";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Interface which identifiesAdd this hook so that it is automatically removed during unloading
|
|
12
|
-
* @param hooks - The single hook or an array of IInstrumentHook objects
|
|
13
|
-
*/
|
|
14
|
-
export interface IUnloadHookContainer {
|
|
15
|
-
add: (hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>) => void;
|
|
16
|
-
run: (logger?: IDiagnosticLogger) => void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Create a IUnloadHookContainer which can be used to remember unload hook functions to be executed during the component unloading
|
|
21
|
-
* process.
|
|
22
|
-
* @returns A new IUnloadHookContainer instance
|
|
23
|
-
*/
|
|
24
|
-
export function createUnloadHookContainer(): IUnloadHookContainer {
|
|
25
|
-
let _hooks: Array<ILegacyUnloadHook | IUnloadHook> = [];
|
|
26
|
-
|
|
27
|
-
function _doUnload(logger: IDiagnosticLogger) {
|
|
28
|
-
let oldHooks = _hooks;
|
|
29
|
-
_hooks = [];
|
|
30
|
-
|
|
31
|
-
// Remove all registered unload hooks
|
|
32
|
-
arrForEach(oldHooks, (fn) => {
|
|
33
|
-
// allow either rm or remove callback function
|
|
34
|
-
try{
|
|
35
|
-
((fn as IUnloadHook).rm || (fn as ILegacyUnloadHook).remove).call(fn);
|
|
36
|
-
} catch (e) {
|
|
37
|
-
_throwInternal(logger, eLoggingSeverity.WARNING, _eInternalMessageId.PluginException, "Unloading:" + dumpObj(e));
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function _addHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>) {
|
|
43
|
-
if (hooks) {
|
|
44
|
-
arrAppend(_hooks, hooks);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
run: _doUnload,
|
|
50
|
-
add: _addHook
|
|
51
|
-
};
|
|
52
|
-
}
|