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:
sessionId, the link, which ties every step of one user on one screen together;conversationIdandsurface;keyon steps that belong to one action, the same for every retry of it.
| Step | When | Adds |
|---|---|---|
link.created | The agent opened the screen | |
event.received | The screen sent an event (lifecycle or yours) | type, key |
handler.finished | Your handler returned or threw | ms, outcome: ok, unchanged or failed |
event.recorded | The event is stored, and the agent will read it | eventId, wake |
event.repeat | A retry of an action that already ran: answered from the first try, nothing ran | eventId |
event.failed | The request failed | kind, code, reason |
kind says which failure it was:
kind | Meaning |
|---|---|
validation | The body didn't match the contract |
refused | A business refusal, with your reason |
upstream | A system your handler calls |
infrastructure | Your store or server |
in_progress | A retry while the first try still runs |
link | Expired, 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:
| Span | From | Carries |
|---|---|---|
ui-calling link <surface> | link.created | |
ui-calling event <type> | event.received to event.recorded, .repeat or .failed | ui_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 event | ui_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 6d0def5fThe 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
- Don't log payloads next to traces. If you need what the user chose, read the event the agent read:
ui.events(conversationId), byeventId. - Sample in production if you need to. There's one step per event and a few per action, so most apps can keep them all.
In the ui-calling repo
Not in the package; for reading if you have the repo.
- Server:
onTraceinui.ts - Proof: "trace: every step of one action shares the session and key" in
test-runtime.ts - OpenTelemetry:
otel.tssets up the exporter and each agent turn's span; proof intest-otel.ts