Skip to content

Commit 1cb9762

Browse files
committed
T7565: Reimplement custom event dropping code in new Sentry release
1 parent a1d7772 commit 1cb9762

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

sentry_sdk/transport.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import urllib3 # type: ignore
66
import certifi
77
import gzip
8+
import re
89

910
from datetime import datetime, timedelta
1011

@@ -93,6 +94,55 @@ def __init__(self, options):
9394

9495
def _send_event(self, event):
9596
# type: (Dict[str, Any]) -> None
97+
98+
error_context_lines = []
99+
100+
# T7565: Collect error message information and skip if any of those
101+
# messages correspond to messages in our blacklist. Re-implementation
102+
# of custom code from the deprecated Raven library.
103+
try:
104+
exception = event['exception']
105+
exc_vals = exception['values']
106+
107+
for exc_val in exc_vals:
108+
frames = exc_val['stacktrace']['frames']
109+
110+
for frame in frames:
111+
error_context_lines.append(frame['context_line'])
112+
except (IndexError, KeyError):
113+
# The event structure is missing some data, so do nothing.
114+
pass
115+
else:
116+
messages_to_ignore = [
117+
u"KeyError: 'partial_pipeline'",
118+
u"TypeError: argument of type 'NoneType' is not iterable",
119+
u"NotFound: Invalid resource lookup data provided (mismatched"
120+
" type)",
121+
u"Invalid resource lookup data provided (mismatched type)",
122+
u"Forbidden (CSRF token missing or incorrect.)"
123+
]
124+
regex_messages = [
125+
r"PdfReadWarning.*", r"Superfluous whitespace.*",
126+
r"SNIMissingWarning: An HTTPS request has.*",
127+
r"An HTTPS request has.*",
128+
r"InsecurePlatformWarning: A true SSLContext.*",
129+
r"A true SSLContext is not available.*",
130+
r"RuntimeWarning: DateTimeField.*",
131+
r"DateTimeField.*received a naive datetime.*",
132+
r"DeprecationWarning: integer argument expected.*"
133+
r"integer argument expected, got float.*"
134+
]
135+
136+
for context_line in error_context_lines:
137+
for msg in messages_to_ignore:
138+
if msg.lower() in context_line.lower() or \
139+
context_line.lower() in msg.lower():
140+
return
141+
142+
for re_msg in regex_messages:
143+
if re.match(re_msg, context_line):
144+
return
145+
96146
if self._disabled_until is not None:
97147
if datetime.utcnow() < self._disabled_until:
98148
return

0 commit comments

Comments
 (0)