Repository navigation
feat(backend): log one wide event per request with the trace id - #153
Conversation
Grafana links a Loki line to its Tempo trace by matching "trace_id" in a JSON body.
Uses the cr-service WideEventMiddleware, with the route template and query statistics bound onto it. This replaces the uvicorn access line and the per-request statistics dump, and applies LOG_LEVEL to loguru.
|
Warning Review limit reachedYou'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 51 minutes. View limit details
Walkthrough
Priority: Change: Feature Merge Risk:
|
* origin/main: (29 commits) chore(deps): update astral-sh/setup-uv action to v10.3.1 fix: leave groups with a retracted latest execution out of the model pages fix: enable an execution's value tabs from its own values fix: keep obs-only groups in every era-scoped count docs: drop 'all' from the execution values value_type docs: add changelog for #147 perf: fetch metric value facets apart from the values perf: count diagnostic groups without counting their executions refactor(api)!: build on climate-ref's query package with explicit filters refactor(api)!: remove the /diagnostics/facets endpoint refactor(api)!: drop the per-attempt execution counts from diagnostics refactor: build the last era filters from cmip_input_filter test: stop pytest collecting the test config helpers as tests fix: return an empty model for an unknown mip_era fix: treat a blank isolate_ids or exclude_ids as no filter refactor: read catalog resource usage from ResourcesReader.summaries refactor: scope values by era with or_no_model_input test: pin how mixed-era and obs-only executions are scoped refactor: resolve the mip_era query value in one place chore: use Session.get for execution outputs ...
pytest-benchmark crashes formatting its machine_info warning when the storage sits outside the working directory.
There was a problem hiding this comment.
Actionable comments posted: 2

Review info
-
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:
400b9bcf-6eb4-48eb-9394-93d84ecc7898
Files ignored due to path filters: 1-
backend/uv.lockis excluded by!**/*.lock
Files selected for processing: 9-
backend/.gitignorebackend/pyproject.tomlbackend/scripts/perf-compare.shbackend/src/ref_backend/builder.pybackend/src/ref_backend/log.pybackend/src/ref_backend/main.pybackend/tests/test_log.pybackend/tests/test_tracing.pychangelog/153.improvement.md
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
-
Both CodeRabbit findings are fixed in 7152f0c (per-run benchmark storage, redacted log fields) and their threads are resolved.
Adds one wide event per request and JSON logs carrying the trace id, following on from #150.
ENVIRONMENT=localthe API logs one compact JSON object per line, in thecr-serviceshape (ts,level,logger,message). Grafana links a Loki line to its Tempo trace and back by matching"trace_id":"…", so the separators stay compact. Local runs keep loguru's text line, with the bound fields appended askey=valuepairs.trace_id,span_id,request_idandroute.cr-serviceWideEventMiddlewarelogs onehttp_requestevent per request with method, path, route, status,duration_ms, response size, client and user agent. The SQLAlchemy monitor addsdb_queriesanddb_time_msto it.routeis the same template as thehandlerlabel in/metrics, bound before routing so it is set for 405s, docs and static files too, andnullwhen nothing matches.LOG_LEVELnow applies to loguru's own logs. Deployed pods previously logged debug fromclimate_refand the providers whatever it was set to. Two requests on the fixture database went from 223 lines to 45.cr_service.redact.redact_fields, as thecr-serviceformatter does, so secret-looking keys are masked.scripts/perf-compare.shkeeps each run's benchmark storage inside the checkout. pytest-benchmark crashed formatting its machine_info warning for storage outside the working directory, which failedbackend-perfon this branch with "No endpoint ran".logging, and keeps the record'sextrafields.Example wide event from the fixture database:
{"ts":"2026-10-24T21:31:05.991Z","level":"info","logger":"cr_service.middleware","message":"http_request","trace_id":"4bf92f3577b34da6a3ce929d0e0e4736","span_id":"c2ec892fa406ca4a","request_id":"8fdd1766e25c449bb68d1a7b8bff6579","route":"/api/v1/executions/{group_id}","db_queries":1,"db_time_ms":0.04,"event":"http_request","method":"GET","path":"/api/v1/executions/999999","query":{},"status":404,"duration_ms":29.89,"response_bytes":32,"client_ip":"testclient","user_agent":"testclient","referer":null,"sentry_trace_id":"202a3b1f860c4f9e8f37d540ae5d0c7c"}Kubernetes still probes
/api/v1/utils/health-check/, so those hits log an info event until the probes move to/livezand/readyz, which log at debug.