sobey-monitor-sdk 1.1.16 → 1.1.18
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/dist/index.cjs.js +44 -18
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +44 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +44 -18
- package/dist/index.umd.js.map +1 -1
- package/dist/types/index.d.ts +6 -0
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -104,6 +104,12 @@ interface ErrorMonitorConfig {
|
|
|
104
104
|
* 任一规则匹配时将上报 http_error
|
|
105
105
|
*/
|
|
106
106
|
businessErrorRules?: BusinessErrorRule[];
|
|
107
|
+
/**
|
|
108
|
+
* 要监听的 HTTP 错误状态码列表
|
|
109
|
+
* 如果不配置或为空数组,则默认不捕获 HTTP 错误
|
|
110
|
+
* 例如: [404, 500, 502, 503, 504]
|
|
111
|
+
*/
|
|
112
|
+
httpErrorStatusCodes?: number[];
|
|
107
113
|
}
|
|
108
114
|
/**
|
|
109
115
|
* 性能监控配置
|
package/dist/index.esm.js
CHANGED
|
@@ -423,11 +423,11 @@ if (typeof window !== 'undefined') {
|
|
|
423
423
|
});
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
+
var version = "1.1.17";
|
|
427
|
+
|
|
426
428
|
/**
|
|
427
429
|
* 数据上报管理
|
|
428
430
|
*/
|
|
429
|
-
// SDK 版本
|
|
430
|
-
const SDK_VERSION$1 = '1.0.0';
|
|
431
431
|
/**
|
|
432
432
|
* 上报器类
|
|
433
433
|
*/
|
|
@@ -564,7 +564,7 @@ class Reporter {
|
|
|
564
564
|
pageUrl: getPageUrl(),
|
|
565
565
|
timestamp: Date.now(),
|
|
566
566
|
userAgent: getUserAgent(),
|
|
567
|
-
sdkVersion: cfg.version ||
|
|
567
|
+
sdkVersion: cfg.version || version,
|
|
568
568
|
};
|
|
569
569
|
}
|
|
570
570
|
/**
|
|
@@ -830,6 +830,31 @@ function isSdkRequest(url) {
|
|
|
830
830
|
}
|
|
831
831
|
return false;
|
|
832
832
|
}
|
|
833
|
+
/**
|
|
834
|
+
* 根据配置的状态码列表判断是否应该上报 HTTP 错误
|
|
835
|
+
* @param status HTTP 状态码
|
|
836
|
+
* @returns 是否应该上报
|
|
837
|
+
*/
|
|
838
|
+
function shouldReportHttpError(status) {
|
|
839
|
+
// 获取配置的状态码列表
|
|
840
|
+
if (!config.isInitialized()) {
|
|
841
|
+
// 配置未初始化时,不上报
|
|
842
|
+
console.log(`[Monitor] shouldReportHttpError: config not initialized, status=${status}, returning false`);
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
const cfg = config.get();
|
|
846
|
+
const httpErrorStatusCodes = cfg.error?.httpErrorStatusCodes;
|
|
847
|
+
// 如果未配置状态码列表或为空数组,则不上报任何HTTP错误
|
|
848
|
+
if (!httpErrorStatusCodes || httpErrorStatusCodes.length === 0) {
|
|
849
|
+
console.log(`[Monitor] shouldReportHttpError: no httpErrorStatusCodes configured, status=${status}, returning false`);
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
// 只检查状态码是否在配置的列表中
|
|
853
|
+
const shouldReport = httpErrorStatusCodes.includes(status);
|
|
854
|
+
// 临时强制输出调试日志
|
|
855
|
+
console.log(`[Monitor] HTTP status ${status} shouldReport: ${shouldReport}, configured codes:`, httpErrorStatusCodes);
|
|
856
|
+
return shouldReport;
|
|
857
|
+
}
|
|
833
858
|
/**
|
|
834
859
|
* 获取嵌套对象的字段值
|
|
835
860
|
* @param obj 对象
|
|
@@ -975,8 +1000,8 @@ function interceptXHR() {
|
|
|
975
1000
|
});
|
|
976
1001
|
}
|
|
977
1002
|
const responseBody = this.responseText?.substring(0, 1000);
|
|
978
|
-
// HTTP
|
|
979
|
-
if (status
|
|
1003
|
+
// HTTP 错误(根据配置的状态码列表过滤)
|
|
1004
|
+
if (shouldReportHttpError(status)) {
|
|
980
1005
|
reportHttpError({
|
|
981
1006
|
method: monitorData.method,
|
|
982
1007
|
url: monitorData.url,
|
|
@@ -1049,8 +1074,8 @@ function interceptFetch() {
|
|
|
1049
1074
|
responseBody = responseBody.substring(0, 1000);
|
|
1050
1075
|
}
|
|
1051
1076
|
catch { }
|
|
1052
|
-
if (!response.ok) {
|
|
1053
|
-
// HTTP
|
|
1077
|
+
if (!response.ok && shouldReportHttpError(status)) {
|
|
1078
|
+
// HTTP 错误(根据配置的状态码列表过滤)
|
|
1054
1079
|
reportHttpError({
|
|
1055
1080
|
method,
|
|
1056
1081
|
url,
|
|
@@ -1093,13 +1118,16 @@ function interceptFetch() {
|
|
|
1093
1118
|
},
|
|
1094
1119
|
});
|
|
1095
1120
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1121
|
+
// 网络错误也遵守 httpErrorStatusCodes 配置
|
|
1122
|
+
if (shouldReportHttpError(0)) {
|
|
1123
|
+
reportHttpError({
|
|
1124
|
+
method,
|
|
1125
|
+
url,
|
|
1126
|
+
status: 0,
|
|
1127
|
+
duration,
|
|
1128
|
+
requestBody,
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1103
1131
|
throw error;
|
|
1104
1132
|
}
|
|
1105
1133
|
};
|
|
@@ -1910,8 +1938,6 @@ function createUseMonitorError(React) {
|
|
|
1910
1938
|
* 前端监控 SDK
|
|
1911
1939
|
* @description 错误监控、性能监控、行为监控
|
|
1912
1940
|
*/
|
|
1913
|
-
// SDK 版本
|
|
1914
|
-
const SDK_VERSION = '1.0.0';
|
|
1915
1941
|
/**
|
|
1916
1942
|
* 监控 SDK 主类
|
|
1917
1943
|
*/
|
|
@@ -1989,7 +2015,7 @@ class MonitorSDK {
|
|
|
1989
2015
|
// 初始化配置管理器
|
|
1990
2016
|
config.init({
|
|
1991
2017
|
...finalConfig,
|
|
1992
|
-
version: finalConfig.version ||
|
|
2018
|
+
version: finalConfig.version || version,
|
|
1993
2019
|
}, true);
|
|
1994
2020
|
this.ready = true;
|
|
1995
2021
|
this.loading = false;
|
|
@@ -2166,7 +2192,7 @@ class MonitorSDK {
|
|
|
2166
2192
|
* 获取 SDK 版本
|
|
2167
2193
|
*/
|
|
2168
2194
|
getVersion() {
|
|
2169
|
-
return
|
|
2195
|
+
return version;
|
|
2170
2196
|
}
|
|
2171
2197
|
}
|
|
2172
2198
|
// 导出单例
|