feat(recorder): Create uuid in RecorderMiddleware
This commit is contained in:
parent
8a62b135e2
commit
dcd9a1053d
2 changed files with 19 additions and 8 deletions
|
|
@ -58,8 +58,6 @@ def recorder(function):
|
|||
wrapper.calls.append(data)
|
||||
return result
|
||||
|
||||
import uuid
|
||||
wrapper.uuid = str(uuid.uuid1())
|
||||
wrapper.calls = list()
|
||||
wrapper.path = frappe.request.path
|
||||
return wrapper
|
||||
|
|
@ -84,9 +82,12 @@ def persist(function):
|
|||
in chronological order
|
||||
"""
|
||||
path = function.path
|
||||
uuid = function.uuid
|
||||
calls = function.calls
|
||||
|
||||
# RecorderMiddleware creates a uuid for every request and
|
||||
# stores it in request environ
|
||||
uuid = frappe.request.environ["uuid"]
|
||||
|
||||
# Redis Sorted Set -> Ordered set (Ordereed by `score`)
|
||||
# Elements are ordered from low to high score
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
# MIT License. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import uuid
|
||||
|
||||
import frappe
|
||||
import os
|
||||
|
|
@ -38,8 +39,17 @@ class RecorderMiddleware(object):
|
|||
start_response(status, headers, exc_info)
|
||||
return response_body.append
|
||||
|
||||
appiter = self._app(environ, catching_start_response)
|
||||
response_body.extend(appiter)
|
||||
if hasattr(appiter, 'close'):
|
||||
appiter.close()
|
||||
return [b''.join(response_body)]
|
||||
def runapp():
|
||||
appiter = self._app(environ, catching_start_response)
|
||||
response_body.extend(appiter)
|
||||
if hasattr(appiter, 'close'):
|
||||
appiter.close()
|
||||
|
||||
# Every request is assigned a uuid here,
|
||||
# uuid is available to everyone as frappe.request.environ["uuid"]
|
||||
# SQL calls and profile details can't be recorded and accessed without this
|
||||
environ["uuid"] = str(uuid.uuid1())
|
||||
|
||||
runapp()
|
||||
body = [b''.join(response_body)]
|
||||
return body
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue