cwj_monitoring 0.0.25 → 0.0.27
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/README.md +1 -1
- package/dist/index.cjs +64 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -4
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.umd.js +64 -4
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -105,12 +105,20 @@ function throttle(fn, delay) {
|
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
|
+
const isIgnoredScriptSource = (sourceURL) => {
|
|
109
|
+
if (!sourceURL || typeof sourceURL !== "string")
|
|
110
|
+
return false;
|
|
111
|
+
if (/node_modules/.test(sourceURL))
|
|
112
|
+
return true;
|
|
113
|
+
return false;
|
|
114
|
+
};
|
|
108
115
|
|
|
109
116
|
const MAX_CACHE_LEN = 5;
|
|
110
117
|
const MAX_WAITING_TIME = 3e4;
|
|
111
118
|
const UUID = "track_uuid";
|
|
112
119
|
const DEFAULT_RESOURCE_THRESHOLD = 1e3;
|
|
113
|
-
const DEFAULT_LOAF_THRESHOLD =
|
|
120
|
+
const DEFAULT_LOAF_THRESHOLD = 100;
|
|
121
|
+
const DEFAULT_LOAF_SINGLETIME = 50;
|
|
114
122
|
|
|
115
123
|
var __defProp$3 = Object.defineProperty;
|
|
116
124
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -662,8 +670,25 @@ const PerformancePlugin = (options = {}) => {
|
|
|
662
670
|
continue;
|
|
663
671
|
}
|
|
664
672
|
const threshold = options.loafThreshold ?? DEFAULT_LOAF_THRESHOLD;
|
|
665
|
-
if (entry.duration
|
|
666
|
-
|
|
673
|
+
if (typeof entry.duration !== "number" || entry.duration <= threshold)
|
|
674
|
+
continue;
|
|
675
|
+
const scripts = Array.isArray(entry.scripts) ? entry.scripts : [];
|
|
676
|
+
let isUserTriggered = false;
|
|
677
|
+
let allIgnored = true;
|
|
678
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
679
|
+
const s = scripts[i];
|
|
680
|
+
if (!s)
|
|
681
|
+
continue;
|
|
682
|
+
if (!isUserTriggered && s.invokerType === "user-callback")
|
|
683
|
+
isUserTriggered = true;
|
|
684
|
+
if (allIgnored && !isIgnoredScriptSource(s.sourceURL)) {
|
|
685
|
+
allIgnored = false;
|
|
686
|
+
}
|
|
687
|
+
if (isUserTriggered && !allIgnored)
|
|
688
|
+
break;
|
|
689
|
+
}
|
|
690
|
+
if (isUserTriggered && !allIgnored) {
|
|
691
|
+
const baseInfo = {
|
|
667
692
|
duration: entry.duration,
|
|
668
693
|
startTime: entry.startTime,
|
|
669
694
|
renderStart: entry.renderStart,
|
|
@@ -675,9 +700,44 @@ const PerformancePlugin = (options = {}) => {
|
|
|
675
700
|
invokerType: s.invokerType,
|
|
676
701
|
sourceURL: s.sourceURL,
|
|
677
702
|
functionName: s.functionName,
|
|
703
|
+
sourceFunctionName: s.sourceFunctionName,
|
|
704
|
+
sourceCharPosition: s.sourceCharPosition,
|
|
678
705
|
startTime: s.startTime
|
|
679
706
|
}))
|
|
680
|
-
}
|
|
707
|
+
};
|
|
708
|
+
(async () => {
|
|
709
|
+
const longScripts = scripts.filter(
|
|
710
|
+
(s) => s && typeof s.duration === "number" && s.duration > DEFAULT_LOAF_SINGLETIME && s.sourceURL
|
|
711
|
+
);
|
|
712
|
+
const contexts = [];
|
|
713
|
+
for (const s of longScripts) {
|
|
714
|
+
try {
|
|
715
|
+
const url = String(s.sourceURL);
|
|
716
|
+
const resp = await fetch(url, { cache: "no-store" });
|
|
717
|
+
if (!resp.ok) {
|
|
718
|
+
contexts.push({ sourceURL: url, error: `http ${resp.status}` });
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
const text = await resp.text();
|
|
722
|
+
const pos = typeof s.sourceCharPosition === "number" ? s.sourceCharPosition : void 0;
|
|
723
|
+
if (pos !== void 0 && Number.isFinite(pos)) {
|
|
724
|
+
const start = Math.max(0, pos - 50);
|
|
725
|
+
const end = Math.min(text.length, pos + 50);
|
|
726
|
+
const snippet = text.substring(start, end);
|
|
727
|
+
contexts.push({ sourceURL: url, position: pos, snippet });
|
|
728
|
+
} else {
|
|
729
|
+
contexts.push({ sourceURL: url, error: "no-position" });
|
|
730
|
+
}
|
|
731
|
+
} catch (e) {
|
|
732
|
+
contexts.push({
|
|
733
|
+
sourceURL: s && s.sourceURL ? String(s.sourceURL) : "",
|
|
734
|
+
error: e?.message || String(e)
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
const info = { ...baseInfo, contexts };
|
|
739
|
+
context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, info);
|
|
740
|
+
})();
|
|
681
741
|
}
|
|
682
742
|
}
|
|
683
743
|
};
|