Add user context to frontend logs#1023
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (14)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThread user_id/job_id into logging: add ContextVar-based UserLogContext/JobLogContext and WorkflowLogContext wiring, update JSON formatters (Python/Go), propagate user through job models and job enqueue sites, wrap runtime handlers/workers, extend UI logger and sync via UserProvider, and add tests. ChangesPer-user logging context
🎯 4 (Complex) | ⏱️ ~45 minutes
Suggested reviewers:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1023 +/- ##
==========================================
- Coverage 46.04% 46.03% -0.02%
==========================================
Files 220 220
Lines 28572 28583 +11
Branches 4268 4272 +4
==========================================
+ Hits 13155 13157 +2
- Misses 14775 14784 +9
Partials 642 642
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
* #None - Add user_id to JSON service logs
Signed-off-by: Trasha Dewan <tdewan@nvidia.com>
* #None - Propagate user_id to all workflow job logs
Threads the workflow submitter through CleanupWorkflow, UploadWorkflowFiles,
CleanupGroup, RescheduleTask, CheckRunTimeout, and CheckQueueTimeout so their
service logs include user_id. Adds user as a default-empty field on
WorkflowJob and BackendWorkflowJob, and replaces the user='osmo' sentinel
on timeout-spawned UpdateGroup and CancelWorkflow jobs with the workflow
owner. CancelWorkflow.execute still writes 'osmo' to cancelled_by for
timeout-driven cancels so the UI can distinguish them from user-initiated
cancels.
Signed-off-by: Trasha Dewan <tdewan@nvidia.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* #None - Fix UserLogContext leaking outer user_id when nested
UserLogContext.__enter__ skipped ContextVar.set() when user_id was empty,
so an empty nested scope would leave the outer user_id live and
misattribute JSON logs emitted inside the inner block. Always call set()
— including with '' — so an empty nested context masks the outer value
within its scope and restores it cleanly on exit.
Signed-off-by: Trasha Dewan <tdewan@nvidia.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* #None - Add job_id and HTTP status_code to JSON service logs
Threads job_id through the same channels as user_id so every log emitted
while a frontend or backend job is executing carries the job's id:
- Adds JobLogContext (mirrors UserLogContext) and extends
WorkflowLogContext to also manage a job_id ContextVar.
- JsonServiceFormatter emits job_id from the record attribute or the
ContextVar, with empty values masking outer scopes.
- Worker (service/worker/worker.py) and backend worker pass job.job_id
into the surrounding log context.
- WorkflowJob.log_labels() and BackendWorkflowJob.log_labels() include
job_id so explicit logs that pass extra=self.log_labels() carry it too.
Adds status_code emission to JSON service logs. The check_client_version
middleware now emits one access-log line per request after the response
is ready, attaching status_code via extra=, so all three return paths
(version mismatch, expired token, normal pass-through) are covered.
Signed-off-by: Trasha Dewan <tdewan@nvidia.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* #None - Add user context to frontend logs
---------
Signed-off-by: Trasha Dewan <tdewan@nvidia.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0085ebc to
d2a44cc
Compare
Description
Adds frontend user context to OSMO UI logs so log messages emitted during an authenticated
UserProvidersession include the active user ID.setLogUserId/clearLogUserIdhelpers in the UI logger.[user=<id>]when a user ID is available.UserProviderto set and clear the log user ID as the active user changes.Issue - None
Checklist
Summary by CodeRabbit