Skip to content

feat: trace requests across the frontend and backend - #150

Merged
lewisjared merged 5 commits into
mainfrom
observability
Oct 24, 2026
Merged

lewisjared merged 5 commits into
mainfrom
observability

Conversation

@lewisjared

@lewisjared lewisjared commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Adds request tracing across the frontend and backend, and moves the backend's metrics onto the shared cr-service package.

  • FastAPI goes to 0.162, which traces each request natively once a tracer provider is installed. cr-service installs one only when OTEL_EXPORTER_OTLP_ENDPOINT is set, so local runs stay quiet, and adds a span per SQLAlchemy statement.
  • The frontend turns on Sentry browser tracing for page loads, route changes and API calls. API calls to the same origin or a *.climate-ref.org/api host carry traceparent, so the backend's spans join the browser trace.
  • /metrics now comes from cr-service, with ungrouped status codes and the shared latency buckets, so the shared Grafana Application dashboard reads it.
  • Adds /livez and /readyz. They stay out of metrics and traces, but /api/v1/utils/health-check/ no longer does, so the deployment probes should move to the new paths once this ships.
  • Outside ENVIRONMENT=local the API logs one compact JSON object per line, in the cr-service shape (ts, level, logger, message), with trace_id and span_id inside a traced request. Grafana links a Loki line to its Tempo trace and back through that field. Local runs keep loguru's text output. The stdlib intercept now reports the real caller, where it used to report logging.
  • Sentry now reports the environment and samples by SENTRY_TRACES_SAMPLE_RATE, which defaults to 1.0 like the old enable_tracing=True.

The browser traces 10% of page loads by default, set at build time by VITE_SENTRY_TRACES_SAMPLE_RATE (also a Docker build arg), so one image carries one rate. The backend follows the browser's decision, so this rate also sets how many API spans from the dashboard reach Sentry and Tempo. Requests without a browser trace use SENTRY_TRACES_SAMPLE_RATE for Sentry and are always kept in Tempo. Cross-origin API calls now send a CORS preflight because of the tracing headers. tests/test_tracing.py checks that an incoming traceparent becomes the request span's trace id.

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bb30a4c5-d10b-48c4-b12d-29b6ea1b6b3c
Commits

Reviewing files that changed from the base of the PR and between f7eb639 and ef5d74c.

Files ignored due to path filters: 1
  • backend/uv.lock is excluded by !**/*.lock
Files selected for processing: 14
  • Dockerfile
  • backend/pyproject.toml
  • backend/src/ref_backend/builder.py
  • backend/src/ref_backend/caching.py
  • backend/src/ref_backend/core/config.py
  • backend/src/ref_backend/metrics.py
  • backend/tests/test_api/test_metrics.py
  • backend/tests/test_builder.py
  • backend/tests/test_caching.py
  • backend/tests/test_tracing.py
  • changelog/150.improvement.md
  • frontend/src/instrument.ts
  • frontend/src/main.tsx
  • frontend/src/vite-env.d.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

lewisjared added a commit that referenced this pull request Oct 24, 2026
Bumps FastAPI to 0.162, which traces each request once a tracer provider is installed.
This takes metrics, tracing and the /livez and /readyz probes from cr-service.
API calls carry traceparent, so backend spans join the browser trace.
@lewisjared
lewisjared marked this pull request as ready for review October 24, 2026 00:29
VITE_SENTRY_TRACES_SAMPLE_RATE defaults to 0.1, because the dashboard serves around 500k API requests a month.
@lewisjared
lewisjared merged commit d46c855 into main Oct 24, 2026
6 checks passed
@lewisjared
lewisjared deleted the observability branch October 24, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant