summaryrefslogtreecommitdiff
path: root/raven/utils
diff options
context:
space:
mode:
authorDavid Cramer <dcramer@gmail.com>2016-03-14 20:51:54 -0700
committerDavid Cramer <dcramer@gmail.com>2016-09-14 09:17:48 -0700
commitc3e504a0bf77deb9a79bd841e9cacc62c8127901 (patch)
treedeed8bbbe03545a501ac394d499769ceb52f8b7e /raven/utils
parentd5b8643b7281e19876eb50567588f23e021ef773 (diff)
downloadraven-c3e504a0bf77deb9a79bd841e9cacc62c8127901.tar.gz
Replace culprits with transaction names
- Implemented in Django via middleware - Defer empty culprit to server (Sentry deals fills it) - Implemented Celery as task names - Cleaned up Django and Celery abstractions to ease testing
Diffstat (limited to 'raven/utils')
-rw-r--r--raven/utils/stacks.py36
-rw-r--r--raven/utils/testutils.py14
-rw-r--r--raven/utils/transaction.py51
3 files changed, 65 insertions, 36 deletions
diff --git a/raven/utils/stacks.py b/raven/utils/stacks.py
index 7933313..ee95d7a 100644
--- a/raven/utils/stacks.py
+++ b/raven/utils/stacks.py
@@ -11,7 +11,6 @@ import inspect
import linecache
import re
import sys
-import warnings
from raven.utils.serializer import transform
from raven._compat import iteritems
@@ -82,41 +81,6 @@ def get_lines_from_file(filename, lineno, context_lines,
)
-def label_from_frame(frame):
- module = frame.get('module') or '?'
- function = frame.get('function') or '?'
- if module == function == '?':
- return ''
- return '%s in %s' % (module, function)
-
-
-def get_culprit(frames, *args, **kwargs):
- # We iterate through each frame looking for a deterministic culprit
- # When one is found, we mark it as last "best guess" (best_guess) and then
- # check it against ``exclude_paths``. If it isn't listed, then we
- # use this option. If nothing is found, we use the "best guess".
- if args or kwargs:
- warnings.warn('get_culprit no longer does application detection')
-
- best_guess = None
- culprit = None
- for frame in reversed(frames):
- culprit = label_from_frame(frame)
- if not culprit:
- culprit = None
- continue
-
- if frame.get('in_app'):
- return culprit
- elif not best_guess:
- best_guess = culprit
- elif best_guess:
- break
-
- # Return either the best guess or the last frames call
- return best_guess or culprit
-
-
def _getitem_from_frame(f_locals, key, default=None):
"""
f_locals is not guaranteed to have .get(), but it will always
diff --git a/raven/utils/testutils.py b/raven/utils/testutils.py
index 52df1b1..4859f43 100644
--- a/raven/utils/testutils.py
+++ b/raven/utils/testutils.py
@@ -7,6 +7,8 @@ raven.utils.testutils
"""
from __future__ import absolute_import
+import raven
+
from exam import Exam
try:
@@ -17,3 +19,15 @@ except ImportError:
class TestCase(Exam, BaseTestCase):
pass
+
+
+class InMemoryClient(raven.Client):
+ def __init__(self, **kwargs):
+ self.events = []
+ super(InMemoryClient, self).__init__(**kwargs)
+
+ def is_enabled(self):
+ return True
+
+ def send(self, **kwargs):
+ self.events.append(kwargs)
diff --git a/raven/utils/transaction.py b/raven/utils/transaction.py
new file mode 100644
index 0000000..8dc6e06
--- /dev/null
+++ b/raven/utils/transaction.py
@@ -0,0 +1,51 @@
+from __future__ import absolute_import
+
+from threading import local
+
+
+class TransactionContext(object):
+ def __init__(self, stack, context):
+ self.stack = stack
+ self.context = context
+
+ def __enter__(self):
+ self.stack.push(self.context)
+ return self
+
+ def __exit__(self, *exc_info):
+ self.stack.pop(self.context)
+
+
+class TransactionStack(local):
+ def __init__(self):
+ self.stack = []
+
+ def __len__(self):
+ return len(self.stack)
+
+ def __iter__(self):
+ return iter(self.stack)
+
+ def __call__(self, context):
+ return TransactionContext(self, context)
+
+ def clear(self):
+ self.stack = []
+
+ def peek(self):
+ try:
+ return self.stack[-1]
+ except IndexError:
+ return None
+
+ def push(self, context):
+ self.stack.append(context)
+ return context
+
+ def pop(self, context=None):
+ if context is None:
+ return self.stack.pop()
+
+ while self.stack:
+ if self.stack.pop() is context:
+ return context