Errors, logs, traces, LLM observability and web vitals: Watchtower
Watchtower, Lucida's sister observability product, owns errors, logs, traces, infrastructure, LLM observability and web vitals. How Lucida links to it, as far as the code goes.
Lucida answers "what are people doing, and does a change make them succeed?". Watchtower answers "is the software working?", and owns:
error tracking, stack traces and source maps
logs and log search
traces, APM and service maps
infrastructure, uptime and synthetics
web vitals and performance monitoring
LLM observability (tokens, latency and traces of LLM calls)
incidents and on-call
Lucida does not build these. It connects to Watchtower instead (the watchtower connector; Datadog, Sentry, New Relic and Grafana Faro use the same pattern).
What the connector does
Errors per session. Watchtower sessions with errors become error markers on the replay timeline. Each marker links to
/replays/{session}in Watchtower. Replays can be filtered by "has Watchtower error".Web vitals per session. LCP, INP and CLS arrive as read-only session metrics, so you can segment by them ("users with slow LCP convert less"). They are not charted as monitoring.
Errors and Web Vitals as events (browser 0.1.7). When the Watchtower browser client on the page has event hooks (
on("error"),on("vital")), Lucida records$exception_seen(wt_event_id,wt_trace_id,message,handled) for each error and one$web_vitalsevent per page view (lcp_ms,inp_ms,cls,fcp_ms,ttfb_ms,rating_worst), after analytics consent only. Use them in funnels and breakdowns ("users with a poor LCP"). Lucida finds the client from thewatchtoweroption,globalThis.watchtoweror thewatchtower:readyevent. Without hooks it records nothing extra. The connector resolveswt_event_idto the Watchtower issue, so the replay lists the issues its visitor hit.Deploys. Watchtower change candidates become deploy and flag markers that annotate Lucida charts.
Flag and experiment changes out. Lucida POSTs them to a Watchtower change source, so a regression can be tied to a flag flip.
Agent conversations. An agent-analytics transcript with a Watchtower trace shows "Open trace in Watchtower".
The connector is read-only on Watchtower's side and uses a read-only token.
Recommended setup
Link sessions with globals, not headers. Load both SDKs on the same pages. From browser 0.1.15 Lucida turns
exposeGlobalon when it sees Watchtower, and Watchtower finds Lucida throughwindow.lucida. Errors and traces then carry the Lucida session with no request headers and no CORS change.Turn on
correlateonly for your own APIs. It adds abaggageheader to fetch and XHR. Same-origin requests are fine. For a cross-origin API, that API must allow the header first (Access-Control-Allow-Headers: baggage), or the browser blocks the request. List only those origins inwatchtower.origins.Pick one recorder. Set
replayOwner: "lucida"(Lucida's masking, heatmaps, funnels) or"watchtower"(console and network next to the replay). Avoidbothunless you need both: two recorders double the page cost.
Linking the two
Both products share lucida.session_id. In the browser SDK:
init("lc_pk_...", { watchtower: { correlate: true, origins: [/api\.example\.com/] } });With correlate on, the SDK writes lucida.session_id into W3C baggage on fetch and XHR requests (to same-origin and the listed origins), so Watchtower can attach its errors and traces to the Lucida session.
One recorder per page. replayOwner is lucida, watchtower or both; unset, Lucida records unless a Watchtower SDK on the page already announces that it is recording, in which case Lucida yields and logs a console warning; set lucida or both to record regardless. Lucida's player never shows console or network panels: use Watchtower for those.
Lucida's own services can export traces to Watchtower over OTLP when OTEL_EXPORTER_OTLP_ENDPOINT is set (self-hosters).
Lucida with Watchtower in Next.js
When both SDKs come from npm they are bundled, so neither is a global the other can find. Expose both. Minimum versions: Lucida browser (@lucida-analytics/browser) 0.1.7 and @watchtowerobservability/browser 0.5.0.
Watchtower first (a client component mounted once, in the root layout; check the option names against the Watchtower browser docs):
"use client";
import { init } from "@watchtowerobservability/browser";
import { useEffect } from "react";
export function WatchtowerInit() {
useEffect(() => {
init({
publishableKey: process.env.NEXT_PUBLIC_WATCHTOWER_KEY!,
endpoint: process.env.NEXT_PUBLIC_WATCHTOWER_ENDPOINT!,
service: "web",
exposeGlobal: true, // sets globalThis.watchtower and fires "watchtower:ready"
});
}, []);
return null;
}Lucida (LucidaNextProvider already defaults to exposeGlobal: true; keep it explicit):
<LucidaNextProvider apiKey={process.env.NEXT_PUBLIC_LUCIDA_KEY!} options={{ exposeGlobal: true, watchtower: { correlate: true } }}>
<WatchtowerInit />
{children}
</LucidaNextProvider>Either start order works: Lucida looks for globalThis.watchtower now and again on watchtower:ready. The link is only made once the visitor has granted analytics consent.
To confirm the link, in the browser console:
window.watchtowerandwindow.lucidaare both defined.lucida.getSessionId()returns an id; in Watchtower the same id is thelucida.session_idattribute on the session.With
correlate: true, a same-originfetchcarriesbaggage: lucida.session_id=<id>(Network tab).A thrown error shows up in Lucida as
$exception_seen, and each page view as$web_vitals.
If window.watchtower is undefined, Lucida cannot tell that a Watchtower client exists on the page and links nothing. Set exposeGlobal: true on the Watchtower side, or pass the client explicitly with watchtower: { client }.
The reverse case: Watchtower finds Lucida only through window.lucida. From browser 0.1.15, Lucida turns exposeGlobal on by itself when it sees a Watchtower browser SDK, either globalThis.watchtower at init or a later watchtower:ready event. You do not need to set it. An explicit exposeGlobal: false still opts out, and then Watchtower cannot find Lucida. With an older browser SDK, set exposeGlobal: true yourself.