ui-calling

Follow one interaction end to end

Use it when a user says "I tapped it and nothing happened", or when you want to know where a screen loses people. The idea is to follow one link from the moment the agent opened it, through each tap, to what reached the agent. You don't need a monitoring platform for this: onTrace hands each step to your logger, and the IDs tie the steps together.

Full example: the demo prints every step with UI_CALLING_TRACE=1 npm run dev.

Server

createUiCalling({
  // ...
  onTrace: (t) => logger.info({ msg: `ui-calling ${t.step}`, ...t }),
});

Each step carries:

StepWhenAdds
link.createdThe agent opened the screen
event.receivedThe screen sent an event (lifecycle or yours)type, key
handler.finishedYour handler returned or threwms, outcome: ok, unchanged or failed
event.recordedThe event is stored, and the agent will read iteventId, wake
event.repeatA retry of an action that already ran: answered from the first try, nothing raneventId
event.failedThe request failedkind, code, reason

kind says which failure it was:

kindMeaning
validationThe body didn't match the contract
refusedA business refusal, with your reason
upstreamA system your handler calls
infrastructureYour store or server
in_progressA retry while the first try still runs
linkExpired, completed, another device, not verified

Alert on upstream and infrastructure. A refused is the screen working, and validation usually means the screen and the contract are out of step.

Traces carry IDs and types, never payloads, so they hold nothing the user typed. A hook that throws or is slow never fails the user's action.

In OpenTelemetry

If your agent already sends its turns to OpenTelemetry (Langfuse, Logfire, Sentry, Jaeger or any OTLP backend), put the screen in the same trace instead of in your logs:

import { context } from "@opentelemetry/api";
import { otelTrace, wokenContext } from "@ui-calling/otel";

createUiCalling({ /* ... */ ...otelTrace() });

// The turn a screen event wakes: run it in the link's trace.
ui.onEvent((e) => e.wake && context.with(wokenContext(e), () => runTurn(e)));

It needs what any standard OpenTelemetry setup already has: a registered tracer provider with a context manager (NodeSDK registers both), and the tool call running inside the agent turn's span (agent SDKs that emit OpenTelemetry do that; otherwise wrap the turn in tracer.startActiveSpan). otelTrace() sets onTrace and traceContext. The tool call saves the turn's traceparent on the link, so when the user opens it minutes later, on any instance, the steps become spans under that turn:

SpanFromCarries
ui-calling link <surface>link.created
ui-calling event <type>event.received to event.recorded, .repeat or .failedui_calling.event.key, .event.id, ui_calling.wake (and a ui_calling.wake span event), ui_calling.repeat; on failure error status and ui_calling.failure.kind, .code, .reason
ui-calling handler <type>handler.finished, as a child of its eventui_calling.handler.ms, .outcome; error status when it threw

Every span has ui_calling.surface, ui_calling.session_id and ui_calling.conversation_id. An event span also links to the HTTP request it arrived in, when that request has a span of its own. Without an agent span active when the link is created, each step is a root span of its own.

To see it locally, run Jaeger (its OTLP endpoint is :4318) and start the demo with OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 npm run dev. Open http://localhost:16686, service ui-calling-demo.

Reading one

A booking where the first response was lost on the way back to the phone:

[trace] wL3k9a link.created
[trace] wL3k9a event.received opened
[trace] wL3k9a event.recorded opened
[trace] wL3k9a event.received shift_selected key 6d0def5f
[trace] wL3k9a handler.finished shift_selected key 6d0def5f 41ms ok
[trace] wL3k9a event.recorded shift_selected wake
[trace] wL3k9a event.received shift_selected key 6d0def5f
[trace] wL3k9a event.repeat shift_selected key 6d0def5f

The same key arriving twice is a retry, and event.repeat shows it ran once. Two different keys with the same type are two taps. If you see handler.finished … ok with no event.recorded after it, the store failed after your handler ran. The screen was told it failed, and a retry after eventKeyStaleMs runs the handler again with the same key.

Watch out

In the ui-calling repo

Not in the package; for reading if you have the repo.

Source: packages/cli/recipes/trace-an-interaction.md