Permalink
Browse files

Initial Commit - Filter tracebacks by `context_type`

This is pretty hacky right now. It's a lot of copy-paste from Sentry,
and the JS is shoe-horned in at the bottom of the template. Still, it
works, so SHIP IT.
  • Loading branch information...
noahsilas committed Jun 28, 2012
0 parents commit 12a7bca41056f2d91f2784d2ed93157ae6134e12
21 LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2012 Philotic, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,2 @@
+include setup.py README.md MANIFEST.in LICENSE
+recursive-include sentry_cardinal/templates *
@@ -0,0 +1,17 @@
+# Sentry Cardinal
+
+This extension to [Sentry](https://github.com/dcramer/sentry) adds a little
+spice when dealing with longwinded tracebacks (such as those generated by Rails
+applications).
+
+## Features
+### Filtered Tracebacks
+ Traceback frames may be annotated with a `context_type`. By default, only
+ frames with a `context_type` of 'application' will be shown, but you can
+ easily toggle to show the full or framework tracebacks.
+
+## Usage
+Add `sentry_cardinal` to sentry's `INSTALLED_APPS`. You will need to configure
+your client to send stack traces with the interface
+`sentry_cardinal.interfaces.Stacktrace` instead of the usual
+`sentry.interfaces.Stacktrace`.
No changes.
@@ -0,0 +1,38 @@
+import sentry.interfaces
+from sentry.web.helpers import render_to_string
+
+class Stacktrace(sentry.interfaces.Stacktrace):
+ score = 1000
+
+ def to_html(self, event):
+ frames = []
+ for frame in self.frames:
+ if frame.get('context_line'):
+ context = sentry.interfaces.get_context(frame['lineno'], frame['context_line'], frame.get('pre_context'), frame.get('post_context'))
+ start_lineno = context[0][0]
+ else:
+ context = []
+ start_lineno = None
+
+ context_vars = []
+ if frame.get('vars'):
+ 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_type': frame.get('context_type'),
+ 'context': context,
+ 'vars': context_vars,
+ })
+
+ return render_to_string('sentry_cardinal/partial/interfaces/stacktrace.html', {
+ 'event': event,
+ 'frames': frames,
+ 'stacktrace': self.get_traceback(event),
+ })
@@ -0,0 +1,79 @@
+{% load i18n %}
+{% load sentry_helpers %}
+
+<div id="traceback" class="module">
+ <div class="page-header">
+ <a href="javascript:void(0)" data-container="#raw_stacktrace" data-title="Stacktrace" class="popup btn small pull-right">{% trans "Raw" %}</a>
+ <h2>{% trans "Stacktrace" %}</h2>
+ <ul class="nav nav-tabs">
+ <li data-filter='application' class="active"><a href="#">Application</a></li>
+ <li data-filter='framework'><a href="#">Framework</a></li>
+ <li data-filter=''><a href="#">Full</a></li>
+ </ul>
+ </div>
+ <div class="module-content">
+ <ul class="traceback">
+ {% for frame in frames %}
+ <li class="frame {{frame.context_type}}">
+ <p>
+ <code>{{ frame.filename }}</code>
+ {% if frame.function %} in <code>{{ frame.function }}</code>{% endif %}
+ {% if not frame.context %} at line <code>{{ frame.lineno }}</code>{% endif %}
+ </p>
+
+ {% if frame.context %}
+ <ol start="{{ frame.start_lineno }}" class="context expandable" id="c{{ forloop.counter0 }}">
+ {% for num, line in frame.context %}
+ <li{% if num == frame.lineno %} class="active"{% else %} class="stack{{ forloop.parentloop.counter0 }} closed"{% endif %} onclick="$('.stack{{ forloop.parentloop.counter0 }}').toggleClass('closed')"><pre>{{ line }}</pre></li>
+ {% endfor %}
+ </ol>
+ {% endif %}
+ {% if frame.vars %}
+ <div class="commands">
+ <a href="#" onclick="return varToggle(this, '{{ forloop.counter0 }}')"><span>&#x25b6;</span> {% trans "Local vars" %}</a>
+ </div>
+ <table class="table vars" id="v{{ forloop.counter0 }}" style="display:none;">
+ <colgroup>
+ <col style="width:100px;">
+ </colgroup>
+ <tbody>
+ {% for key, value in frame.vars.iteritems|as_sorted %}
+ <tr>
+ <td>{{ key }}</td>
+ <td class="code"><pre>{{ value|pprint }}</pre></td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ {% endif %}
+ </li>
+ {% endfor %}
+ </ul>
+ </div>
+</div>
+
+<script>
+ (function($){
+ function filter_trace(classname){
+ frames = $('.traceback .frame');
+ if (classname == '') {
+ frames.show();
+ } else {
+ frames.hide();
+ frames.filter('.' + classname).show();
+ }
+ }
+ $('#traceback li[data-filter] a').click(function(e){
+ e.preventDefault();
+ tab = $($(this).parent());
+ tab.addClass('active')
+ tab.siblings().removeClass('active');
+ filter_trace(tab.data('filter'));
+ });
+ filter_trace('application');
+ })(jQuery);
+</script>
+
+<div id="raw_stacktrace" style="display: none;">
+ <pre>{{ stacktrace }}</pre>
+</div>
@@ -0,0 +1,22 @@
+from setuptools import setup
+
+setup(
+ name='sentry-cardinal',
+ version='0.1.0-1',
+ packages=['sentry_cardinal'],
+ include_package_data=True,
+ license='MIT',
+ author='Noah Silas',
+ author_email='noah.silas@causes.com',
+ url='https://github.com/causes/sentry_cardinal',
+ description="Added niceness for railsy tracebacks in Sentry",
+ zip_safe=False,
+ classifiers=[
+ 'Framework :: Django',
+ 'Intended Audience :: Developers',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'License :: OSI Approved :: BSD License',
+ 'Development Status :: 3 - Alpha',
+ ],
+)

0 comments on commit 12a7bca

Please sign in to comment.