Skip to main content

Python client for Sentry (https://getsentry.com)

Project description

sentry-python - Sentry SDK for PythonBuild StatusSentry-Python is an experimental SDK for Sentry. For a stable one, useraven.## Getting started with the new Sentry SDK for PythonInstall this package with pip install sentry-sdk. Then, in your code: import sentry_sdk sentry_sdk.init(dsn="https://foo@sentry.io/123")After initialization, you can capture exceptions like this: sentry_sdk.capture_exception(ValueError()) try: raise ValueError() except Exception: sentry_sdk.capture_exception()...or send messages: sentry_sdk.capture_message("Hi Sentry!")## Scopes (contexts, tags)You can create a scope to attach data to all events happening inside of it: with sentry_sdk.get_current_hub().push_scope(): with sentry_sdk.configure_scope() as scope: scope.transaction = "my_view_name" scope.set_tag("key", "value") scope.user = {"id": 123} # ValueError event will have all that data attached capture_exception(ValueError()) # This one not since it is outside of the context manager capture_exception(ValueError())Scopes can be nested. If you call push_scope inside of thewith-statement again, that scope will be pushed onto a stack. It will alsoinherit all data from the outer scope.### Scopes in unconfigured environmentsIf you never call init, no data will ever get sent to any server. In suchsituations, code like this is essentially deadweight: with sentry_sdk.configure_scope() as scope: scope.user = _get_user_data()Sentry-Python supports an alternative syntax for configuring a scope thatsolves this problem: @sentry_sdk.configure_scope def _(scope): scope.user = _get_user_data()Your function will just not be executed if there is no client configured.In your testing and development environment you still might want to run thatcode without sending any events. In that case, simply call init without aDSN: sentry_sdk.init()### BreadcrumbsBreadcrumbs also live on the stack. By default any (non-debug) log messageanywhere in your system ends up as a breadcrumb, see the loggingdocs for more information. You can, however, also createbreadcrumbs manually: sentry_sdk.add_breadcrumb({ # "ty": "log", # "level": "debug", # "category": "myapp.models", "message": "hi" })## Concurrency* Sentry-Python currently does not support gevent-based setups.* On init, Sentry-Python spawns a thread on its own. That means if you use uwsgi, you currently need to enable threads.* On Python 3.7, Sentry-Python supports and automatically uses ContextVars. This should effectively enable Sentry-Python to work with asyncio under that Python version.## PIICurrently Sentry-Python does not send any personally-identifiable user datawith events by default. You need to explicitly enable this behavior with thesend_default_pii option passed to init: init(..., send_default_pii=True)## IntegrationsHead over to the other pages to check out integrations, which usethese low-level APIs so you don't have to.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sentry-sdk-0.1.0rc5.tar.gz (17.0 kB view hashes)

Uploaded Source

Built Distribution

sentry_sdk-0.1.0rc5-py2.py3-none-any.whl (20.4 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page