Non-invasive Sentry tracing for NoneBot events and matchers
Project description
📖 功能特性
- 每个事件产生一个 Sentry Transaction(
op: nonebot.event) - 每次 Matcher 运行产生一个 Sentry Span(
op: nonebot.matcher) - 并发事件拥有独立 trace,互不干扰
- 同优先级并发 Matcher 拥有独立 span
- httpx / SQLAlchemy / aiohttp 等集成的子 span 自动挂载
- Matcher 异常反映为
internal_errorspan 状态
🔧 前置条件
本插件不负责初始化 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 许可证开源。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonebot_plugin_sentry_transaction-0.1.0.tar.gz.
File metadata
- Download URL: nonebot_plugin_sentry_transaction-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62f5656bd8e4bc9f9956920bfea378c9ad10da90b08c64e2a9148c09dfae5560
|
|
| MD5 |
96fe2a3f74e8b1097c5b828e570dfff6
|
|
| BLAKE2b-256 |
12f09e7c4483617d4316ec81e85cf92ecfe6b70a21f1137f20246dd8f8217e0c
|
File details
Details for the file nonebot_plugin_sentry_transaction-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nonebot_plugin_sentry_transaction-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47a87aed46f08bc7ca522ef7c612923533b695216020dc8f41481b815649fe39
|
|
| MD5 |
0bdfdda608787e4982b6200800b67836
|
|
| BLAKE2b-256 |
397235a0a52ad5409ee855d61a0626eac9737cb5211182428d7d87c7b6c8ed89
|