Skip to content

Commit 9093d32

Browse files
niieanibbrzoska
authored andcommitted
feat: better rendering of computed spans
1 parent fea07ac commit 9093d32

File tree

2 files changed

+48
-39
lines changed

2 files changed

+48
-39
lines changed

src/v3/TraceManagerDebugger.tsx

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef, useState } from 'react'
1+
import React, { useEffect, useMemo, useRef, useState } from 'react'
22
import {
33
formatMatcher,
44
formatMs,
@@ -814,6 +814,14 @@ function TraceItem<
814814
!!trace.traceContext &&
815815
!!trace.finalTransition
816816

817+
// Memoize computed results for this trace
818+
const computedResults = useMemo(() => {
819+
if (trace.traceContext && trace.finalTransition) {
820+
return getComputedResults(trace.traceContext, trace.finalTransition)
821+
}
822+
return { computedSpans: {}, computedValues: {} }
823+
}, [trace.traceContext, trace.finalTransition])
824+
817825
// Handle download button click without triggering the expand/collapse
818826
const handleDownloadClick = (e: React.MouseEvent) => {
819827
e.stopPropagation()
@@ -834,12 +842,11 @@ function TraceItem<
834842
? '#c62828'
835843
: '#e0e0e0',
836844
}}
837-
onClick={onToggleExpand}
838845
onMouseEnter={() => void setIsHovered(true)}
839846
onMouseLeave={() => void setIsHovered(false)}
840847
>
841848
{/* ROW 1: Title, state, buttons, and IDs */}
842-
<div style={styles.historyHeader}>
849+
<div style={styles.historyHeader} onClick={onToggleExpand}>
843850
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
844851
<strong style={{ fontSize: '15px' }}>{trace.traceName}</strong>
845852
<span
@@ -975,7 +982,12 @@ function TraceItem<
975982
</div>
976983

977984
{isExpanded && (
978-
<div style={styles.expandedHistory}>
985+
<div
986+
style={styles.expandedHistory}
987+
onClick={(e) => {
988+
void e.stopPropagation()
989+
}}
990+
>
979991
<TraceAttributes attributes={trace.attributes} />
980992

981993
<RequiredSpansList requiredSpans={trace.requiredSpans} />
@@ -990,30 +1002,32 @@ function TraceItem<
9901002
<div style={styles.section}>
9911003
<div style={styles.sectionTitle}>Computed Spans:</div>
9921004
<ul style={{ listStyle: 'none', margin: 0, padding: 0 }}>
993-
{(trace.computedSpans ?? []).map((name) => (
994-
<li key={name} style={styles.listItem}>
995-
{name}
996-
{trace.state === 'complete' || trace.state === 'interrupted'
997-
? (() => {
998-
const { computedSpans } =
999-
trace.traceContext && trace.finalTransition
1000-
? getComputedResults(
1001-
trace.traceContext,
1002-
trace.finalTransition,
1003-
)
1004-
: {}
1005-
if (computedSpans?.[name]) {
1006-
return (
1007-
<span style={{ marginLeft: 8, color: '#1976d2' }}>
1008-
{JSON.stringify(computedSpans[name])}
1009-
</span>
1010-
)
1011-
}
1012-
return null
1013-
})()
1014-
: null}
1015-
</li>
1016-
))}
1005+
{(trace.computedSpans ?? []).map((name) => {
1006+
const value = computedResults.computedSpans?.[name]
1007+
return (
1008+
<li key={name} style={styles.listItem}>
1009+
{name}
1010+
{trace.state === 'complete' ||
1011+
trace.state === 'interrupted' ? (
1012+
value ? (
1013+
<span style={{ marginLeft: 8, color: '#1976d2' }}>
1014+
{JSON.stringify(value)}
1015+
</span>
1016+
) : (
1017+
<span
1018+
style={{
1019+
marginLeft: 8,
1020+
color: 'red',
1021+
fontWeight: 500,
1022+
}}
1023+
>
1024+
missing
1025+
</span>
1026+
)
1027+
) : null}
1028+
</li>
1029+
)
1030+
})}
10171031
</ul>
10181032
</div>
10191033
<div style={styles.section}>
@@ -1024,17 +1038,11 @@ function TraceItem<
10241038
{name}
10251039
{trace.state === 'complete' || trace.state === 'interrupted'
10261040
? (() => {
1027-
const { computedValues } =
1028-
trace.traceContext && trace.finalTransition
1029-
? getComputedResults(
1030-
trace.traceContext,
1031-
trace.finalTransition,
1032-
)
1033-
: {}
1034-
if (computedValues?.[name] !== undefined) {
1041+
const value = computedResults.computedValues?.[name]
1042+
if (value !== undefined) {
10351043
return (
10361044
<span style={{ marginLeft: 8, color: '#1976d2' }}>
1037-
{String(computedValues[name])}
1045+
{String(value)}
10381046
</span>
10391047
)
10401048
}
@@ -1068,6 +1076,7 @@ function TraceItem<
10681076
...styles.expandArrow,
10691077
...(isExpanded ? styles.expandArrowUp : styles.expandArrowDown),
10701078
}}
1079+
onClick={onToggleExpand}
10711080
>
10721081
10731082
</div>

src/v3/debugUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export function isSuppressedError<RelationSchemasT>(
2424

2525
// Helper to format ms
2626
export function formatMs(ms?: number): string {
27-
if (ms == null) return ''
28-
if (ms < 1_000) return `${ms}ms`
27+
if (ms == null) return 'n/a'
28+
if (ms < 1_000) return `${ms.toFixed(0)}ms`
2929
return `${(ms / 1_000).toFixed(2)}s`
3030
}
3131

0 commit comments

Comments
 (0)