Python

Sentry 的 Python SDK 可以自动报告应用程序中的错误和性能数据。

  • 您需要一个 Sentry 账户项目
  • 如果您使用我们支持的任何 框架,请阅读我们专门的指南

选择您希望安装的 Sentry 功能(除了错误监控之外),以获取相应的安装和配置说明。

使用 pip 安装 Sentry SDK:

Copied
pip install --upgrade sentry-sdk

配置应尽可能早地在应用程序的生命周期中进行。

Copied
import sentry_sdk

sentry_sdk.init(
    dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    traces_sample_rate=1.0,
    # 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,
)

将此有意的错误添加到您的应用程序中,以测试一切是否立即正常工作。

Copied
division_by_zero = 1 / 0

了解更多关于手动捕获错误或消息的内容,请参阅我们的 使用文档

要查看和解决记录的错误,请登录 sentry.io 并选择您的项目。单击错误标题将打开一个页面,您可以在其中查看详细信息并将其标记为已解决。

在 Sentry 中看不到您的错误?请确保您是从文件中运行上述示例,而不是从 IPython 等 Python shell 中运行。