sobey-monitor-sdk 1.1.9 → 1.1.11
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 +59 -35
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +59 -35
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +59 -35
- package/dist/index.umd.js.map +1 -1
- package/dist/reporter/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -418,10 +418,12 @@ class Reporter {
|
|
|
418
418
|
}
|
|
419
419
|
/**
|
|
420
420
|
* 发送早期缓存的数据(根据最新配置过滤)
|
|
421
|
+
* 所有数据会先累积到 sender 的缓冲区,最后统一发送一次
|
|
421
422
|
*/
|
|
422
423
|
flushEarlyBuffer() {
|
|
423
424
|
const cfg = config.get();
|
|
424
425
|
let skippedCount = 0;
|
|
426
|
+
let processedCount = 0;
|
|
425
427
|
// 全局开关检查:如果 enabled 为 false,清空缓存不上报
|
|
426
428
|
if (cfg.enabled === false) {
|
|
427
429
|
const totalCount = this.earlyBuffer.length;
|
|
@@ -462,6 +464,7 @@ class Reporter {
|
|
|
462
464
|
continue;
|
|
463
465
|
}
|
|
464
466
|
this.reportError(item.data);
|
|
467
|
+
processedCount++;
|
|
465
468
|
break;
|
|
466
469
|
case 'performance':
|
|
467
470
|
// 检查性能监控是否启用
|
|
@@ -470,6 +473,7 @@ class Reporter {
|
|
|
470
473
|
continue;
|
|
471
474
|
}
|
|
472
475
|
this.reportPerformance(item.data);
|
|
476
|
+
processedCount++;
|
|
473
477
|
break;
|
|
474
478
|
case 'behavior':
|
|
475
479
|
// 检查行为监控是否启用
|
|
@@ -488,9 +492,17 @@ class Reporter {
|
|
|
488
492
|
continue;
|
|
489
493
|
}
|
|
490
494
|
this.reportBehavior(item.data);
|
|
495
|
+
processedCount++;
|
|
491
496
|
break;
|
|
492
497
|
}
|
|
493
498
|
}
|
|
499
|
+
// 所有早期数据已添加到 sender 缓冲区,立即统一发送
|
|
500
|
+
if (processedCount > 0) {
|
|
501
|
+
sender.flush();
|
|
502
|
+
if (cfg.debug) {
|
|
503
|
+
console.log(`[Monitor] Flushed ${processedCount} early buffered items in single batch`);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
494
506
|
if (skippedCount > 0 && cfg.debug) {
|
|
495
507
|
console.log(`[Monitor] Filtered out ${skippedCount} early buffered items based on config`);
|
|
496
508
|
}
|
|
@@ -768,12 +780,20 @@ function installHttpErrorHandler() {
|
|
|
768
780
|
* 检查是否是 SDK 自身的请求
|
|
769
781
|
*/
|
|
770
782
|
function isSdkRequest(url) {
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
return
|
|
776
|
-
|
|
783
|
+
// 检查是否匹配常见的 SDK 上报路径
|
|
784
|
+
if (url.includes('/monitor/api/report') ||
|
|
785
|
+
url.includes('/monitor/api/beacon') ||
|
|
786
|
+
url.includes('/monitor/api/config')) {
|
|
787
|
+
return true;
|
|
788
|
+
}
|
|
789
|
+
// 配置已初始化时,检查 dsn
|
|
790
|
+
if (config.isInitialized()) {
|
|
791
|
+
const cfg = config.get();
|
|
792
|
+
if (cfg.dsn && url.includes(cfg.dsn)) {
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return false;
|
|
777
797
|
}
|
|
778
798
|
/**
|
|
779
799
|
* 获取嵌套对象的字段值
|
|
@@ -963,35 +983,39 @@ function interceptFetch() {
|
|
|
963
983
|
},
|
|
964
984
|
});
|
|
965
985
|
}
|
|
966
|
-
//
|
|
967
|
-
const
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
986
|
+
// 检查是否配置了业务错误规则
|
|
987
|
+
const hasBusinessRules = cfg?.error?.businessErrorRules && cfg.error.businessErrorRules.length > 0;
|
|
988
|
+
// 只有在请求失败或配置了业务规则时才读取响应体
|
|
989
|
+
if (!response.ok || hasBusinessRules) {
|
|
990
|
+
const cloned = response.clone();
|
|
991
|
+
let responseBody;
|
|
992
|
+
try {
|
|
993
|
+
responseBody = await cloned.text();
|
|
994
|
+
responseBody = responseBody.substring(0, 1000);
|
|
995
|
+
}
|
|
996
|
+
catch { }
|
|
997
|
+
if (!response.ok) {
|
|
998
|
+
// HTTP 错误
|
|
999
|
+
reportHttpError({
|
|
1000
|
+
method,
|
|
1001
|
+
url,
|
|
1002
|
+
status,
|
|
1003
|
+
duration,
|
|
1004
|
+
requestBody,
|
|
1005
|
+
responseBody,
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
else if (hasBusinessRules && detectBusinessError(responseBody)) {
|
|
1009
|
+
// HTTP 200 但检测到业务错误
|
|
1010
|
+
reportHttpError({
|
|
1011
|
+
method,
|
|
1012
|
+
url,
|
|
1013
|
+
status,
|
|
1014
|
+
duration,
|
|
1015
|
+
requestBody,
|
|
1016
|
+
responseBody,
|
|
1017
|
+
}, true);
|
|
1018
|
+
}
|
|
995
1019
|
}
|
|
996
1020
|
return response;
|
|
997
1021
|
}
|