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