KEMBAR78
# Python | Sentry for Python ## [Prerequisites](https://docs.sentry.io/platforms/python.md#prerequisites) * You need a Sentry [account](https://sentry.io/signup/) and [project](https://docs.sentry.io/product/projects.md) * Read one of our dedicated guides if you use any of the [frameworks](https://docs.sentry.io/platforms/python/integrations.md#web-frameworks) we support ## [Features](https://docs.sentry.io/platforms/python.md#features) Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below. Error Monitoring\[ ]Logs\[ ]Tracing\[ ]Profiling ## [Install](https://docs.sentry.io/platforms/python.md#install) Install the Sentry SDK using [`pip`](https://pip.pypa.io/en/stable/): ```bash pip install "sentry-sdk" ``` ## [Configure](https://docs.sentry.io/platforms/python.md#configure) Configuration should happen as **early as possible** in your application's lifecycle. ```python import sentry_sdk sentry_sdk.init( dsn="https://examplePublicKey@o0.ingest.sentry.io/0", # Add request headers and IP for users, # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info send_default_pii=True, # performance # Set traces_sample_rate to 1.0 to capture 100% # of transactions for tracing. traces_sample_rate=1.0, # performance # profiling # To collect profiles for all profile sessions, # set `profile_session_sample_rate` to 1.0. profile_session_sample_rate=1.0, # Profiles will be automatically collected while # there is an active span. profile_lifecycle="trace", # profiling # logs # Enable logs to be sent to Sentry enable_logs=True, # logs ) ``` In async programs, it's recommended to call `sentry_sdk.init()` inside an `async` function to ensure async code is instrumented properly. If possible, we recommend calling `sentry_sdk.init()` at the beginning of the first `async` function you call. ```python import asyncio import sentry_sdk async def main(): sentry_sdk.init( ... # same as above ) asyncio.run(main()) ``` ## [Verify](https://docs.sentry.io/platforms/python.md#verify) Add this intentional error to your application to test that everything is working right away. ```py division_by_zero = 1 / 0 ``` Learn more about manually capturing an error or message in our [Usage documentation](https://docs.sentry.io/platforms/python/usage.md). To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved. Not seeing your error in Sentry? Make sure you're running the above example from a file and not from a Python shell like IPython.