Page MenuHomePhabricator

Add logging middleware
Closed, ResolvedPublic

Description

Add logging middleware that keeps track of all requests and their corresponding responses, including errors, for debugging.

https://expressjs.com/en/advanced/best-practice-performance.html#do-logging-correctly

Ensure that originating IP addresses are not being recorded.

Event Timeline

Logging both Citoid raw and Web2Cit citations (returned when the server is used with option citoid=true, as is the case with the Web2Cit-Gadget) would help us evaluate if Citoid's coverage gap is narrowing with Web2Cit (Web2Cit-Research).

diegodlh added a project: Web2Cit (Grant end).

Having this resolved by the end of Web2Cit grant period will ensure that we can evaluate Web2Cit usage in the future.

Also, consider logging the Referrer or Origin headers of the request (if any) to identify requests made by the Web2Cit-Gadget.

Also, consider logging the Referrer or Origin headers of the request (if any) to identify requests made by the Web2Cit-Gadget.

To identify requests made by the Web2Cit-Gadget we may consider whether the user script should use the [[ https://meta.wikimedia.org/wiki/User-Agent_policy | Api-User-Agent header ]].

In these cases, the Referrer or Origin headers may be used to better understand from which Wikipedia articles Web2Cit citations are being requested (as proposed in the Web2Cit project's final report).

Also, consider logging the Referrer or Origin headers of the request (if any) to identify requests made by the Web2Cit-Gadget.

If these headers don't reach the app (maybe they are removed by the proxy for privacy?) consider adding utm_source query parameters to the URL used by Web2Cit-Gadget.

We may also want to do this for URLs included in Web2Cit-Monitor results pages included in T317977.

To identify requests made by the Web2Cit-Gadget we may consider whether the user script should use the Api-User-Agent header.

See T390791

Jobs logging in Toolforge is moving to Loki (log aggregation system): https://wikitech.wikimedia.org/wiki/News/2025_New_Toolforge_log_storage. But it's not clear if this is also the case for web services.

Edit: see T127367#11855731: The plan is that webservices will be managed by jobs-api: T348755: [jobs-api,webservice] Run webservices via the jobs framework. When that task is completed, webservice logs will be available in Loki."

Also see this draft documentation page: https://wikitech.wikimedia.org/wiki/Portal%3AToolforge/Admin/Logging. And corresponding Grafana dashboard: https://grafana.wmcloud.org/d/TJuKfnt4z/tool-dashboard?orgId=1&from=now-7d&to=now&timezone=browser&var-cluster=P8433460076D33992&var-namespace=tool-web2cit

diegodlh changed the task status from Open to In Progress.Jun 10 2026, 10:47 PM

Added support for setting custom logger in Web2Cit-Core with 2105091d. In the future, consider T302588.

Added logging middleware in Web2Cit-Server with 574c0ed3 (but pending using upcoming w2c-core library with setLogger support):

Also lowered logging level of some common events in w2c-core as they would otherwise flood the server logs: 859ca801.

We may still need to reconsider logging level of some events (such as Citoid selection step errors) if we want server logs to be useful (and size-manageable).

Note that on Toolforge, the webservice toolforge logs output shows encoding issues and gets truncated, as opposed to the kubectl logs output. Reported in T429028.

diegodlh claimed this task.

Deployed with w2c-server v1.4.0