@localstack/appinspector-ui 1.0.186 → 1.0.187

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.js CHANGED
@@ -16632,6 +16632,94 @@ var StatusMessage = ({
16632
16632
  return /* @__PURE__ */ jsx130(Fragment6, {});
16633
16633
  };
16634
16634
 
16635
+ // src/utils/span-parents.ts
16636
+ var resolveParents = (spans) => {
16637
+ const byId = new Map(spans.map((span) => [span.span_id, span]));
16638
+ const parentOf = /* @__PURE__ */ new Map();
16639
+ for (const span of spans) {
16640
+ const parent = span.parent_span_id === null ? void 0 : byId.get(span.parent_span_id);
16641
+ if (parent && parent.span_id !== span.span_id && parent.trace_id === span.trace_id) {
16642
+ parentOf.set(span.span_id, parent.span_id);
16643
+ }
16644
+ }
16645
+ const causes = /* @__PURE__ */ new Map();
16646
+ const addCause = (spanId, causeId) => {
16647
+ const list = causes.get(spanId);
16648
+ if (list) list.push(causeId);
16649
+ else causes.set(spanId, [causeId]);
16650
+ };
16651
+ for (const span of spans) {
16652
+ for (const causeId of span.outgoing_link_span_ids ?? []) addCause(span.span_id, causeId);
16653
+ for (const effectId of span.incoming_link_span_ids ?? []) addCause(effectId, span.span_id);
16654
+ }
16655
+ const isAncestorOrSelf = (candidateId, spanId) => {
16656
+ let current = spanId;
16657
+ for (let hops = 0; current !== void 0 && hops <= spans.length; hops++) {
16658
+ if (current === candidateId) return true;
16659
+ current = parentOf.get(current);
16660
+ }
16661
+ return false;
16662
+ };
16663
+ for (const span of spans) {
16664
+ if (parentOf.has(span.span_id)) continue;
16665
+ const cause = causes.get(span.span_id)?.find((causeId) => byId.has(causeId) && !isAncestorOrSelf(span.span_id, causeId));
16666
+ if (cause !== void 0) parentOf.set(span.span_id, cause);
16667
+ }
16668
+ return parentOf;
16669
+ };
16670
+
16671
+ // src/components/trace-panel/timeline-tree.ts
16672
+ var compareNano = (left, right) => {
16673
+ const difference = BigInt(left) - BigInt(right);
16674
+ if (difference === 0n) return 0;
16675
+ return difference < 0n ? -1 : 1;
16676
+ };
16677
+ var buildTraceTree = (spans) => {
16678
+ const nodes2 = new Map(spans.map((span) => [span.span_id, { children: [], span }]));
16679
+ const parentOf = resolveParents(spans);
16680
+ const roots = [];
16681
+ for (const [spanId, node] of nodes2) {
16682
+ const parent = parentOf.get(spanId);
16683
+ if (parent === void 0) roots.push(node);
16684
+ else nodes2.get(parent)?.children.push(node);
16685
+ }
16686
+ const byStart = (left, right) => compareNano(left.span.start_time_unix_nano, right.span.start_time_unix_nano);
16687
+ roots.sort(byStart);
16688
+ for (const node of nodes2.values()) node.children.sort(byStart);
16689
+ return { parentOf, roots };
16690
+ };
16691
+ var findRootSpan = (spans, parentOf, spanId) => {
16692
+ let current = spanId;
16693
+ for (let hops = 0; hops <= spans.length; hops++) {
16694
+ const parent = parentOf.get(current);
16695
+ if (parent === void 0) break;
16696
+ current = parent;
16697
+ }
16698
+ return spans.find((span) => span.span_id === current);
16699
+ };
16700
+ var findFirstSpan = (nodes2, predicate) => {
16701
+ for (const node of nodes2) {
16702
+ if (predicate(node.span.span_id)) return node.span;
16703
+ const found = findFirstSpan(node.children, predicate);
16704
+ if (found) return found;
16705
+ }
16706
+ return void 0;
16707
+ };
16708
+ var getTraceBounds = (spans) => {
16709
+ let start;
16710
+ let end;
16711
+ for (const span of spans) {
16712
+ const spanStart = BigInt(span.start_time_unix_nano);
16713
+ const spanEnd = span.end_time_unix_nano ? BigInt(span.end_time_unix_nano) : spanStart;
16714
+ if (start === void 0 || spanStart < start) start = spanStart;
16715
+ if (end === void 0 || spanEnd > end) end = spanEnd;
16716
+ }
16717
+ if (start === void 0 || end === void 0) {
16718
+ return { durationMs: 0, startNano: 0n };
16719
+ }
16720
+ return { durationMs: Number(end - start) / 1e6, startNano: start };
16721
+ };
16722
+
16635
16723
  // src/components/trace-panel/trace-sidebar.tsx
16636
16724
  import { Close as Close4 } from "@mui/icons-material";
16637
16725
  import { Box as Box20, IconButton as IconButton8, ToggleButton as ToggleButton3, ToggleButtonGroup as ToggleButtonGroup3, Typography as Typography15 } from "@mui/material";
@@ -32149,86 +32237,6 @@ function useLocalStorage(key, initialValue) {
32149
32237
  return [storedValue, setValue];
32150
32238
  }
32151
32239
 
32152
- // src/utils/span-parents.ts
32153
- var resolveParents = (spans) => {
32154
- const byId = new Map(spans.map((span) => [span.span_id, span]));
32155
- const parentOf = /* @__PURE__ */ new Map();
32156
- for (const span of spans) {
32157
- const parent = span.parent_span_id === null ? void 0 : byId.get(span.parent_span_id);
32158
- if (parent && parent.span_id !== span.span_id && parent.trace_id === span.trace_id) {
32159
- parentOf.set(span.span_id, parent.span_id);
32160
- }
32161
- }
32162
- const causes = /* @__PURE__ */ new Map();
32163
- const addCause = (spanId, causeId) => {
32164
- const list = causes.get(spanId);
32165
- if (list) list.push(causeId);
32166
- else causes.set(spanId, [causeId]);
32167
- };
32168
- for (const span of spans) {
32169
- for (const causeId of span.outgoing_link_span_ids ?? []) addCause(span.span_id, causeId);
32170
- for (const effectId of span.incoming_link_span_ids ?? []) addCause(effectId, span.span_id);
32171
- }
32172
- const isAncestorOrSelf = (candidateId, spanId) => {
32173
- let current = spanId;
32174
- for (let hops = 0; current !== void 0 && hops <= spans.length; hops++) {
32175
- if (current === candidateId) return true;
32176
- current = parentOf.get(current);
32177
- }
32178
- return false;
32179
- };
32180
- for (const span of spans) {
32181
- if (parentOf.has(span.span_id)) continue;
32182
- const cause = causes.get(span.span_id)?.find((causeId) => byId.has(causeId) && !isAncestorOrSelf(span.span_id, causeId));
32183
- if (cause !== void 0) parentOf.set(span.span_id, cause);
32184
- }
32185
- return parentOf;
32186
- };
32187
-
32188
- // src/components/trace-panel/timeline-tree.ts
32189
- var compareNano = (left, right) => {
32190
- const difference = BigInt(left) - BigInt(right);
32191
- if (difference === 0n) return 0;
32192
- return difference < 0n ? -1 : 1;
32193
- };
32194
- var buildTraceTree = (spans) => {
32195
- const nodes2 = new Map(spans.map((span) => [span.span_id, { children: [], span }]));
32196
- const parentOf = resolveParents(spans);
32197
- const roots = [];
32198
- for (const [spanId, node] of nodes2) {
32199
- const parent = parentOf.get(spanId);
32200
- if (parent === void 0) roots.push(node);
32201
- else nodes2.get(parent)?.children.push(node);
32202
- }
32203
- const byStart = (left, right) => compareNano(left.span.start_time_unix_nano, right.span.start_time_unix_nano);
32204
- roots.sort(byStart);
32205
- for (const node of nodes2.values()) node.children.sort(byStart);
32206
- return { parentOf, roots };
32207
- };
32208
- var findRootSpan = (spans, parentOf, spanId) => {
32209
- let current = spanId;
32210
- for (let hops = 0; hops <= spans.length; hops++) {
32211
- const parent = parentOf.get(current);
32212
- if (parent === void 0) break;
32213
- current = parent;
32214
- }
32215
- return spans.find((span) => span.span_id === current);
32216
- };
32217
- var getTraceBounds = (spans) => {
32218
- let start;
32219
- let end;
32220
- for (const span of spans) {
32221
- const spanStart = BigInt(span.start_time_unix_nano);
32222
- const spanEnd = span.end_time_unix_nano ? BigInt(span.end_time_unix_nano) : spanStart;
32223
- if (start === void 0 || spanStart < start) start = spanStart;
32224
- if (end === void 0 || spanEnd > end) end = spanEnd;
32225
- }
32226
- if (start === void 0 || end === void 0) {
32227
- return { durationMs: 0, startNano: 0n };
32228
- }
32229
- return { durationMs: Number(end - start) / 1e6, startNano: start };
32230
- };
32231
-
32232
32240
  // src/components/trace-panel/waterfall.tsx
32233
32241
  import { AccountTreeOutlined, Cancel as Cancel7, Error as ErrorIcon5, FormatListBulleted, KeyboardArrowDown as KeyboardArrowDown2, KeyboardArrowRight as KeyboardArrowRight2 } from "@mui/icons-material";
32234
32242
  import { Box as Box19, ButtonBase, ToggleButton as ToggleButton2, ToggleButtonGroup as ToggleButtonGroup2, Typography as Typography14 } from "@mui/material";
@@ -33528,17 +33536,22 @@ var SpansListPage = () => {
33528
33536
  const [bannerDismissed, setBannerDismissed] = useState22(false);
33529
33537
  const [order2, setOrder] = useLocalStorage("spans-order", "oldest_first");
33530
33538
  const [selectedSpanId, setSelectedSpanId] = useState22();
33539
+ const getTreeSpans = useCallback12((rootSpanId2) => Object.entries(compute.rows).filter(([, row]) => row.rootSpanId === rootSpanId2).map(([spanId]) => getSpan(spanId)).filter((span) => span !== void 0), [compute.rows, getSpan]);
33540
+ const latestRef = useRef19({ compute, getTreeSpans });
33541
+ useEffect22(() => {
33542
+ latestRef.current = { compute, getTreeSpans };
33543
+ }, [compute, getTreeSpans]);
33531
33544
  const navigateToSpan = useCallback12((span) => {
33532
- setSelectedSpanId(span.span_id);
33545
+ const { compute: { queryActive, rows }, getTreeSpans: getSpans } = latestRef.current;
33546
+ const rootSpanId2 = rows[span.span_id]?.rootSpanId;
33547
+ const firstMatch = queryActive && rootSpanId2 !== void 0 ? findFirstSpan(buildTraceTree(getSpans(rootSpanId2)).roots, (spanId) => rows[spanId]?.matches ?? false) : void 0;
33548
+ setSelectedSpanId(firstMatch?.span_id ?? span.span_id);
33533
33549
  }, []);
33534
33550
  const closeSidebar = useCallback12(() => {
33535
33551
  setSelectedSpanId(void 0);
33536
33552
  }, []);
33537
33553
  const rootSpanId = selectedSpanId === void 0 ? void 0 : compute.rows[selectedSpanId]?.rootSpanId;
33538
- const treeSpans = useMemo13(() => {
33539
- if (rootSpanId === void 0) return [];
33540
- return Object.entries(compute.rows).filter(([, row]) => row.rootSpanId === rootSpanId).map(([spanId]) => getSpan(spanId)).filter((span) => span !== void 0);
33541
- }, [compute.rows, getSpan, rootSpanId]);
33554
+ const treeSpans = useMemo13(() => rootSpanId === void 0 ? [] : getTreeSpans(rootSpanId), [getTreeSpans, rootSpanId]);
33542
33555
  const spanMatches = useMemo13(
33543
33556
  () => compute.queryActive ? (spanId) => compute.rows[spanId]?.matches ?? false : void 0,
33544
33557
  [compute]