Repository navigation
Closed
Labels
priority: mediumMedium prioritystatus: triageHas not been triaged by admintype: featureNew feature or requestworkload: daysLikely takes days to resolve
Milestone
Description
Problem
FOCA apps can't correlate the log lines of one request: there is no app-wide request ID and no machine-readable log format. The plugin engine has its own request_id(), but nothing else does. Apps such as cloud-registry set logger levels in code, because the log config model has no loggers or filters sections.
Proposal
Framework-neutral except for the setter; no new runtime dependency.
foca.context.request_id(), held in aContextVar. This creates thefoca.contextmodule, which the request accessors in 0.22.0 extend. The plugin engine'srequest_id()uses it.- A plain WSGI middleware around
app.wsgi_app, not Flask hooks. An ASGI port follows with 1.0.0-rc1.- Header from
server.request_id.header(defaultX-Request-ID). - An incoming value is accepted only if it matches
^[A-Za-z0-9._:-]{1,128}$andserver.request_id.trust_incomingis on (default on); otherwiseuuid4().hex. - The ID is echoed in the response header.
- Header from
foca.utils.logging.ContextFilteraddsrequest_id,operation_id,subjectandclientto every record; empty outside requests; Celery uses the task ID.foca.utils.logging.JsonFormatter(stdlib): one JSON object per line withtimestamp,level,logger,message, context fields,exc_infoandextrakeys. No double escaping of whatescape_log_valuedoes for text logs.- Config model:
log.filters,log.loggers, formatter extras and a built-in formatterjson. The default staysstandard. foca.gunicorn_config: access log format with the request ID.
The ID is for log correlation only. Traces, metrics and health endpoints are out of scope.
Acceptance criteria
- A valid incoming ID is echoed; an invalid or missing one, or
trust_incoming: false, gives a generated ID; the header name is configurable. - Records in a request carry the fields; outside, they are empty and nothing fails.
formatter: jsongives one valid JSON object per line, including exceptions andextrafields.log.loggersandlog.filtersare validated and passed todictConfig.- Defaults unchanged, not breaking. 100% coverage, mypy, ruff, strict docs build; docs section on request IDs and JSON logs.
Metadata
Metadata
Assignees
Labels
priority: mediumMedium prioritystatus: triageHas not been triaged by admintype: featureNew feature or requestworkload: daysLikely takes days to resolve
Activity