noneflow[bot] 033c90dd74
Some checks failed
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.10) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.11) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.12) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.9) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.10) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.11) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.12) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.9) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.10) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.11) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.11) (push) Failing after 2s
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.12) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.9) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.10) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.11) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.12) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.9) (push) Waiting to run
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.12) (push) Failing after 6m59s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.10) (push) Failing after 7m7s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.10) (push) Failing after 5m14s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.9) (push) Failing after 5m42s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.11) (push) Failing after 4m51s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.12) (push) Failing after 7m12s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.9) (push) Failing after 6m33s
Pyright Lint / Pyright Lint (pydantic-v1) (push) Failing after 8m12s
Ruff Lint / Ruff Lint (push) Successful in 43s
Pyright Lint / Pyright Lint (pydantic-v2) (push) Failing after 6m56s
Site Deploy / publish (push) Failing after 7m21s
🔖 Release 2.4.1
2024-12-25 07:21:05 +00:00

2.4 KiB
Raw Blame History

sidebar_position description
2 使用 sentry 进行错误跟踪

错误跟踪

在应用实际运行过程中可能会出现各种各样的错误。可能是由于代码逻辑错误也可能是由于用户输入错误甚至是由于第三方服务的错误。这些错误都会导致应用的运行出现问题这时候就需要对错误进行跟踪以便及时发现问题并进行修复。NoneBot 提供了 nonebot-plugin-sentry 插件,支持 sentry 平台,可以方便地进行错误跟踪。

安装插件

在使用前请先安装 nonebot-plugin-sentry 插件至项目环境中,可参考获取商店插件来了解并选择安装插件的方式。如:

项目目录下执行以下命令:

nb plugin install nonebot-plugin-sentry

使用插件

在安装完成之后,仅需要对插件进行简单的配置即可使用。

获取 sentry DSN

前往 sentry 平台,注册并创建一个新的项目,然后在项目设置中找到 Client Keys (DSN),复制其中的 DSN 值。

配置插件

:::caution 注意 错误跟踪通常在生产环境中使用,因此开发环境中 sentry_dsn 留空即会停用插件。 :::

在项目 dotenv 配置文件中添加以下配置即可使用:

SENTRY_DSN=<your_sentry_dsn>

配置项

配置项具体含义参考 Sentry Docs

  • sentry_dsn: str
  • sentry_debug: bool = False
  • sentry_release: str | None = None
  • sentry_release: str | None = None
  • sentry_environment: str | None = nonebot env
  • sentry_server_name: str | None = None
  • sentry_sample_rate: float = 1.
  • sentry_max_breadcrumbs: int = 100
  • sentry_attach_stacktrace: bool = False
  • sentry_send_default_pii: bool = False
  • sentry_in_app_include: List[str] = Field(default_factory=list)
  • sentry_in_app_exclude: List[str] = Field(default_factory=list)
  • sentry_request_bodies: str = "medium"
  • sentry_with_locals: bool = True
  • sentry_ca_certs: str | None = None
  • sentry_before_send: Callable[[Any, Any], Any | None] | None = None
  • sentry_before_breadcrumb: Callable[[Any, Any], Any | None] | None = None
  • sentry_transport: Any | None = None
  • sentry_http_proxy: str | None = None
  • sentry_https_proxy: str | None = None
  • sentry_shutdown_timeout: int = 2