11import hashlib
22import json
3- import traceback
43
54from debug_toolbar .panels import Panel
6- from debug_toolbar .utils import ThreadCollector
5+ from debug_toolbar .utils import ThreadCollector , get_stack , tidy_stacktrace , render_stacktrace , \
6+ get_module_path , hidden_paths
77from django .templatetags .static import static
88from django .utils .translation import gettext_lazy as _
99from elasticsearch .connection .base import Connection
@@ -30,6 +30,9 @@ def _pretty_json(data):
3030 return data
3131
3232
33+ hidden_paths .append (get_module_path (__name__ ))
34+
35+
3336class ElasticQueryInfo :
3437 def __init__ (self , method , full_url , path , body , status_code , response , duration ):
3538 if not body :
@@ -38,7 +41,6 @@ def __init__(self, method, full_url, path, body, status_code, response, duration
3841 self .body = _pretty_json (body )
3942 if isinstance (self .body , bytes ):
4043 self .body = self .body .decode ("ascii" , "ignore" )
41- self .traceback = "" .join (traceback .format_stack ()[:- 2 ])
4244 self .method = method
4345 self .full_url = full_url
4446 self .path = path
@@ -48,6 +50,7 @@ def __init__(self, method, full_url, path, body, status_code, response, duration
4850 self .hash = hashlib .md5 (
4951 self .full_url .encode ("ascii" , "ignore" ) + self .body .encode ("ascii" , "ignore" )
5052 ).hexdigest ()
53+ self .stacktrace = tidy_stacktrace (reversed (get_stack ()))
5154
5255
5356class ElasticDebugPanel (Panel ):
@@ -98,6 +101,7 @@ def generate_stats(self, request, response):
98101 if record .hash in hashs :
99102 self .nb_duplicates += 1
100103 hashs .add (record .hash )
104+ record .stacktrace = render_stacktrace (record .stacktrace )
101105
102106 self .nb_queries = len (records )
103107
0 commit comments