diff options
author | Armin Ronacher <armin.ronacher@active-4.com> | 2016-05-05 12:31:00 +0200 |
---|---|---|
committer | Armin Ronacher <armin.ronacher@active-4.com> | 2016-05-05 12:31:02 +0200 |
commit | 373f2817755bd54cb71309b366f96fa62fc1cf32 (patch) | |
tree | d0a78bf606e64ee29bdeec3b3f3afd013bc8c2e1 | |
parent | 37c3a892b308e0ae2b6962859a888628bf4ddbe1 (diff) | |
download | raven-373f2817755bd54cb71309b366f96fa62fc1cf32.tar.gz |
Added flag for enabling or disabling breadcrumbs
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | raven/base.py | 18 | ||||
-rw-r--r-- | raven/breadcrumbs.py | 11 | ||||
-rw-r--r-- | raven/context.py | 4 |
4 files changed, 26 insertions, 9 deletions
@@ -3,6 +3,8 @@ Version 5.16.0 * exc_info is no longer included in logger based breadcrumbs. * log the entire logger name as category. +* added a `enable_breadcrumbs` flag to the client to allow the enabling or + disabling of breadcrumbs quickly. Version 5.15.0 -------------- diff --git a/raven/base.py b/raven/base.py index 0136c88..6c06d61 100644 --- a/raven/base.py +++ b/raven/base.py @@ -138,7 +138,7 @@ class Client(object): def __init__(self, dsn=None, raise_send_errors=False, transport=None, install_sys_hook=True, install_logging_hook=True, - hook_libraries=None, **options): + hook_libraries=None, enable_breadcrumbs=True, **options): global Raven o = options @@ -194,6 +194,7 @@ class Client(object): # We want to remember the creating thread id here because this # comes in useful for the context special handling self.main_thread_id = get_thread_ident() + self.enable_breadcrumbs = enable_breadcrumbs from raven.context import Context self._context = Context(self) @@ -460,13 +461,14 @@ class Client(object): data.setdefault('sdk', SDK_VALUE) # insert breadcrumbs - crumbs = self.context.breadcrumbs.get_buffer() - if crumbs: - # Make sure we send the crumbs here as "values" as we use the - # raven client internally in sentry and the alternative - # submission option of a list here is not supported by the - # internal sender. - data.setdefault('breadcrumbs', {'values': crumbs}) + if self.enable_breadcrumbs: + crumbs = self.context.breadcrumbs.get_buffer() + if crumbs: + # Make sure we send the crumbs here as "values" as we use the + # raven client internally in sentry and the alternative + # submission option of a list here is not supported by the + # internal sender. + data.setdefault('breadcrumbs', {'values': crumbs}) return data diff --git a/raven/breadcrumbs.py b/raven/breadcrumbs.py index b6a35dc..66e579f 100644 --- a/raven/breadcrumbs.py +++ b/raven/breadcrumbs.py @@ -45,6 +45,17 @@ class BreadcrumbBuffer(object): return rv +class BlackholeBreadcrumbBuffer(BreadcrumbBuffer): + def record(self, *args, **kwargs): + pass + + +def make_buffer(enabled=True): + if enabled: + return BreadcrumbBuffer() + return BlackholeBreadcrumbBuffer() + + def record_breadcrumb(type, timestamp=None, duration=None, level=None, message=None, category=None, data=None, processor=None): diff --git a/raven/context.py b/raven/context.py index 03309f1..d27572a 100644 --- a/raven/context.py +++ b/raven/context.py @@ -44,6 +44,8 @@ class Context(local, Mapping, Iterable): """ def __init__(self, client=None): + breadcrumbs = raven.breadcrumbs.make_buffer( + client is None or client.enable_breadcrumbs) if client is not None: client = weakref(client) self._client = client @@ -54,7 +56,7 @@ class Context(local, Mapping, Iterable): self.activate() self.data = {} self.exceptions_to_skip = set() - self.breadcrumbs = raven.breadcrumbs.BreadcrumbBuffer() + self.breadcrumbs = breadcrumbs @property def client(self): |