Skip to main content
logo

nonebot-plugin-sentry-transaction

✨ NoneBot2 事件与 Matcher 的非侵入式 Sentry 性能追踪 ✨

Python PyPI uv Ruff License CI Codecov


简体中文 | English

📖 功能特性

  • 每个事件产生一个 Sentry Transaction(op: nonebot.event)
  • 每次 Matcher 运行产生一个 Sentry Span(op: nonebot.matcher)
  • 并发事件拥有独立 trace,互不干扰
  • 同优先级并发 Matcher 拥有独立 span
  • httpx / SQLAlchemy / aiohttp 等集成的子 span 自动挂载
  • Matcher 异常反映为 internal_error span 状态

🔧 前置条件

本插件不负责初始化 Sentry,请配合 nonebot-plugin-sentry 使用:

SENTRY_DSN=https://<key>@<org>.ingest.sentry.io/<project>
SENTRY_TRACES_SAMPLE_RATE=1.0

其他 Sentry 配置项请参阅 nonebot-plugin-sentry 文档。

💿 安装

🚀 使用 uv

uv add nonebot-plugin-sentry-transaction

🚀 使用 PDM

pdm add nonebot-plugin-sentry-transaction

🚀 使用 Poetry

poetry add nonebot-plugin-sentry-transaction

⚙️ 配置

配置项 默认值 说明
SENTRY_NB_TRACE_ENABLED true 设为 false 可关闭事件/Matcher 追踪,同时保留 Sentry 错误上报。

📊 在 Sentry 中的呈现

Transaction 出现在 Performance 面板,名称来自 event.get_event_name(),例如 message.private.friend、notice.group_upload。

Span 以 Matcher 所属插件命名(plugin_name),回退到 module_name 或类名。

各 transaction/span 携带以下 tag:

Tag 来源
adapter bot.type
event_type event.get_type()
matcher.plugin Matcher.plugin_name
matcher.module Matcher.module_name

🔍 工作原理

插件在加载时 monkey-patch NoneBot 的两个内部函数:

  • nonebot.message.handle_event — 包装 sentry_sdk.isolation_scope() + start_transaction()
  • nonebot.message._run_matcher — 包装 sentry_sdk.new_scope() + start_span()

同时注册 run_postprocessor 钩子,检测被 NoneBot 内部捕获的 Matcher 异常并将 span 状态设为 internal_error。

不修改任何业务插件代码。

📄 许可证

本项目使用 MIT 许可证开源。

Metadata

Release files for nonebot-plugin-sentry-transaction 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-plugin-sentry-transaction 0.2.1
File Size Uploaded Provenance Actions
nonebot_plugin_sentry_transaction-0.2.1.tar.gz 6.5 kB Without provenance Details for nonebot_plugin_sentry_transaction-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-sentry-transaction 0.2.1
File Interpreter ABI Platform Actions
nonebot_plugin_sentry_transaction-0.2.1-py3-none-any.whl Python 3 none any Details for nonebot_plugin_sentry_transaction-0.2.1-py3-none-any.whl

Total release size: 13.2 kB

Release files / nonebot_plugin_sentry_transaction-0.2.1.tar.gz

Download URL nonebot_plugin_sentry_transaction-0.2.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
59d9f0a41c4452710038a66e0a098f8de765bcd1570baced8cf2965f44af1c1e
BLAKE2b-256 checksum
How to use checksums
2c735fcf3eef5039d4502516c6c4634d5d34d32c27fe16939298cedf21a32e98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / nonebot_plugin_sentry_transaction-0.2.1-py3-none-any.whl

Download URL nonebot_plugin_sentry_transaction-0.2.1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
265dc33f40fdc40835249d23d2368815b79362872a091ecd1aeac6248f12adb3
BLAKE2b-256 checksum
How to use checksums
a5794fdab25cc1a15e9775b1e0b7616d91160f5b0ca568ecdb25f688708bf5e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for nonebot-plugin-sentry-transaction 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page