Skip to content

feat: using structlog for all logging, add userID, add prod arg

Nathillard requested to merge nhillard_structlog into dev

Uses structlog for logging purposes; uses asgi for creating user id.

When run for debugging purposes, it prints directly to the console, eg:

2023-06-06T03:40:30.084442Z [info     ] Initial request received       [app.routes.search_wikipedia] destination=Plugin full_request_info={'request': {'query_language': 'en', 'query': 'trains', 'use_native_wikipedia_search': False, 'original_user_input': 'what is a train'}, 'headers': {'openai_ephemeral_user_id': 'abc123', 'openai_conversation_id': 'def456', 'openai_subdivision_1_iso_code': 'EN-US'}} request_id=None source=ChatGPT

When you specify LOG_JSON_FORMAT, as the docker container / prod config does, everything is logged as JSON:

{"event": "Waiting for application startup.", "logger": "uvicorn.error", "level": "info", "timestamp": "2023-06-06T03:40:55.664601Z"}
{"event": "Application startup complete.", "logger": "uvicorn.error", "level": "info", "timestamp": "2023-06-06T03:40:55.665645Z"}
{"event": "Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)", "logger": "uvicorn.error", "level": "info", "color_message": "Uvicorn running on \u001b[1m%s://%s:%d\u001b[0m (Press CTRL+C to quit)", "timestamp": "2023-06-06T03:40:55.666384Z"}

With logs like this, you can query and filter on AWS and parse more easily

Merge request reports