Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

3.2 KB
Raw Blame

trace-graph-view

Read-only agent-graph renderer for the trace detail view: ELK computes the layout, we draw HTML nodes over an SVG edge layer, d3-zoom owns the viewport. Deliberately NOT React Flow / vis-network β€” the view is read-only and the custom renderer keeps it virtualization-ready.

Data flow (one way)

agentGraphData (tRPC getAgentGraphData)
  β†’ buildStepData            timing-based step inference (cycle-guarded)
    / transformLanggraphToGeneralized   when langgraph metadata exists
  β†’ one builder per GraphViewMode (the mode switch overlaid on the canvas):
      buildGraphCanvasData   "aggregated": repeats collapse by name (+ cycling
                             map); langgraph traces show framework nodes only
      buildExpandedGraph     "expanded": one node per observation (EVERY call,
                             minus EVENTs β€” framework metadata is ignored);
                             edges from the instrumented hierarchy +
                             happened-before sibling ordering (fork/join)
  β†’ layout/graphLayoutWorkerClient.requestGraphLayout
      layout/elkLayout       prepare (dedupe, size, count ceiling) on the main
                             thread β†’ run ELK in workers/elk-layout.worker.ts
      layout/measureNode     estimates node boxes (labels, counter reserve)
  β†’ components/ElkGraphRenderer           draws + gestures
      components/GraphNode                view-only node (memo)

Both builders return the same {graph, nodeToObservationsMap} pair β€” everything downstream is mode-agnostic. The selected mode is a trace view preference (ViewPreferencesContext.graphViewMode, localStorage), passed in as a prop.

Ownership

  • Viewport: deterministic and data-derived β€” the rendered transform is always userOverride ?? fit(layout, size). The user's last gesture (drag/wheel/pinch/toolbar zoom) is the ONLY viewport state; without one, fit re-applies on every layout/size change. Selection never moves the viewport (it's a ring/glow β€” under fit the node is always visible); Fit and a graph change clear the override. Per-frame pan/zoom writes the world div's CSS transform (and the edge stroke-compensation var) imperatively β€” React state holds only the discrete derivations (compact label threshold, fitted reveal, layout/error).
  • Selection: the ?observation= URL param, wired in components/TraceGraphView.tsx (click-cycling through a node's observations, URLβ†’node sync with a parent-walk fallback for descendants without their own graph node).
  • Pure layout math: layout/* has no React imports and is unit-tested (layout/*.clienttest.ts). elkLayout.ts stays free of worker plumbing so it runs unchanged on either thread; graphLayoutWorkerClient.ts owns the worker singleton, request ids, cancellation and the wall-clock deadline.
  • Layout thread: ELK runs in web/src/workers/elk-layout.worker.ts, so a slow layout never blocks the trace view. ELK is uninterruptible even there β€” cancelling a stale layout means terminating the worker.

Next migration slices

  • Node virtualization for very large graphs (only render nodes intersecting the viewport β€” the renderer's world/viewport split is already shaped for it).