Skip to main content

Non-invasive Sentry tracing for NoneBot events and matchers

Project description

logo

nonebot-plugin-sentry-transaction

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

Python PyPI uv Ruff License CI Codecov


简体中文 | English

📖 功能特性

  • 每个事件产生一个 Sentry Transactionop: nonebot.event
  • 每次 Matcher 运行产生一个 Sentry Spanop: 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.friendnotice.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_sentry_transaction-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Hashes for nonebot_plugin_sentry_transaction-0.1.0.tar.gz
Algorithm Hash digest
SHA256 62f5656bd8e4bc9f9956920bfea378c9ad10da90b08c64e2a9148c09dfae5560
MD5 96fe2a3f74e8b1097c5b828e570dfff6
BLAKE2b-256 12f09e7c4483617d4316ec81e85cf92ecfe6b70a21f1137f20246dd8f8217e0c

See more details on using hashes here.

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

Hashes for nonebot_plugin_sentry_transaction-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47a87aed46f08bc7ca522ef7c612923533b695216020dc8f41481b815649fe39
MD5 0bdfdda608787e4982b6200800b67836
BLAKE2b-256 397235a0a52ad5409ee855d61a0626eac9737cb5211182428d7d87c7b6c8ed89

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page