Skip to content

Commit

Permalink
Shorten children (and truncate at depth 5) as it can become slow, and…
Browse files Browse the repository at this point in the history
… generally unnescesary to render
  • Loading branch information
dcramer committed Feb 10, 2012
1 parent ba25c81 commit dfaabf6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion sentry/interfaces.py
Expand Up @@ -144,6 +144,19 @@ def __init__(self, frames):
# assert 'context_line' in frame
# assert 'function' in frame

def _shorten(self, value, depth=1):
if depth > 5:
return type(value)
if isinstance(value, dict):
return dict((k, self._shorten(v, depth + 1)) for k, v in sorted(value.iteritems())[:100 / depth])
elif isinstance(value, (list, tuple, set, frozenset)):
return tuple(self._shorten(v, depth + 1) for v in value)[:100 / depth]
elif isinstance(value, (int, long, float)):
return value
elif not value:
return value
return value[:100]

def serialize(self):
return {
'frames': self.frames,
Expand All @@ -158,14 +171,21 @@ def to_html(self, event):
else:
context = []
start_lineno = None

context_vars = []
if 'vars' in frame:
context_vars = self._shorten(frame['vars'])
else:
context_vars = []

frames.append({
'abs_path': frame.get('abs_path'),
'filename': frame['filename'],
'function': frame.get('function'),
'start_lineno': start_lineno,
'lineno': frame.get('lineno'),
'context': context,
'vars': frame.get('vars') or {},
'vars': context_vars,
})

return render_to_string('sentry/partial/interfaces/stacktrace.html', {
Expand Down

0 comments on commit dfaabf6

Please sign in to comment.