If you want to move to the new sentry-python SDK we provided a short guide here of the most common patterns:
Migration
Here are some examples of how the new SDKs work. Please note that the API for all Python SDKs is the same.
Installation
Old :
import raven
client = raven.Client('___PUBLIC_DSN___', release="1.3.0")
New :
import sentry_sdk
sentry_sdk.init('___PUBLIC_DSN___', release='1.3.0')
Set a global tag
Old :
client.tags_context({'key': 'value'})
New :
with sentry_sdk.configure_scope() as scope:
scope.set_tag('key', 'value')
Capture custom exception
Old :
try:
throwing_function()
except Exception:
client.captureException(extra={'debug': False})
New :
try:
throwing_function()
except Exception as e:
with sentry_sdk.push_scope() as scope:
scope.set_extra('debug', False)
sentry_sdk.capture_exception(e)
Capture a message
Old :
client.captureMessage('test', level='info', extra={'debug': False})
New :
with sentry_sdk.push_scope() as scope:
scope.set_extra('debug', False)
sentry_sdk.capture_message('test', 'info')
Breadcrumbs
Old :
from raven import breadcrumbs import
breadcrumbs.record(
message='Item added to shopping cart',
category='action',
data={
'isbn': '978-1617290541',
'cartSize': '3'
}
)
New :
sentry_sdk.add_breadcrumb(
message='Item added to shopping cart',
category='action',
data={
'isbn': '978-1617290541',
'cartSize': '3'
}
)