Skip to content

Commit 67ccb20

Browse files
committed
chore: move exc deduplicator into client
let's keep event processors free for user and integration. It also feels wrong to let scope.clear() disable such core functionality.
1 parent 995fe81 commit 67ccb20

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

sentry_sdk/client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import os
22
import uuid
33

4-
from .utils import Dsn, SkipEvent
4+
from .utils import Dsn, SkipEvent, ContextVar
55
from .transport import Transport
66
from .consts import DEFAULT_OPTIONS, SDK_INFO
77
from .stripping import strip_event, flatten_metadata
88

99

1010
NO_DSN = object()
1111

12+
_most_recent_exception = ContextVar("sentry_most_recent_exception")
13+
1214

1315
class Client(object):
1416
def __init__(self, dsn=None, *args, **kwargs):
@@ -58,6 +60,11 @@ def _prepare_event(self, event, scope):
5860
if event.get("event_id") is None:
5961
event["event_id"] = uuid.uuid4().hex
6062

63+
if event._exc_value is not None:
64+
if _most_recent_exception.get(None) is event._exc_value:
65+
raise SkipEvent()
66+
_most_recent_exception.set(event._exc_value)
67+
6168
if scope is not None:
6269
scope.apply_to_event(event)
6370

sentry_sdk/hub.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from ._compat import with_metaclass
66
from .scope import Scope
7-
from .utils import Event, skip_internal_frames, ContextVar, DefaultEventProcessor
7+
from .utils import Event, skip_internal_frames, ContextVar
88

99

1010
_local = ContextVar("sentry_current_hub")
@@ -191,4 +191,3 @@ def _flush_event_processors(self):
191191

192192

193193
GLOBAL_HUB = Hub()
194-
GLOBAL_HUB.add_event_processor(DefaultEventProcessor)

sentry_sdk/utils.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,6 @@ def __len__(self):
355355
return len(self._data)
356356

357357

358-
class DefaultEventProcessor(object):
359-
def __init__(self):
360-
self._most_recent_exception = ContextVar("most-recent-exception")
361-
362-
def __call__(self, event):
363-
if event._exc_value is None:
364-
return
365-
if self._most_recent_exception.get(None) is event._exc_value:
366-
raise SkipEvent()
367-
self._most_recent_exception.set(event._exc_value)
368-
369-
370358
class SkipEvent(Exception):
371359
"""Risen from an event processor to indicate that the event should be
372360
ignored and not be reported."""

0 commit comments

Comments
 (0)