#154 — Not enough logging about HTTP requests.

Repo: Twill-AI/facade State: closed | Status: done Assignee: Unassigned

Created: 2024-10-22 · Updated: 2025-09-15

Description

Caused by #152.

If look on logs in it then tenant_id is not visible in logs because “ERROR: Exception in ASGI application” is generated in file “/usr/local/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py”, line 224. “INFO: 10.0.2.27:49920 - “PATCH /api/v1/dashboards/28 HTTP/1.1” 500 Internal Server Error” is generated in uvicorn/protocols/http/h11_impl.py:475 as well.

We may try to fix the latter with --no-access-log flag, see https://www.uvicorn.org/settings/#logging. But error still would be logged.

AC:

  • Make tenant_id visible for all errors happened inside HTTP handlers.
  • (optional) Change format of HTTP requests logs.

Implementation details

Following code effectively removes all Uvicorn logging:

    uvicorn_error_logger = logging.getLogger("uvicorn.error")
    uvicorn_error_logger.disabled = True
    uvicorn_access_logger = logging.getLogger("uvicorn.access")
    uvicorn_access_logger.disabled = True

Unfortunately it also removes “Application started” logs.

Tenant context is a quite low level item in current implementation. Because content is applied in run_endpoint_function_in_tenant_context function (in python-shared “auth.py”), which means it is executed in FastAPI logic right after solving all FastAPI dependencies

app.add_exception_handler(Exception, build_exception_handler()) in main.py sets exception handlers for Starlette’s ExceptionMiddleware. But all middlewares are be applied on the result of `run_

Notes

Add implementation notes, blockers, and context here

Add wikilinks to related people, meetings, or other tickets