Skip to content

Commit 9bdcdd6

Browse files
authored
Merge pull request #13 from dbreen/master
Add a stacktrace to the records to show where the searches were originated
2 parents 6454059 + 71ae949 commit 9bdcdd6

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

elastic_panel/panel.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import hashlib
22
import json
3-
import traceback
43

54
from 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
77
from django.templatetags.static import static
88
from django.utils.translation import gettext_lazy as _
99
from 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+
3336
class 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

5356
class 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

elastic_panel/static/elastic_panel/js/elastic_panel.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ var uarr = String.fromCharCode(0x25b6),
1212

1313
var showHandler = function(e) {
1414

15-
toggle(this.nextElementSibling)
15+
if(this.nextElementSibling) {
16+
toggle(this.nextElementSibling)
17+
}
1618

17-
var arrow = document.querySelector('a.elasticShowTemplate .toggleArrow')
19+
var arrow = this.children[0];
1820
arrow.textContent = arrow.textContent == uarr ? darr : uarr
1921

2022
toggle(this.parentNode.nextElementSibling)

elastic_panel/templates/elastic_panel/elastic_panel.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
<dd>
3636
<div class="djTemplateShowContextDiv">
3737
<a class="elasticShowTemplate">
38-
<span class="toggleArrow"></span> Show Traceback
38+
<span class="toggleArrow"></span> Show Stacktrace
3939
</a>
40-
<a class="selectText" style="display: none;"> -&gt; (Select All Json for ctrl + c)</a>
4140
</div>
4241
<div class="djTemplateHideContextDiv" style="display: none;">
43-
<code class="json_code" contenteditable="true" >{{record.traceback}}</code>
42+
<pre class="djdt-stack">
43+
{{record.stacktrace}}
44+
</pre>
4445
</div>
4546
</dd>
46-
</dt>
4747
{% endfor %}
4848
</dl>
4949
{% else %}

0 commit comments

Comments
 (0)