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.2.1.tar.gz (6.5 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.2.1.tar.gz.

File metadata

  • Download URL: nonebot_plugin_sentry_transaction-0.2.1.tar.gz
  • Upload date:
  • Size: 6.5 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.2.1.tar.gz
Algorithm Hash digest
SHA256 59d9f0a41c4452710038a66e0a098f8de765bcd1570baced8cf2965f44af1c1e
MD5 7bc2012504e7a5f138bb1ba9e4d901c3
BLAKE2b-256 2c735fcf3eef5039d4502516c6c4634d5d34d32c27fe16939298cedf21a32e98

See more details on using hashes here.

File details

Details for the file nonebot_plugin_sentry_transaction-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: nonebot_plugin_sentry_transaction-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 265dc33f40fdc40835249d23d2368815b79362872a091ecd1aeac6248f12adb3
MD5 5482c90decc242fca3405989cfb2d536
BLAKE2b-256 a5794fdab25cc1a15e9775b1e0b7616d91160f5b0ca568ecdb25f688708bf5e1

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