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