@microsoft/applicationinsights-common 3.0.0-beta.2210-19 → 3.0.0-beta.2210-21
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-common.integrity.json +9 -9
- package/browser/applicationinsights-common.js +385 -159
- package/browser/applicationinsights-common.js.map +1 -1
- package/browser/applicationinsights-common.min.js +2 -2
- package/browser/applicationinsights-common.min.js.map +1 -1
- package/dist/applicationinsights-common.api.json +2048 -1176
- package/dist/applicationinsights-common.api.md +65 -0
- package/dist/applicationinsights-common.d.ts +118 -1
- package/dist/applicationinsights-common.js +385 -159
- package/dist/applicationinsights-common.js.map +1 -1
- package/dist/applicationinsights-common.min.js +2 -2
- package/dist/applicationinsights-common.min.js.map +1 -1
- package/dist/applicationinsights-common.rollup.d.ts +118 -1
- package/dist-esm/ConnectionStringParser.js +1 -1
- package/dist-esm/Constants.js +1 -1
- package/dist-esm/DomHelperFuncs.js +1 -1
- package/dist-esm/Enums.js +1 -1
- package/dist-esm/HelperFuncs.js +1 -1
- package/dist-esm/Interfaces/ConnectionString.js +1 -1
- package/dist-esm/Interfaces/Context/IApplication.js +1 -1
- package/dist-esm/Interfaces/Context/IDevice.js +1 -1
- package/dist-esm/Interfaces/Context/IInternal.js +1 -1
- package/dist-esm/Interfaces/Context/ILocation.js +1 -1
- package/dist-esm/Interfaces/Context/IOperatingSystem.js +1 -1
- package/dist-esm/Interfaces/Context/ISample.js +1 -1
- package/dist-esm/Interfaces/Context/ISession.js +1 -1
- package/dist-esm/Interfaces/Context/ITelemetryTrace.js +1 -1
- package/dist-esm/Interfaces/Context/IUser.js +1 -1
- package/dist-esm/Interfaces/Context/IWeb.js +1 -1
- package/dist-esm/Interfaces/Contracts/AvailabilityData.js +1 -1
- package/dist-esm/Interfaces/Contracts/ContextTagKeys.js +1 -1
- package/dist-esm/Interfaces/Contracts/DataPointType.js +1 -1
- package/dist-esm/Interfaces/Contracts/DependencyKind.js +1 -1
- package/dist-esm/Interfaces/Contracts/DependencySourceType.js +1 -1
- package/dist-esm/Interfaces/Contracts/IBase.js +1 -1
- package/dist-esm/Interfaces/Contracts/IData.js +1 -1
- package/dist-esm/Interfaces/Contracts/IDataPoint.js +1 -1
- package/dist-esm/Interfaces/Contracts/IDomain.js +1 -1
- package/dist-esm/Interfaces/Contracts/IEnvelope.js +1 -1
- package/dist-esm/Interfaces/Contracts/IEventData.js +1 -1
- package/dist-esm/Interfaces/Contracts/IExceptionData.js +1 -1
- package/dist-esm/Interfaces/Contracts/IExceptionDetails.js +1 -1
- package/dist-esm/Interfaces/Contracts/IMessageData.js +1 -1
- package/dist-esm/Interfaces/Contracts/IMetricData.js +1 -1
- package/dist-esm/Interfaces/Contracts/IPageViewData.js +1 -1
- package/dist-esm/Interfaces/Contracts/IPageViewPerfData.js +1 -1
- package/dist-esm/Interfaces/Contracts/IRemoteDependencyData.js +1 -1
- package/dist-esm/Interfaces/Contracts/IStackFrame.js +1 -1
- package/dist-esm/Interfaces/Contracts/RequestData.js +1 -1
- package/dist-esm/Interfaces/Contracts/SeverityLevel.js +1 -1
- package/dist-esm/Interfaces/IAppInsights.js +1 -1
- package/dist-esm/Interfaces/IChannelControlsAI.js +1 -1
- package/dist-esm/Interfaces/IConfig.js +1 -1
- package/dist-esm/Interfaces/ICorrelationConfig.js +1 -1
- package/dist-esm/Interfaces/IDependencyTelemetry.js +1 -1
- package/dist-esm/Interfaces/IEventTelemetry.js +1 -1
- package/dist-esm/Interfaces/IExceptionTelemetry.js +1 -1
- package/dist-esm/Interfaces/IMetricTelemetry.js +1 -1
- package/dist-esm/Interfaces/IPageViewPerformanceTelemetry.js +1 -1
- package/dist-esm/Interfaces/IPageViewTelemetry.js +1 -1
- package/dist-esm/Interfaces/IPartC.js +1 -1
- package/dist-esm/Interfaces/IPropertiesPlugin.js +1 -1
- package/dist-esm/Interfaces/IRequestContext.js +1 -1
- package/dist-esm/Interfaces/ITelemetryContext.js +1 -1
- package/dist-esm/Interfaces/IThrottleMgr.js +6 -0
- package/dist-esm/Interfaces/IThrottleMgr.js.map +1 -0
- package/dist-esm/Interfaces/ITraceTelemetry.js +1 -1
- package/dist-esm/Interfaces/PartAExtensions.js +1 -1
- package/dist-esm/Interfaces/Telemetry/IEnvelope.js +1 -1
- package/dist-esm/Interfaces/Telemetry/ISerializable.js +1 -1
- package/dist-esm/RequestResponseHeaders.js +1 -1
- package/dist-esm/StorageHelperFuncs.js +1 -1
- package/dist-esm/Telemetry/Common/Data.js +1 -1
- package/dist-esm/Telemetry/Common/DataPoint.js +1 -1
- package/dist-esm/Telemetry/Common/DataSanitizer.js +1 -1
- package/dist-esm/Telemetry/Common/Envelope.js +1 -1
- package/dist-esm/Telemetry/Event.js +1 -1
- package/dist-esm/Telemetry/Exception.js +1 -1
- package/dist-esm/Telemetry/Metric.js +3 -3
- package/dist-esm/Telemetry/Metric.js.map +1 -1
- package/dist-esm/Telemetry/PageView.js +1 -1
- package/dist-esm/Telemetry/PageViewPerformance.js +1 -1
- package/dist-esm/Telemetry/RemoteDependencyData.js +1 -1
- package/dist-esm/Telemetry/Trace.js +1 -1
- package/dist-esm/TelemetryItemCreator.js +1 -1
- package/dist-esm/ThrottleMgr.js +259 -0
- package/dist-esm/ThrottleMgr.js.map +1 -0
- package/dist-esm/UrlHelperFuncs.js +1 -1
- package/dist-esm/Util.js +1 -1
- package/dist-esm/__DynamicConstants.js +10 -4
- package/dist-esm/__DynamicConstants.js.map +1 -1
- package/dist-esm/applicationinsights-common.js +2 -1
- package/dist-esm/applicationinsights-common.js.map +1 -1
- package/package.json +5 -4
- package/src/Enums.ts +6 -0
- package/src/Interfaces/IThrottleMgr.ts +109 -0
- package/src/ThrottleMgr.ts +285 -0
- package/src/__DynamicConstants.ts +9 -3
- package/src/applicationinsights-common.ts +3 -1
- package/types/Enums.d.ts +5 -0
- package/types/Interfaces/IThrottleMgr.d.ts +94 -0
- package/types/ThrottleMgr.d.ts +12 -0
- package/types/__DynamicConstants.d.ts +8 -2
- package/types/applicationinsights-common.d.ts +3 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { IThrottleMsgKey } from "../Enums";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Identifies limit number/percentage of items sent per time
|
|
5
|
+
* If both are provided, minimum number between the two will be used
|
|
6
|
+
*/
|
|
7
|
+
export interface IThrottleLimit {
|
|
8
|
+
/**
|
|
9
|
+
* Identifies sampling percentage of items per time
|
|
10
|
+
* The percentage is set to 4 decimal places, for example: 1 means 0.0001%
|
|
11
|
+
* Default: 100 (0.01%)
|
|
12
|
+
*/
|
|
13
|
+
samplingRate?: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Identifies limit number of items per time
|
|
17
|
+
* Default: 1
|
|
18
|
+
*/
|
|
19
|
+
maxSendNumber?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Identifies frequency of items sent
|
|
24
|
+
* Default: send data on 28th every 3 month each year
|
|
25
|
+
*/
|
|
26
|
+
export interface IThrottleInterval {
|
|
27
|
+
/**
|
|
28
|
+
* Identifies month interval that items can be sent
|
|
29
|
+
* For example, if it is set to 2 and start date is in Jan, items will be sent out every two months (Jan, March, May etc.)
|
|
30
|
+
* Default: 3
|
|
31
|
+
*/
|
|
32
|
+
monthInterval?: number;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Identifies days that items can be sent within a month
|
|
36
|
+
* Default: 28
|
|
37
|
+
*/
|
|
38
|
+
dayInterval?: number;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Identifies max times items can be sent within a month
|
|
42
|
+
* Default: 1
|
|
43
|
+
*/
|
|
44
|
+
maxTimesPerMonth?: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Identifies basic config
|
|
49
|
+
*/
|
|
50
|
+
export interface IThrottleMgrConfig {
|
|
51
|
+
/**
|
|
52
|
+
* Identifies message key to be used for local storage key
|
|
53
|
+
*/
|
|
54
|
+
msgKey: IThrottleMsgKey;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Identifies if throttle is disabled
|
|
58
|
+
* Default: false
|
|
59
|
+
*/
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Identifies limit number/percentage of items sent per time
|
|
64
|
+
*/
|
|
65
|
+
limit?: IThrottleLimit;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Identifies frequency of items sent
|
|
69
|
+
* Default: send data on 28th every 3 month each year
|
|
70
|
+
*/
|
|
71
|
+
interval?: IThrottleInterval;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Identifies object for local storage
|
|
76
|
+
*/
|
|
77
|
+
export interface IThrottleLocalStorageObj {
|
|
78
|
+
/**
|
|
79
|
+
* Identifies start date
|
|
80
|
+
*/
|
|
81
|
+
date: Date;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Identifies current count
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
count: number;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* identifies previous triggered throttle date
|
|
91
|
+
*/
|
|
92
|
+
preTriggerDate?: Date;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Identifies throttle result
|
|
97
|
+
*/
|
|
98
|
+
export interface IThrottleResult {
|
|
99
|
+
/**
|
|
100
|
+
* Identifies if items are sent
|
|
101
|
+
*/
|
|
102
|
+
isThrottled: boolean;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Identifies numbers of items are sent
|
|
106
|
+
* if isThrottled is false, it will be set to 0
|
|
107
|
+
*/
|
|
108
|
+
throttleNum: number;
|
|
109
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IAppInsightsCore, IDiagnosticLogger, _eInternalMessageId, _throwInternal, arrForEach, eLoggingSeverity, isNotNullOrUndefined,
|
|
3
|
+
isNullOrUndefined, randomValue, safeGetLogger, strTrim
|
|
4
|
+
} from "@microsoft/applicationinsights-core-js";
|
|
5
|
+
import { IThrottleMsgKey } from "./Enums";
|
|
6
|
+
import { IThrottleLocalStorageObj, IThrottleMgrConfig, IThrottleResult } from "./Interfaces/IThrottleMgr";
|
|
7
|
+
import { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from "./StorageHelperFuncs";
|
|
8
|
+
|
|
9
|
+
const THROTTLE_STORAGE_PREFIX = "appInsightsThrottle";
|
|
10
|
+
|
|
11
|
+
interface SendMsgParameter {
|
|
12
|
+
msgID: _eInternalMessageId,
|
|
13
|
+
message: string,
|
|
14
|
+
severity?: eLoggingSeverity
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class ThrottleMgr {
|
|
18
|
+
public canThrottle: () => boolean;
|
|
19
|
+
public sendMessage: (msgID: _eInternalMessageId, message: string, severity?: eLoggingSeverity) => IThrottleResult | null;
|
|
20
|
+
public getConfig: () => IThrottleMgrConfig;
|
|
21
|
+
public isTriggered: () => boolean; // this function is to get previous triggered status
|
|
22
|
+
public isReady: () => boolean
|
|
23
|
+
public onReadyState: (isReady?: boolean) => boolean;
|
|
24
|
+
public flush: () => boolean;
|
|
25
|
+
|
|
26
|
+
constructor(throttleMgr?: IThrottleMgrConfig, core?: IAppInsightsCore, namePrefix?: string) {
|
|
27
|
+
let _self = this;
|
|
28
|
+
let _canUseLocalStorage: boolean;
|
|
29
|
+
let _logger: IDiagnosticLogger | null | undefined;
|
|
30
|
+
let _config: IThrottleMgrConfig;
|
|
31
|
+
let _localStorageName: string | null;
|
|
32
|
+
let _localStorageObj: IThrottleLocalStorageObj | null | undefined;
|
|
33
|
+
let _isTriggered: boolean; //_isTriggered is to make sure that we only trigger throttle once a day
|
|
34
|
+
let _namePrefix: string;
|
|
35
|
+
let _queue: Array<SendMsgParameter>;
|
|
36
|
+
let _isReady: boolean = false;
|
|
37
|
+
|
|
38
|
+
_initConfig();
|
|
39
|
+
|
|
40
|
+
_self.getConfig = (): IThrottleMgrConfig => {
|
|
41
|
+
return _config;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Check if it is the correct day to send message.
|
|
46
|
+
* If _isTriggered is true, even if canThrottle returns true, message will not be sent,
|
|
47
|
+
* because we only allow triggering sendMessage() once a day.
|
|
48
|
+
* @returns if the current date is the valid date to send message
|
|
49
|
+
*/
|
|
50
|
+
_self.canThrottle = (): boolean => {
|
|
51
|
+
return _canThrottle(_config, _canUseLocalStorage, _localStorageObj);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Check if throttle is triggered on current day(UTC)
|
|
56
|
+
* if canThrottle returns false, isTriggered will return false
|
|
57
|
+
* @returns if throttle is triggered on current day(UTC)
|
|
58
|
+
*/
|
|
59
|
+
_self.isTriggered = (): boolean => {
|
|
60
|
+
return _isTriggered;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Before isReady set to true, all message will be stored in queue.
|
|
65
|
+
* Message will only be sent out after isReady set to true.
|
|
66
|
+
* Initial and default value: false
|
|
67
|
+
* @returns isReady state
|
|
68
|
+
*/
|
|
69
|
+
_self.isReady = (): boolean => {
|
|
70
|
+
return _isReady;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Flush all message in queue with isReady state set to true.
|
|
75
|
+
* @returns if message queue is flushed
|
|
76
|
+
*/
|
|
77
|
+
_self.flush = (): boolean => {
|
|
78
|
+
try {
|
|
79
|
+
if (_isReady && _queue.length > 0) {
|
|
80
|
+
arrForEach(_queue, (item: SendMsgParameter) => {
|
|
81
|
+
_self.sendMessage(item.msgID, item.message, item.severity);
|
|
82
|
+
});
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
} catch(err) {
|
|
86
|
+
// eslint-disable-next-line no-empty
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Set isReady State
|
|
93
|
+
* if isReady set to true, message queue will be flushed automatically.
|
|
94
|
+
* @param isReady isReady State
|
|
95
|
+
* @returns if message queue is flushed
|
|
96
|
+
*/
|
|
97
|
+
_self.onReadyState = (isReady?: boolean): boolean => {
|
|
98
|
+
_isReady = isNullOrUndefined(isReady)? true : isReady;
|
|
99
|
+
return _self.flush();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
_self.sendMessage = (msgID: _eInternalMessageId, message: string, severity?: eLoggingSeverity): IThrottleResult | null => {
|
|
103
|
+
if (_isReady) {
|
|
104
|
+
let isSampledIn = _canSampledIn();
|
|
105
|
+
if (!isSampledIn) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
let canThrottle = _canThrottle(_config, _canUseLocalStorage, _localStorageObj);
|
|
109
|
+
let throttled = false;
|
|
110
|
+
let number = 0;
|
|
111
|
+
try {
|
|
112
|
+
if (canThrottle && !_isTriggered) {
|
|
113
|
+
number = Math.min(_config.limit.maxSendNumber, _localStorageObj.count + 1);
|
|
114
|
+
_localStorageObj.count = 0;
|
|
115
|
+
throttled = true;
|
|
116
|
+
_isTriggered = true;
|
|
117
|
+
_localStorageObj.preTriggerDate = new Date();
|
|
118
|
+
} else {
|
|
119
|
+
_isTriggered = canThrottle;
|
|
120
|
+
_localStorageObj.count += 1;
|
|
121
|
+
}
|
|
122
|
+
_resetLocalStorage(_logger, _localStorageName, _localStorageObj);
|
|
123
|
+
for (let i = 0; i < number; i++) {
|
|
124
|
+
_sendMessage(msgID, _logger, message, severity);
|
|
125
|
+
}
|
|
126
|
+
} catch(e) {
|
|
127
|
+
// eslint-disable-next-line no-empty
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
isThrottled: throttled,
|
|
131
|
+
throttleNum: number
|
|
132
|
+
} as IThrottleResult;
|
|
133
|
+
} else {
|
|
134
|
+
_queue.push({
|
|
135
|
+
msgID: msgID,
|
|
136
|
+
message: message,
|
|
137
|
+
severity: severity
|
|
138
|
+
} as SendMsgParameter);
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function _initConfig() {
|
|
144
|
+
_canUseLocalStorage = utlCanUseLocalStorage();
|
|
145
|
+
_logger = safeGetLogger(core);
|
|
146
|
+
_isTriggered = false;
|
|
147
|
+
_namePrefix = isNotNullOrUndefined(namePrefix)? namePrefix : "";
|
|
148
|
+
_queue = [];
|
|
149
|
+
let configMgr = throttleMgr;
|
|
150
|
+
_config = {} as any;
|
|
151
|
+
_config.disabled = !!configMgr.disabled;
|
|
152
|
+
_config.msgKey = configMgr.msgKey;
|
|
153
|
+
// default: send data on 28th every 3 month each year
|
|
154
|
+
let interval = {
|
|
155
|
+
// dafault: sent every three months
|
|
156
|
+
monthInterval: configMgr.interval?.monthInterval || 3,
|
|
157
|
+
dayInterval : configMgr.interval?.dayInterval || 28,
|
|
158
|
+
maxTimesPerMonth: configMgr.interval?.maxTimesPerMonth || 1
|
|
159
|
+
};
|
|
160
|
+
_config.interval = interval;
|
|
161
|
+
let limit = {
|
|
162
|
+
samplingRate: configMgr.limit?.samplingRate || 100,
|
|
163
|
+
// dafault: every time sent only 1 event
|
|
164
|
+
maxSendNumber: configMgr.limit?.maxSendNumber || 1
|
|
165
|
+
};
|
|
166
|
+
_config.limit = limit;
|
|
167
|
+
_localStorageName = _getLocalStorageName(_config.msgKey, _namePrefix);
|
|
168
|
+
|
|
169
|
+
if (_canUseLocalStorage && _localStorageName) {
|
|
170
|
+
_localStorageObj = _getLocalStorageObj(utlGetLocalStorage(_logger, _localStorageName), _logger, _localStorageName);
|
|
171
|
+
}
|
|
172
|
+
if (_localStorageObj) {
|
|
173
|
+
_isTriggered = _isTriggeredOnCurDate(_localStorageObj.preTriggerDate);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function _canThrottle(config: IThrottleMgrConfig, canUseLocalStorage: boolean, localStorageObj: IThrottleLocalStorageObj) {
|
|
178
|
+
if (!config.disabled && canUseLocalStorage && isNotNullOrUndefined(localStorageObj)) {
|
|
179
|
+
let curDate = _getThrottleDate();
|
|
180
|
+
let date = localStorageObj.date;
|
|
181
|
+
let interval = config.interval;
|
|
182
|
+
let monthExpand = (curDate.getUTCFullYear() - date.getUTCFullYear()) * 12 + curDate.getUTCMonth() - date.getUTCMonth();
|
|
183
|
+
let monthCheck = _checkInterval(interval.monthInterval, 0, monthExpand);
|
|
184
|
+
let dayCheck = _checkInterval(interval.dayInterval, 0, curDate.getUTCDate()) -1;
|
|
185
|
+
return monthCheck >= 0 && dayCheck >= 0 && dayCheck <= config.interval.maxTimesPerMonth;
|
|
186
|
+
}
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function _getLocalStorageName(msgKey: IThrottleMsgKey, prefix?: string) {
|
|
191
|
+
let fix = isNotNullOrUndefined(prefix)? prefix : "";
|
|
192
|
+
if (msgKey) {
|
|
193
|
+
return THROTTLE_STORAGE_PREFIX + fix + "-" + msgKey;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// returns if throttle is triggered on current Date
|
|
199
|
+
function _isTriggeredOnCurDate(preTriggerDate?: Date) {
|
|
200
|
+
try {
|
|
201
|
+
if(preTriggerDate) {
|
|
202
|
+
let curDate = new Date();
|
|
203
|
+
return preTriggerDate.getUTCFullYear() === curDate.getUTCFullYear() &&
|
|
204
|
+
preTriggerDate.getUTCMonth() === curDate.getUTCMonth() &&
|
|
205
|
+
preTriggerDate.getUTCDate() === curDate.getUTCDate();
|
|
206
|
+
}
|
|
207
|
+
} catch (e) {
|
|
208
|
+
// eslint-disable-next-line no-empty
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// transfer local storage string value to object that identifies start date, current count and preTriggerDate
|
|
214
|
+
function _getLocalStorageObj(value: string, logger: IDiagnosticLogger, storageName: string) {
|
|
215
|
+
try {
|
|
216
|
+
let storageObj = {
|
|
217
|
+
date: _getThrottleDate(),
|
|
218
|
+
count: 0
|
|
219
|
+
} as IThrottleLocalStorageObj;
|
|
220
|
+
if (value) {
|
|
221
|
+
let obj = JSON.parse(value);
|
|
222
|
+
return {
|
|
223
|
+
date: _getThrottleDate(obj.date) || storageObj.date,
|
|
224
|
+
count: obj.count || storageObj.count,
|
|
225
|
+
preTriggerDate: obj.preTriggerDate? _getThrottleDate(obj.preTriggerDate) : undefined
|
|
226
|
+
} as IThrottleLocalStorageObj;
|
|
227
|
+
} else {
|
|
228
|
+
_resetLocalStorage(logger, storageName, storageObj);
|
|
229
|
+
return storageObj;
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
} catch(e) {
|
|
233
|
+
// eslint-disable-next-line no-empty
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// if datestr is not defined, current date will be returned
|
|
239
|
+
function _getThrottleDate(dateStr?: string) {
|
|
240
|
+
// if new Date() can't be created through the provided dateStr, null will be returned.
|
|
241
|
+
try {
|
|
242
|
+
if (dateStr) {
|
|
243
|
+
let date = new Date(dateStr);
|
|
244
|
+
//make sure it is a valid Date Object
|
|
245
|
+
if (!isNaN(date.getDate())) {
|
|
246
|
+
return date;
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
return new Date();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
} catch (e) {
|
|
253
|
+
// eslint-disable-next-line no-empty
|
|
254
|
+
}
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function _resetLocalStorage(logger: IDiagnosticLogger, storageName: string, obj: IThrottleLocalStorageObj) {
|
|
259
|
+
try {
|
|
260
|
+
return utlSetLocalStorage(logger, storageName, strTrim(JSON.stringify(obj)));
|
|
261
|
+
} catch (e) {
|
|
262
|
+
// // eslint-disable-next-line no-empty
|
|
263
|
+
}
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function _checkInterval(interval: number, start: number, current: number) {
|
|
268
|
+
// count from start year
|
|
269
|
+
return (current >= start) && (current - start) % interval == 0 ? Math.floor((current - start) / interval) + 1 : -1;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function _sendMessage(msgID: _eInternalMessageId, logger: IDiagnosticLogger, message: string, severity?: eLoggingSeverity) {
|
|
273
|
+
_throwInternal(logger,
|
|
274
|
+
severity || eLoggingSeverity.CRITICAL,
|
|
275
|
+
msgID,
|
|
276
|
+
message);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// NOTE: config.limit.samplingRate is set to 4 decimal places,
|
|
280
|
+
// so config.limit.samplingRate = 1 means 0.0001%
|
|
281
|
+
function _canSampledIn() {
|
|
282
|
+
return randomValue(1000000) <= _config.limit.samplingRate;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
@@ -11,12 +11,20 @@
|
|
|
11
11
|
// ###########################################################################################################################################
|
|
12
12
|
|
|
13
13
|
export const _DYN_SPLIT = "split"; // Count: 6
|
|
14
|
-
export const _DYN_LENGTH = "length"; // Count:
|
|
14
|
+
export const _DYN_LENGTH = "length"; // Count: 41
|
|
15
15
|
export const _DYN_TO_LOWER_CASE = "toLowerCase"; // Count: 6
|
|
16
16
|
export const _DYN_INGESTIONENDPOINT = "ingestionendpoint"; // Count: 4
|
|
17
17
|
export const _DYN_TO_STRING = "toString"; // Count: 12
|
|
18
18
|
export const _DYN_REMOVE_ITEM = "removeItem"; // Count: 3
|
|
19
19
|
export const _DYN_NAME = "name"; // Count: 11
|
|
20
|
+
export const _DYN_MESSAGE = "message"; // Count: 10
|
|
21
|
+
export const _DYN_COUNT = "count"; // Count: 8
|
|
22
|
+
export const _DYN_PRE_TRIGGER_DATE = "preTriggerDate"; // Count: 4
|
|
23
|
+
export const _DYN_DISABLED = "disabled"; // Count: 3
|
|
24
|
+
export const _DYN_DATE = "date"; // Count: 5
|
|
25
|
+
export const _DYN_GET_UTCDATE = "getUTCDate"; // Count: 3
|
|
26
|
+
export const _DYN_MAX_TIMES_PER_MONTH = "maxTimesPerMonth"; // Count: 2
|
|
27
|
+
export const _DYN_STRINGIFY = "stringify"; // Count: 4
|
|
20
28
|
export const _DYN_PATHNAME = "pathname"; // Count: 4
|
|
21
29
|
export const _DYN_CORRELATION_HEADER_E0 = "correlationHeaderExcludePatterns"; // Count: 2
|
|
22
30
|
export const _DYN_EXTENSION_CONFIG = "extensionConfig"; // Count: 4
|
|
@@ -24,8 +32,6 @@ export const _DYN_EXCEPTIONS = "exceptions"; // Count: 6
|
|
|
24
32
|
export const _DYN_PARSED_STACK = "parsedStack"; // Count: 11
|
|
25
33
|
export const _DYN_PROPERTIES = "properties"; // Count: 9
|
|
26
34
|
export const _DYN_MEASUREMENTS = "measurements"; // Count: 9
|
|
27
|
-
export const _DYN_STRINGIFY = "stringify"; // Count: 3
|
|
28
|
-
export const _DYN_MESSAGE = "message"; // Count: 8
|
|
29
35
|
export const _DYN_SIZE_IN_BYTES = "sizeInBytes"; // Count: 11
|
|
30
36
|
export const _DYN_TYPE_NAME = "typeName"; // Count: 11
|
|
31
37
|
export const _DYN_SEVERITY_LEVEL = "severityLevel"; // Count: 5
|
|
@@ -5,6 +5,7 @@ export {
|
|
|
5
5
|
correlationIdGetCorrelationContextValue, dateTimeUtilsNow, dateTimeUtilsDuration, isInternalApplicationInsightsEndpoint,
|
|
6
6
|
createDistributedTraceContextFromTrace
|
|
7
7
|
} from "./Util";
|
|
8
|
+
export { ThrottleMgr } from "./ThrottleMgr";
|
|
8
9
|
export { parseConnectionString, ConnectionStringParser } from "./ConnectionStringParser";
|
|
9
10
|
export { FieldType } from "./Enums";
|
|
10
11
|
export { IRequestHeaders, RequestHeaders, eRequestHeaders } from "./RequestResponseHeaders";
|
|
@@ -57,7 +58,8 @@ export { IPropertiesPlugin } from "./Interfaces/IPropertiesPlugin";
|
|
|
57
58
|
export { IUser, IUserContext } from "./Interfaces/Context/IUser";
|
|
58
59
|
export { ITelemetryTrace, ITraceState } from "./Interfaces/Context/ITelemetryTrace";
|
|
59
60
|
export { IRequestContext } from "./Interfaces/IRequestContext";
|
|
60
|
-
export {
|
|
61
|
+
export { IThrottleLocalStorageObj, IThrottleMgrConfig, IThrottleResult, IThrottleLimit, IThrottleInterval } from "./Interfaces/IThrottleMgr";
|
|
62
|
+
export { eDistributedTracingModes, DistributedTracingModes, IThrottleMsgKey } from "./Enums";
|
|
61
63
|
export { stringToBoolOrDefault, msToTimeSpan, getExtensionByName, isCrossOriginError } from "./HelperFuncs";
|
|
62
64
|
export {
|
|
63
65
|
isBeaconsSupported as isBeaconApiSupported,
|
package/types/Enums.d.ts
CHANGED
|
@@ -33,3 +33,8 @@ export declare const enum eDistributedTracingModes {
|
|
|
33
33
|
}
|
|
34
34
|
export declare const DistributedTracingModes: import("@microsoft/applicationinsights-core-js").EnumValue<typeof eDistributedTracingModes>;
|
|
35
35
|
export declare type DistributedTracingModes = number | eDistributedTracingModes;
|
|
36
|
+
export declare const enum IThrottleMsgKey {
|
|
37
|
+
default = 0,
|
|
38
|
+
ikeyDeprecate = 1,
|
|
39
|
+
cdnDeprecate = 2
|
|
40
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { IThrottleMsgKey } from "../Enums";
|
|
2
|
+
/**
|
|
3
|
+
* Identifies limit number/percentage of items sent per time
|
|
4
|
+
* If both are provided, minimum number between the two will be used
|
|
5
|
+
*/
|
|
6
|
+
export interface IThrottleLimit {
|
|
7
|
+
/**
|
|
8
|
+
* Identifies sampling percentage of items per time
|
|
9
|
+
* The percentage is set to 4 decimal places, for example: 1 means 0.0001%
|
|
10
|
+
* Default: 100 (0.01%)
|
|
11
|
+
*/
|
|
12
|
+
samplingRate?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Identifies limit number of items per time
|
|
15
|
+
* Default: 1
|
|
16
|
+
*/
|
|
17
|
+
maxSendNumber?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Identifies frequency of items sent
|
|
21
|
+
* Default: send data on 28th every 3 month each year
|
|
22
|
+
*/
|
|
23
|
+
export interface IThrottleInterval {
|
|
24
|
+
/**
|
|
25
|
+
* Identifies month interval that items can be sent
|
|
26
|
+
* For example, if it is set to 2 and start date is in Jan, items will be sent out every two months (Jan, March, May etc.)
|
|
27
|
+
* Default: 3
|
|
28
|
+
*/
|
|
29
|
+
monthInterval?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Identifies days that items can be sent within a month
|
|
32
|
+
* Default: 28
|
|
33
|
+
*/
|
|
34
|
+
dayInterval?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Identifies max times items can be sent within a month
|
|
37
|
+
* Default: 1
|
|
38
|
+
*/
|
|
39
|
+
maxTimesPerMonth?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Identifies basic config
|
|
43
|
+
*/
|
|
44
|
+
export interface IThrottleMgrConfig {
|
|
45
|
+
/**
|
|
46
|
+
* Identifies message key to be used for local storage key
|
|
47
|
+
*/
|
|
48
|
+
msgKey: IThrottleMsgKey;
|
|
49
|
+
/**
|
|
50
|
+
* Identifies if throttle is disabled
|
|
51
|
+
* Default: false
|
|
52
|
+
*/
|
|
53
|
+
disabled?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Identifies limit number/percentage of items sent per time
|
|
56
|
+
*/
|
|
57
|
+
limit?: IThrottleLimit;
|
|
58
|
+
/**
|
|
59
|
+
* Identifies frequency of items sent
|
|
60
|
+
* Default: send data on 28th every 3 month each year
|
|
61
|
+
*/
|
|
62
|
+
interval?: IThrottleInterval;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Identifies object for local storage
|
|
66
|
+
*/
|
|
67
|
+
export interface IThrottleLocalStorageObj {
|
|
68
|
+
/**
|
|
69
|
+
* Identifies start date
|
|
70
|
+
*/
|
|
71
|
+
date: Date;
|
|
72
|
+
/**
|
|
73
|
+
* Identifies current count
|
|
74
|
+
*/
|
|
75
|
+
count: number;
|
|
76
|
+
/**
|
|
77
|
+
* identifies previous triggered throttle date
|
|
78
|
+
*/
|
|
79
|
+
preTriggerDate?: Date;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Identifies throttle result
|
|
83
|
+
*/
|
|
84
|
+
export interface IThrottleResult {
|
|
85
|
+
/**
|
|
86
|
+
* Identifies if items are sent
|
|
87
|
+
*/
|
|
88
|
+
isThrottled: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Identifies numbers of items are sent
|
|
91
|
+
* if isThrottled is false, it will be set to 0
|
|
92
|
+
*/
|
|
93
|
+
throttleNum: number;
|
|
94
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IAppInsightsCore, _eInternalMessageId, eLoggingSeverity } from "@microsoft/applicationinsights-core-js";
|
|
2
|
+
import { IThrottleMgrConfig, IThrottleResult } from "./Interfaces/IThrottleMgr";
|
|
3
|
+
export declare class ThrottleMgr {
|
|
4
|
+
canThrottle: () => boolean;
|
|
5
|
+
sendMessage: (msgID: _eInternalMessageId, message: string, severity?: eLoggingSeverity) => IThrottleResult | null;
|
|
6
|
+
getConfig: () => IThrottleMgrConfig;
|
|
7
|
+
isTriggered: () => boolean;
|
|
8
|
+
isReady: () => boolean;
|
|
9
|
+
onReadyState: (isReady?: boolean) => boolean;
|
|
10
|
+
flush: () => boolean;
|
|
11
|
+
constructor(throttleMgr?: IThrottleMgrConfig, core?: IAppInsightsCore, namePrefix?: string);
|
|
12
|
+
}
|
|
@@ -5,6 +5,14 @@ export declare const _DYN_INGESTIONENDPOINT = "ingestionendpoint";
|
|
|
5
5
|
export declare const _DYN_TO_STRING = "toString";
|
|
6
6
|
export declare const _DYN_REMOVE_ITEM = "removeItem";
|
|
7
7
|
export declare const _DYN_NAME = "name";
|
|
8
|
+
export declare const _DYN_MESSAGE = "message";
|
|
9
|
+
export declare const _DYN_COUNT = "count";
|
|
10
|
+
export declare const _DYN_PRE_TRIGGER_DATE = "preTriggerDate";
|
|
11
|
+
export declare const _DYN_DISABLED = "disabled";
|
|
12
|
+
export declare const _DYN_DATE = "date";
|
|
13
|
+
export declare const _DYN_GET_UTCDATE = "getUTCDate";
|
|
14
|
+
export declare const _DYN_MAX_TIMES_PER_MONTH = "maxTimesPerMonth";
|
|
15
|
+
export declare const _DYN_STRINGIFY = "stringify";
|
|
8
16
|
export declare const _DYN_PATHNAME = "pathname";
|
|
9
17
|
export declare const _DYN_CORRELATION_HEADER_E0 = "correlationHeaderExcludePatterns";
|
|
10
18
|
export declare const _DYN_EXTENSION_CONFIG = "extensionConfig";
|
|
@@ -12,8 +20,6 @@ export declare const _DYN_EXCEPTIONS = "exceptions";
|
|
|
12
20
|
export declare const _DYN_PARSED_STACK = "parsedStack";
|
|
13
21
|
export declare const _DYN_PROPERTIES = "properties";
|
|
14
22
|
export declare const _DYN_MEASUREMENTS = "measurements";
|
|
15
|
-
export declare const _DYN_STRINGIFY = "stringify";
|
|
16
|
-
export declare const _DYN_MESSAGE = "message";
|
|
17
23
|
export declare const _DYN_SIZE_IN_BYTES = "sizeInBytes";
|
|
18
24
|
export declare const _DYN_TYPE_NAME = "typeName";
|
|
19
25
|
export declare const _DYN_SEVERITY_LEVEL = "severityLevel";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { correlationIdSetPrefix, correlationIdGetPrefix, correlationIdCanIncludeCorrelationHeader, correlationIdGetCorrelationContext, correlationIdGetCorrelationContextValue, dateTimeUtilsNow, dateTimeUtilsDuration, isInternalApplicationInsightsEndpoint, createDistributedTraceContextFromTrace } from "./Util";
|
|
2
|
+
export { ThrottleMgr } from "./ThrottleMgr";
|
|
2
3
|
export { parseConnectionString, ConnectionStringParser } from "./ConnectionStringParser";
|
|
3
4
|
export { FieldType } from "./Enums";
|
|
4
5
|
export { IRequestHeaders, RequestHeaders, eRequestHeaders } from "./RequestResponseHeaders";
|
|
@@ -46,7 +47,8 @@ export { IPropertiesPlugin } from "./Interfaces/IPropertiesPlugin";
|
|
|
46
47
|
export { IUser, IUserContext } from "./Interfaces/Context/IUser";
|
|
47
48
|
export { ITelemetryTrace, ITraceState } from "./Interfaces/Context/ITelemetryTrace";
|
|
48
49
|
export { IRequestContext } from "./Interfaces/IRequestContext";
|
|
49
|
-
export {
|
|
50
|
+
export { IThrottleLocalStorageObj, IThrottleMgrConfig, IThrottleResult, IThrottleLimit, IThrottleInterval } from "./Interfaces/IThrottleMgr";
|
|
51
|
+
export { eDistributedTracingModes, DistributedTracingModes, IThrottleMsgKey } from "./Enums";
|
|
50
52
|
export { stringToBoolOrDefault, msToTimeSpan, getExtensionByName, isCrossOriginError } from "./HelperFuncs";
|
|
51
53
|
export { isBeaconsSupported as isBeaconApiSupported, ITraceParent, createTraceParent, parseTraceParent, isValidTraceId, isValidSpanId, isValidTraceParent, isSampledFlag, formatTraceParent, findW3cTraceParent } from "@microsoft/applicationinsights-core-js";
|
|
52
54
|
export { createDomEvent } from "./DomHelperFuncs";
|