---
title: "Observability"
description: "Logs, request ids, traces and errors, and what never gets logged."
url: https://pr-470-docs.preview-ritorno.findmalek.engineer/docs/observability
markdown: https://pr-470-docs.preview-ritorno.findmalek.engineer/docs/observability.md
---

# Observability

## Logs

The api and the Next servers log json lines through `@ritorno/logger` (one readable line in dev). `console.*` calls are routed through the same logger.

Before a line is written, every field passes the redaction:

- keys that look like a secret (`password`, `token`, `authorization`, `cookie`, `api key`, `session`, `dsn`) are replaced with `[redacted]`
- keys that look like guest data (`phone`, `mobile`, `whatsapp`, `email`, `name`, `firstName`, `fullName`, ...) are replaced with `[redacted]`
- email addresses and phone numbers (international `+216 20 123 456` or `00216...`, and Tunisian local `20 123 456`, `20.123.456`, `20123456`) inside any string, including error messages and stacks, are masked
- a database query error is logged as its class and Postgres code only (`{ name: "DrizzleQueryError", code: "23505" }`), since its message and `params` hold the row being written

Log the guest id and the hotel id, never the guest. If a new field carries personal data under another key name, add it to `PII_KEY` in `packages/logger/src/redact.ts` and a case to its test.

## Request ids

The api gives every request an id, the inbound `x-request-id` when it is short and plain, a new uuid otherwise. Every log line written while the request runs carries it as `requestId`, and the response returns it in the `x-request-id` header. A guest or hotel reporting a problem can send that header value to find the whole request.

## Traces and logs: OpenObserve

Set these in `.env` (all optional, empty means off):

| Key | What it is |
| --- | --- |
| `OPENOBSERVE_URL` | base url of your OpenObserve. On The Keep the stacks share the docker network, so `http://openobserve:5080` works without a public host |
| `OPENOBSERVE_ORG` | organization, `default` unless you changed it |
| `OPENOBSERVE_USER`, `OPENOBSERVE_PASSWORD` | the ingest user |

The api and the worker both send their traces (one span per request) and their json log lines, in batches every 2 seconds, to OpenObserve. The `default` stream holds both services, told apart by the `service` and `env` fields (`staging`, `production`), and a preview writes to a stream named after itself (`pr-123`). Log lines carry `requestId`, `trace_id` and `span_id`, so a log line links to its trace and back. Pretty dev lines are never sent.

## Errors: GlitchTip

| Key | What it is |
| --- | --- |
| `GLITCHTIP_DSN` | dsn of the api project, from the GlitchTip project settings |
| `NEXT_PUBLIC_GLITCHTIP_DSN` | dsn of the browser project, used by web and dashboard |
| `NEXT_PUBLIC_DEPLOY_ENV` | environment tag of web and dashboard errors, set from `DEPLOY_ENV` by `docker-compose.deploy.yml` (a build arg, it is inlined into the browser bundle) |

GlitchTip speaks the sentry protocol, so the sentry sdk is used as is. Errors are tagged with `DEPLOY_ENV`, so staging and previews stay apart from production. Web and dashboard run the same `scrubEvent` as the api (`@ritorno/logger/scrub`) before anything leaves, in the browser and on the Next server. See [The Keep](https://pr-470-docs.preview-ritorno.findmalek.engineer/docs/infrastructure/the-keep.md) for where both run.

On the public site (`apps/web/instrumentation-client.ts`) the browser sdk is about 150 KB gzipped, so it is imported only when `NEXT_PUBLIC_GLITCHTIP_DSN` is set and only once the page is idle. Errors thrown before that are not reported.

The api and the worker both init sentry with a `beforeSend` (`apps/api/src/sentry.ts`) that drops the `params:` part of query errors, masks phone and email shaped text, redacts `extra` and breadcrumb data and drops request bodies, headers and cookies.

## Failed jobs

A job that throws is logged as `job failed` with its name and id, and sent to GlitchTip as `job <name> failed` tagged `job` and `jobId`, never with its payload or the raw error. pg-boss then retries it under the job's retry policy. To see what went wrong, look the job up by id in the `pgboss` schema.

## Check it works

Do it on staging first, then once on production after the keys are set. Never paste a key into a ticket, a log or a chat: set them with Infisical (`infisical secrets set NAME=... --env=staging`, same flags as in [deploy](https://pr-470-docs.preview-ritorno.findmalek.engineer/docs/deploy.md)) and redeploy, because web and dashboard inline the `NEXT_PUBLIC_*` keys at build time.

**1. Keys.** Per environment (`staging`, `prod`) these names must exist in Infisical: `GLITCHTIP_DSN`, `NEXT_PUBLIC_GLITCHTIP_DSN`, `OPENOBSERVE_URL`, `OPENOBSERVE_ORG`, `OPENOBSERVE_USER`, `OPENOBSERVE_PASSWORD`, `NEXT_PUBLIC_UMAMI_URL`, `NEXT_PUBLIC_UMAMI_WEBSITE_ID`. List names only: `infisical export ... | sed 's/=.*//' | grep -iE 'glitch|umami|openobserve'`. In GlitchTip create two projects once (api and worker, browser), in Umami one website per environment (a staging hit must never land in the production website), in OpenObserve one ingest user.

**2. Errors.** On the api container run `docker exec <api> bun -e 'import * as S from "@sentry/bun"; import { sentryOptions } from "@ritorno/logger/scrub"; S.init(sentryOptions(process.env.GLITCHTIP_DSN, process.env.DEPLOY_ENV)); S.captureException(new Error("observability check api")); await S.flush(2000)'` and the same inside the worker container with `worker` in the message. For web and dashboard open the site, then in the browser console run `setTimeout(() => { throw new Error("observability check web") })` (`dashboard` on the dashboard). In GlitchTip each event must show up under the right project with the environment `staging`. A deliberate failing job also shows as `job <name> failed`.

**3. Logs and traces.** Make a request, `curl -si https://api-staging-ritorno.findmalek.engineer/health`, and read the `x-request-id` header. In OpenObserve, logs, stream `default`, search `requestId='<that id>'`: a `request` line with `service='api'` and `env='staging'` comes up, and its `trace_id` finds the span in traces. The worker writes `worker running (staging)` with `service='worker'` at boot.

**4. Analytics.** Open the landing page in a private window: no request to the Umami host before you accept the banner, one `script.js` and one `send` after. Then open `/en/privacy`, the dashboard, a guest page and the docs: only the landing pages (`/`, `/privacy`, `/terms`, `/status`) may show a hit in the Umami website, and the dashboard, guest pages and docs must not. Declining sends nothing.

**5. Uptime and alerts.** Uptime Kuma (see [The Keep](https://pr-470-docs.preview-ritorno.findmalek.engineer/docs/infrastructure/the-keep.md)) has one http monitor per public host of each environment: web, dashboard, docs, and the api on `/health`. Alerts: a Kuma notification to Malek on any monitor down, and a GlitchTip alert on the api and worker project (environment `production`, more than a few events in five minutes, and any `job ... failed` event) sent to Malek by email. Failed jobs reach GlitchTip as events, so the same alert covers the api 5xx rate and failed jobs.
