comparison roundup/cgi/wsgi_handler.py @ 8446:14c7c07b32d8

feature: add thread local trace_id and trace_reason to logging. Added trace_id to default logging so that all logs for a given request share the same trace_id. This allows correlation of logs across a request. admin_guide.txt, upgrading.txt: add docs update sample configs to include trace_id. rewrite logging docs in admin_guide. Hopefully they are clearer now. clean up some stuff in the logging config file docs. admin.py: add decorators to run_command to enable trace_id. change calls to db.commit() to use run_command to get trace_id. configuration.py: clean up imports. update docstrings, comments and inline docs. add trace_id to default log format. add function for testing decorated with trace_id. add support for dumping stack trace in logging. add check for pytest in sys.modules to enable log propagation when pytest is running. Otherwise tests fail as the caplog logger doesn't see the roundup logs. logcontext.py: new file to handle thread local contextvar mangement. mailgw.py: add decorators for trace_id etc. scripts/roundup_xlmrpc_server.py: add decorators for trace_id etc. fix encoding bug turning bytes into a string. fix command line issue where we can't set encoding. (not sure if changing encoding via command line even works) cgi/client.py decorate two entry points for trace_id etc. cgi/wsgi_handler.py: decorate entry point for trace_id etc. test/test_config.py: add test for trace_id in new log format. test various cases for sinfo and errors in formating msg.
author John Rouillard <rouilj@ieee.org>
date Tue, 16 Sep 2025 22:53:00 -0400
parents dbeb6bf056c7
children 617d55f1d518
comparison
equal deleted inserted replaced
8445:4b6e9a0e13ee 8446:14c7c07b32d8
11 from roundup.anypy import http_ 11 from roundup.anypy import http_
12 from roundup.anypy.html import html_escape 12 from roundup.anypy.html import html_escape
13 from roundup.anypy.strings import s2b 13 from roundup.anypy.strings import s2b
14 from roundup.cgi import TranslationService 14 from roundup.cgi import TranslationService
15 from roundup.cgi.client import BinaryFieldStorage 15 from roundup.cgi.client import BinaryFieldStorage
16 from roundup.logcontext import gen_trace_id, store_trace_reason
16 17
17 BaseHTTPRequestHandler = http_.server.BaseHTTPRequestHandler 18 BaseHTTPRequestHandler = http_.server.BaseHTTPRequestHandler
18 DEFAULT_ERROR_MESSAGE = http_.server.DEFAULT_ERROR_MESSAGE 19 DEFAULT_ERROR_MESSAGE = http_.server.DEFAULT_ERROR_MESSAGE
19 20
20 try: 21 try:
100 self.feature_flags["cache_tracker"] is not False: 101 self.feature_flags["cache_tracker"] is not False:
101 self.tracker = roundup.instance.open(self.home, not self.debug) 102 self.tracker = roundup.instance.open(self.home, not self.debug)
102 else: 103 else:
103 self.preload() 104 self.preload()
104 105
106 @gen_trace_id()
107 @store_trace_reason("wsgi")
105 def __call__(self, environ, start_response): 108 def __call__(self, environ, start_response):
106 """Initialize with `apache.Request` object""" 109 """Initialize with `apache.Request` object"""
107 request = RequestHandler(environ, start_response) 110 request = RequestHandler(environ, start_response)
108 111
109 if environ['REQUEST_METHOD'] == 'OPTIONS': 112 if environ['REQUEST_METHOD'] == 'OPTIONS':

Roundup Issue Tracker: http://roundup-tracker.org/