log2trace-ui Guide
API Docs GitHub
Programmatic API

Events, Programmatic API & States

Drive <trace-visualizer> imperatively from JavaScript or TypeScript: load remote endpoints, select and reveal spans across collapsed subtrees, scope views to a shared { t0, t1 } time window, and subscribe to bubbling, composed CustomEvents.

1Interactive API & Event Workbench

Use the imperative controls below to invoke public methods on the element, then interact directly with the timeline, tabs, or filter bar to compare user-originated events against programmatic calls. Note that selectSpan() expands ancestors and reveals the span without re-emitting span-selected, preventing listener feedback loops.

Load Data:
Subtrees:
setTimeWindow
const viz = document.querySelector('#viz-api');

// Imperative async loading
await viz.loadTraceData('./data/ai-search-trace.json');
await viz.loadAndTransform('./data/fintech-logs.json', FINTECH_LOG_CONFIG);

// Expand ancestors, select a span, and scroll it into view
viz.selectSpan('rag-llm-fail-s', { reveal: true });
console.log('Selected IDs:', viz.selection);

// Scope all views (Waterfall, Flame, Service, Sequence) to [t0, t1] ms from trace origin
viz.setTimeWindow({ t0: 150, t1: 850 });
viz.setTimeWindow(null); // reset to full trace

// Subscribe to bubbling, composed CustomEvents
viz.addEventListener('trace-loaded', (e) => console.log(e.detail)); // { spans, roots, traceId }
viz.addEventListener('span-selected', (e) => console.log(e.detail)); // { span, spanId, spanIds, view }
viz.addEventListener('filter-changed', (e) => console.log(e.detail)); // { field, source, value, allFilters }
viz.addEventListener('view-changed', (e) => console.log(e.detail)); // { view, previous }

2Built-in Status, Empty & Error States

<trace-visualizer> renders accessible status overlays inside its Shadow DOM for every lifecycle phase — requiring no external wrapper UI when data is empty, awaiting required external filters, loading asynchronously, filtered down to zero matches, or failing to fetch.

Trigger State:
Fresh element with zero spans
How This State Occurs

3Properties & Methods Reference

MemberSignatureDescription
traceData set traceData(data: TraceData) Indexes and renders a standard OTLP TraceData object synchronously, then emits trace-loaded.
logData set logData(input: { logs: LogEntry[]; config: TransformConfig }) Runs transformLogs(logs, config), indexes the resulting spans, and emits trace-loaded.
config get / set config: TraceVisualizerConfig Merges programmatic config fields on top of HTML attributes (setting a key to undefined falls back to its attribute).
fetchCallback get / set fetchCallback: FetchCallback | null Custom async loader (url, filters) => Promise<TraceData | LogEntry[]> for external filters.
view get / set view: string Reads or switches the active view tab ID (waterfall, flame, service, sequence, stats, lanes, or custom ID).
selection get selection: readonly SpanId[] Currently selected span IDs in the shared store.
selectSpan() selectSpan(id: SpanId, options?: { reveal?: boolean }): void Expands collapsed ancestors, selects the span, and reveals it in the active view (default reveal: true).
expandAll() / collapseAll() (): void Expands every span or collapses every parent span that has children.
setTimeWindow() setTimeWindow(window: { t0: number; t1: number } | null): void Scopes all views to [t0, t1] milliseconds from trace origin, or clears the window with null.
loadTraceData() loadTraceData(url: string): Promise<void> Fetches OTel JSON from url; network/parse errors render in the status overlay without rejecting.
loadAndTransform() loadAndTransform(url: string, config: TransformConfig): Promise<void> Fetches raw JSON logs from url, transforms them with config, and renders the result.
refreshTheme() refreshTheme(): void Re-reads computed --l2t-* CSS custom properties after script-driven style changes.

4Custom DOM Events Reference

All events bubble and are composed: true, so they cross Shadow DOM boundaries cleanly.

Event Nameevent.detail ShapeWhen Dispatched
trace-loaded { spans: number; roots: number; traceId: string } After data is indexed via data-url, traceData, logData, loadTraceData(), or loadAndTransform().
span-selected { span: Span; spanId: string; spanIds: string[]; view: string } When the user selects a span, flame box, service node/edge, sequence arrow, lanes bar or merged run, or stats row (not emitted by programmatic selectSpan()).
filter-changed { field: string; source: FilterSource; value: FilterValue; allFilters: Record<string, FilterValue> } Whenever a filter input changes in the filter bar (after debounce for text inputs).
view-changed { view: string; previous: string } When switching from one mounted view to another via tabs, the view attribute, or the .view setter.