Menu ▾ ▴

#227 feat: report server and web UI errors to Sentry

open
nobody
None
9 hours ago
14 hours ago
Anonymous
No

Originally created by: thomijasir

Summary

Until now, when a self-hosted install hit an error, we only heard about it if someone opened an issue. This sends server and web UI errors, traces and logs to Dopbase's Sentry projects (dopbase/server and dopbase/frontend). Only binaries built by the release workflow on dophq/dopbase know the projects, and so does the Docker image, which wraps that binary. They report by default, and DOPBASE_ERROR_REPORTING=false turns it off. Forks and builds from source never report.

dopbase server start
  init Sentry before the Tokio runtime     # only if the DSNs were compiled in
  router
    transaction middleware                 # names spans "GET /api/v1/…" by route
    security headers                       # CSP adds the UI DSN's ingest origin when on
  GET /api/v1/bootstrap/status
    errorReporting: { dsn, release, … }    # the web UI starts @sentry/vue from this

Dopbase stores secrets, so most of this change is about what stays out:

  • Server: transactions carry the method and route only. sentry-tower's layer was dropped because it records full URLs (which can hold a setup token or SSO code) and headers. server_name is a fixed dopbase, not the machine's hostname.
  • Web UI: no Session Replay and no component props (the Vue SDK attaches them by default, and ours can hold secret values). No request bodies, headers, cookies or user details either. Every URL in events, breadcrumbs, spans and debug images is cut down to its route:
  • https://vault.acme.com/projects/payments/prod/secrets?tab=raw becomes /projects/:projectRef/:environmentName/secrets
  • /api/v1/environments/env_1/secrets/DB_URL becomes /api/v1/environments/*
  • Sentry projects: IP storage is off, and a data-scrubbing rule removes location (user.geo, on events and spans) and the browser time zone.
  • Source maps: the release workflow uploads hidden UI source maps when the SENTRY_AUTH_TOKEN secret is set. They never land in ui/dist, so the server doesn't embed or serve them.

The DSNs come from DOPBASE_SENTRY_SERVER_DSN and DOPBASE_SENTRY_UI_DSN at compile time. release.yml sets them on the binary build step only when github.repository is dophq/dopbase, so a fork running the workflow builds them empty, and an empty DSN counts as none. Without both, setting the switch to true does nothing.

The startup banner gains a Reporting: row, so operators see it from the server itself:

Reporting:  errors and traces go to Dopbase (DOPBASE_ERROR_REPORTING=false turns this off)

A build without the projects shows Reporting: off. Only server setup and server start report. Client commands like dopbase run never do, and the e2e harness sets the switch to false for every process it starts.

Compatibility

No breaking changes and no migration. Existing installs that run the release binaries or the Docker image start reporting after they upgrade, unless they set DOPBASE_ERROR_REPORTING=false. Installs built from source don't change. That is the part to weigh before merging. Turning it off later is easy, but anything already sent stays in Sentry, so reviewing the privacy rules above is the step that can't be redone.

  • The switch is an environment variable only; server.toml has no key for it. An invalid value stops startup, the same way the other boolean switches do.
  • With reporting on, the CSP's connect-src also allows the UI DSN's ingest origin, https://o4512546289876992.ingest.de.sentry.io. With it off, or if the DSN doesn't parse, the CSP is unchanged.
  • /api/v1/bootstrap/status gains an optional errorReporting object, present only while reporting is on.
  • Volume: every install sends INFO and higher logs, plus 10% of traces. Keep an eye on the Sentry quota as installs grow.
  • The release binary stays stripped, so Rust stack traces are not symbolicated. Server errors still carry their message and route.

Verification

  • cargo test --all-targets --all-features: all suites pass (326, 411, 118, 67, 42 and the smaller ones)
  • cargo clippy --all-targets --all-features -- -D warnings and cargo fmt --check: clean
  • bun run --cwd ui test: 3312 passed. UI typecheck and lint are clean.
  • bun run test:e2e --skip-build --agent on the release binary: 96 CLI (1 skipped), 101 API, 53 UI, 10 journeys, coverage ok
  • bun run test:docs, bun test scripts, the e2e and scripts typechecks, and prettier: clean
  • Every new test was broken on purpose (the change it covers undone) and failed as expected:
  • the 6 config, CSP and bootstrap Rust tests
  • for the build-time DSNs: false ignored, default flipped to off, a non-bool accepted, a project built in by fallback, the ingest origin dropped from the CSP, an unparseable DSN opening the CSP, the server DSN sent to the UI, and the banner rows swapped
  • the 10 UI scrubber tests, plus the debug_meta case
  • Live runs of the release binary against the real Sentry projects:
  • Reporting on (default): UI and server errors arrive tagged production. A page URL holding a project name, env ID, secret key and email arrived as route patterns only, with no host, port, query, props, IP, location or time zone. Server spans and logs arrive with server_name: dopbase and no URLs or headers.
  • Reporting off: the CSP is unchanged, the bootstrap status has no errorReporting, no Sentry client loads in the browser, and the server opens no outgoing connections.
  • Build-time DSNs: a release binary built with both DSNs printed the Reporting: row, allowed the ingest origin in the CSP and gave the UI its DSN. With DOPBASE_ERROR_REPORTING=false it showed Reporting: off and the plain CSP. A build without the DSNs and the switch set to true also stayed off.
  • Source maps: a build with the token uploaded 174 files, and ui/dist holds no .map files. An error thrown in the app showed original files and lines in Sentry, for example runtime-core.esm-bundler.js:4419.

Demo

Not needed: nothing in the app looks or behaves differently. The change is what reaches Sentry, and the Verification section lists the events that arrived and what they did and did not contain.

Checklist

  • [x] I kept this pull request focused on one problem.
  • [x] I added or updated tests for behavior changes, or explained why tests are not needed.
  • [x] I updated the documentation in /docs and CHANGELOG.md when public behavior changed, or explained why they are not needed.
  • [x] I added a screenshot or video demo for a feature or improvement, or explained why one is not needed.

Discussion


Log in to post a comment.