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.

Embed
Preview of the card
<a href="https://lucidace.com/help/watchtower"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/ec4ac72f-2423-4a35-9f6b-cc0279d5c33d/social-card.svg?v=3e7ae33eec8b" alt="Errors, logs, traces, LLM observability and web vitals: Watchtower" width="600" height="315"></a>

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_vitals event 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 the watchtower option, globalThis.watchtower or the watchtower:ready event. Without hooks it records nothing extra. The connector resolves wt_event_id to 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.

  1. Link sessions with globals, not headers. Load both SDKs on the same pages. From browser 0.1.15 Lucida turns exposeGlobal on when it sees Watchtower, and Watchtower finds Lucida through window.lucida. Errors and traces then carry the Lucida session with no request headers and no CORS change.

  2. Turn on correlate only for your own APIs. It adds a baggage header 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 in watchtower.origins.

  3. Pick one recorder. Set replayOwner: "lucida" (Lucida's masking, heatmaps, funnels) or "watchtower" (console and network next to the replay). Avoid both unless 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:

  1. window.watchtower and window.lucida are both defined.

  2. lucida.getSessionId() returns an id; in Watchtower the same id is the lucida.session_id attribute on the session.

  3. With correlate: true, a same-origin fetch carries baggage: lucida.session_id=<id> (Network tab).

  4. 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.

Updated