ENG-3006 Add request_id metadata to all logs#7691
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
Greptile SummaryThis PR adds Key changes:
Confidence Score: 3/5
Important Files Changed
Last reviewed commit: "fix test" |
|
@greptile re-review |
|
@greptile |
|
@greptile |
thabofletcher
left a comment
There was a problem hiding this comment.
Great! All tests pass from the PR description: I sent a over a doc with a few ideas
Ticket ENG-3006
Description Of Changes
Adds
X-Request-IDheader support so that all logs emitted during a single API request can be correlated. Clients can supply their own ID via theX-Request-IDrequest header, or the server generates a UUID automatically. The ID is returned in theX-Request-IDresponse header and injected into every log record.How it works:
LogRequestMiddlewarereads/generates the request ID and stores it in the existingRequestContextContextVarrequest_idinto every log record'sextradict — no changes needed to the ~2,900 existinglogger.*call sitesbefore_task_publish/task_prerun) propagate the request ID to worker processesrequest_idappears as a searchable field in log aggregators (e.g.@record.extra.request_idin Datadog)Code Changes
src/fides/api/request_context.py— Addedrequest_idfield toRequestContextdataclass with get/set helpers. Fixed pre-existing bug whereset_request_contextmutated a shared default object instead of creating a per-request copy.src/fides/api/util/logger.py— Added_inject_request_contextpatcher that reads the ContextVar and injectsrequest_idinto every log record. Updatedhas_custom_extrafilter to ignore patcher-injected keys.src/fides/api/asgi_middleware.py— UpdatedLogRequestMiddlewareto read/generate request ID, set ContextVar, and injectX-Request-IDresponse header. Addedheader_injecting_sendhelper toBaseASGIMiddleware.src/fides/api/tasks/__init__.py— Addedbefore_task_publishandtask_prerunCelery signal handlers to propagate request ID to worker processes.Steps to Confirm
X-Request-IDheader — confirm the response includes a generatedX-Request-IDheaderX-Request-ID: test-123— confirmtest-123appears in the response header and in log outputrequest_idvaluesrequest_idappears in the serialized log output underrecord.extra.request_idPre-Merge Checklist
CHANGELOG.mdupdated