New:New releases:CLIcreate-clubedge-app v0.49.1·Clubedge Starter v0.32.0

Clubedge Starter Docs

Observability

Server and browser error reporting and request tracing, with OpenTelemetry or Sentry.

Choose with --observability otel, --observability sentry, or --observability none (default). On a React + Vite frontend with an API, the Hono and FastAPI APIs implement every option: see A frontend and its API.

Server errors and traces go to the tool you chose. Errors that escape a page, route, server action, or server function are sent with the request's method and path, and so are errors the app handles and reports with reportError from @clubedge/core, such as a failed webhook, email, or background job.

Every request is traced, and so are calls through the email, storage, and payments composition roots, as spans such as email.send and storage.upload. Wrap your own work with traced:

Any server code
import { traced } from "@clubedge/core";

await traced("name", () => work());

Until the tool is configured nothing is sent, and errors keep going to the server log.

Set OTEL_EXPORTER_OTLP_ENDPOINT to an OpenTelemetry collector or to a vendor's OTLP/HTTP endpoint (Grafana Cloud, Honeycomb, Datadog, and others accept it), with any API key in OTEL_EXPORTER_OTLP_HEADERS as key=value pairs. Traces go to /v1/traces and errors to /v1/logs as error log records, and each error is also recorded on the span it happened in. OTEL_SERVICE_NAME defaults to the project's service id. With Next.js, the spans Next.js and pg-boss create join the same traces.

To see traces during development, run Jaeger, set OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318, and open http://localhost:16686:

docker run --rm -p 16686:16686 -p 4318:4318 jaegertracing/jaeger:latest

Browser errors

Uncaught errors in the browser are reported too, with the page's path and no query string. With OpenTelemetry, the browser sends them to /api/client-errors, which reports them like server errors and accepts 30 reports a minute per address. With Sentry, Sentry's browser SDK sends them directly; it is downloaded only when SENTRY_DSN is set. In both cases the browser reads its settings from /api/client-errors at runtime, so builds never bake them in.

On Vercel and Netlify, a function can stop right after it responds, so spans still waiting in a batch at that moment can be lost.

A frontend and its API

With the Hono API (Starter v0.25.0 or newer) and the FastAPI API (Starter v0.26.0 or newer), the API reports its errors and traces its requests. Set the variables in apps/api/.env.local, and on the API's service in production. OTEL_SERVICE_NAME defaults to the API's service id. The API stops taking requests on SIGTERM and sends what is still buffered before it exits.

With FastAPI, every error the API logs at the ERROR level, such as with logger.exception(...), reaches the tool, with the extra it was logged with as its attributes. With Sentry, create a Python project instead of a Node.js one; its integrations trace what FastAPI, httpx, and Redis do in the same traces.

The React + Vite frontend reports browser errors as above: it reads its settings from the API's /api/client-errors at runtime, through the frontend, so SENTRY_DSN is set on the API only. The React + Vite build does not upload source maps to Sentry yet, so browser stack traces point into the minified bundle.

Another tool

Observability goes through the provider-neutral ObservabilityProvider interface in packages/observability and the telemetry hooks in @clubedge/core. To use another tool, implement that interface in a new package and install it from apps/web/src/server/observability.ts (apps/api/src/server/observability.ts with the Hono API); error reports and spans across the app stay the same.

With the FastAPI API, the Observability protocol is in apps/api/src/clubedge_api/telemetry.py, and tracing.py traces each request. Implement the protocol and start it from apps/api/src/clubedge_api/observability.py.

How is this guide?