Skip to content

Commit

Permalink
Use Sentry scope when setting breadcrumbs (#498)
Browse files Browse the repository at this point in the history
We've had a longstanding issue where some of our Sentry errors wind up with a giant pile of accumulated breadcrumbs that seem to be from other requests. I think it might be because we are not creating a scope when manually adding these breadcrumbs for errors, and they aren't getting cleared when you call `capture_message` like they used to in the old SDK.
  • Loading branch information
Mr0grog authored Oct 18, 2019
1 parent d6be738 commit bd1b60e
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions web_monitoring/diffing_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,21 @@ def write_error(self, status_code, **kwargs):
# Pass non-raised (i.e. we manually called `send_error()`), non-user
# errors to Sentry.io.
if actual_error is None and response['code'] >= 500:
# TODO: this breadcrumb should happen at the start of the request
# handler, but we need to test and make sure crumbs are properly
# attached to *this* HTTP request and don't bleed over to others,
# since Sentry's special support for Tornado has been dropped.
headers = dict(self.request.headers)
if 'Authorization' in headers:
headers['Authorization'] = '[removed]'
sentry_sdk.add_breadcrumb(category='request', data={
'url': self.request.full_url(),
'method': self.request.method,
'headers': headers,
})
sentry_sdk.capture_message(f'{self._reason} (status: {response["code"]})')
with sentry_sdk.push_scope():
# TODO: this breadcrumb should happen at the start of the
# request handler, but we need to test and make sure crumbs are
# properly attached to *this* HTTP request and don't bleed over
# to others, since Sentry's special support for Tornado has
# been dropped.
headers = dict(self.request.headers)
if 'Authorization' in headers:
headers['Authorization'] = '[removed]'
sentry_sdk.add_breadcrumb(category='request', data={
'url': self.request.full_url(),
'method': self.request.method,
'headers': headers,
})
sentry_sdk.capture_message(f'{self._reason} (status: {response["code"]})')

# Fill in full info if configured to do so
if self.settings.get('serve_traceback') and 'exc_info' in kwargs:
Expand Down

0 comments on commit bd1b60e

Please sign in to comment.