fix: complete traces on idle, improve dashboard span/event/analytics views
This commit is contained in:
@@ -49,6 +49,8 @@ interface Trace {
|
||||
tags: string[];
|
||||
metadata: Record<string, unknown>;
|
||||
costUsd: number | null;
|
||||
totalTokens: number | null;
|
||||
totalCost: number | null;
|
||||
}
|
||||
|
||||
interface TraceAnalyticsProps {
|
||||
@@ -112,9 +114,15 @@ function ExecutionTimeline({ trace, spans }: { trace: Trace; spans: Span[] }) {
|
||||
}
|
||||
|
||||
const traceStartTime = new Date(trace.startedAt).getTime();
|
||||
const lastSpanEnd = spans.reduce((max, s) => {
|
||||
const end = s.endedAt ? new Date(s.endedAt).getTime() : 0;
|
||||
return end > max ? end : max;
|
||||
}, 0);
|
||||
const traceEndTime = trace.endedAt
|
||||
? new Date(trace.endedAt).getTime()
|
||||
: Date.now();
|
||||
: trace.status === "COMPLETED" || trace.status === "ERROR"
|
||||
? lastSpanEnd || traceStartTime
|
||||
: Date.now();
|
||||
const totalDuration = traceEndTime - traceStartTime;
|
||||
|
||||
// Build span hierarchy for nesting
|
||||
@@ -310,7 +318,7 @@ function CostBreakdown({
|
||||
(sum, d) => sum + (d.cost || 0),
|
||||
0
|
||||
);
|
||||
const totalCostValue = trace.costUsd ?? totalSpanCost + totalDecisionCost;
|
||||
const totalCostValue = trace.costUsd ?? trace.totalCost ?? totalSpanCost + totalDecisionCost;
|
||||
const hasData =
|
||||
totalCostValue > 0 || spanCostsData.length > 0 || decisionCostsData.length > 0;
|
||||
|
||||
@@ -462,6 +470,7 @@ function CostBreakdown({
|
||||
function TokenUsageGauge({ trace }: { trace: Trace }) {
|
||||
const tokenData = useMemo(() => {
|
||||
const totalTokens =
|
||||
trace.totalTokens ??
|
||||
(trace.metadata?.totalTokens as number | null | undefined) ??
|
||||
(trace.metadata?.tokenCount as number | null | undefined) ??
|
||||
null;
|
||||
|
||||
Reference in New Issue
Block a user