I found a way to log request uuid is that rename thread name in my middleware,but I’m not sure that if have problem in high qps.
Besides, it has any other method to log request uuid?
here is my middleware
class RequestIDMiddleware():
# pass
def __init__(self, get_response):
self.get_response = get_response
# One-time configuration and initialization.
def __call__(self, request):
request.META['request_id'] = str(uuid.uuid4())
logger.info(f"start request id: {request.META['request_id']}")
response = self.get_response(request)
if request.META.get('request_id') is None:
response.headers['X-REQUEST-ID'] = request.META['request_id']
logger.info(f"finish request id: {response.headers['X-REQUEST-ID']}")
return response