Migrate from Raven

Learn about migrating from raven to sentry-python

This guide describes the common patterns involved in migrating from raven-python to the sentry-python SDK.

The installation is now the same regardless of framework or library you integrate with. There are no alternative initialization routines other than sentry_sdk.init. For integration-specific instructions please refer to our list of guides for the new SDK.

Old:

Copied
import raven
client = raven.Client("https://examplePublicKey@o0.ingest.sentry.io/0", release="1.3.0")

New:

Copied
import sentry_sdk
sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    release="1.3.0",
)

Old:

Copied
client.tags_context({'key': 'value'})

New:

Copied
sentry_sdk.set_tag('key', 'value')

Old:

Copied
try:
    throwing_function()
except Exception:
    client.captureException(extra={'debug': False})

New:

Copied
with sentry_sdk.push_scope() as scope:
    scope.set_extra('debug', False)

    try:
        throwing_function()
    except Exception as e:
        sentry_sdk.capture_exception(e)

Old:

Copied
client.captureMessage('test', level='info', extra={'debug': False})

New:

Copied
with sentry_sdk.push_scope() as scope:
    scope.set_extra('debug', False)
    sentry_sdk.capture_message('test', 'info')

Old:

Copied
from raven import breadcrumbs

breadcrumbs.record(
    message='Item added to shopping cart',
    category='action',
    data={
        'isbn': '978-1617290541',
        'cartSize': '3'
    }
)

New:

Copied
sentry_sdk.add_breadcrumb(
  message='Item added to shopping cart',
  category='action',
  data={
    'isbn': '978-1617290541',
    'cartSize': '3'
  }
)

Raven used to have a few built-in heuristics to detect password fields and creditcard numbers. Since those heuristics were the same for everybody, it was impossible to further improve them for a usecase without breaking somebody else's usecase. There is no easy search-and-replace type solution in the new SDK.

We encourage you to consider alternative options outlined at Filtering Events.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").