Skip to content

Latest commit

 

History

History
100 lines (72 loc) · 2.78 KB

index.mdx

File metadata and controls

100 lines (72 loc) · 2.78 KB
title description caseStyle supportLevel sdk showIntegrationsInSearch categories
Python
Sentry's Python SDK enables automatic reporting of errors and performance data in your application.
snake_case
production
sentry.python
true
server
serverless

Prerequisites

  • You need a Sentry account and project
  • Read one of our dedicated guides if you use any of the frameworks we support

Features

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

<OnboardingOptionButtons options={[ 'error-monitoring', 'performance', 'profiling', ]} />

Install

Install the Sentry SDK using pip:

pip install --upgrade sentry-sdk

Configure

Configuration should happen as early as possible in your application's lifecycle.

import sentry_sdk

sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    # 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,
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ profiling
    # Set profiles_sample_rate to 1.0 to profile 100%
    # of sampled transactions.
    # We recommend adjusting this value in production.
    profiles_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ profiling
)

However, in async applications, you need to call sentry_sdk.init() inside an async function to ensure async code is instrumented properly. We recommend calling sentry_sdk.init() at the beginning of the first async function you call, as demonstrated in the example below.

import asyncio
import sentry_sdk

async def main():
    sentry_sdk.init(
        ...  # same as above
    )

asyncio.run(main())

Verify

Add this intentional error to your application to test that everything is working right away.

division_by_zero = 1 / 0

Learn more about manually capturing an error or message in our Usage documentation.

To view and resolve the recorded error, log into 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.