Skip to content

Commit 0413214

Browse files
committed
Add a stacktrace to the records to show where the searches were originated
1 parent 0ea63ed commit 0413214

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

elastic_panel/panel.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from django.template.loader import render_to_string
33
from django.utils.translation import ugettext_lazy as _
44
from debug_toolbar.panels import Panel
5-
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
67
import hashlib
78
import json
89

@@ -30,6 +31,9 @@ def _pretty_json(data):
3031
return data
3132

3233

34+
hidden_paths.append(get_module_path(__name__))
35+
36+
3337
class ElasticQueryInfo:
3438
def __init__(self, method, full_url, path, body, status_code, response, duration):
3539
if not body:
@@ -47,6 +51,7 @@ def __init__(self, method, full_url, path, body, status_code, response, duration
4751
self.hash = hashlib.md5(
4852
self.full_url.encode("ascii", "ignore") + self.body.encode("ascii", "ignore")
4953
).hexdigest()
54+
self.stacktrace = tidy_stacktrace(reversed(get_stack()))
5055

5156

5257
class ElasticDebugPanel(Panel):
@@ -91,6 +96,7 @@ def generate_stats(self, request, response):
9196
if record.hash in hashs:
9297
self.nb_duplicates += 1
9398
hashs.add(record.hash)
99+
record.stacktrace = render_stacktrace(record.stacktrace)
94100

95101
self.nb_queries = len(records)
96102

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-
arrow = document.querySelector('a.elasticShowTemplate .toggleArrow')
19+
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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,18 @@
3232
<code class="json_code" contenteditable="true" >{{record.response}}</code>
3333
</div>
3434
</dd>
35-
</dt>
35+
<dd>
36+
<div class="djTemplateShowContextDiv">
37+
<a class="elasticShowTemplate">
38+
<span class="toggleArrow"></span> Show Stacktrace
39+
</a>
40+
</div>
41+
<div class="djTemplateHideContextDiv" style="display: none;">
42+
<pre class="djdt-stack">
43+
{{record.stacktrace}}
44+
</pre>
45+
</div>
46+
</dd>
3647
{% endfor %}
3748
</dl>
3849
{% else %}

0 commit comments

Comments
 (0)