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.0.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.0.tar.gz.

File metadata

  • Download URL: nonebot_plugin_sentry_transaction-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 8fba5b93c1748bd4c86a0915222ec465200c55681c931b8f31454695d60b109d
MD5 e2287ec7c04c4aa6f2b4d68ff180901e
BLAKE2b-256 6b1f2e0118c5828ac28a3f3e22a6455737f0678b3eac5e91c7c7cd0c873e5331

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nonebot_plugin_sentry_transaction-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fd70899304fd54a78da96f35f6b9fed0948d57d60f002f0536284e569c98458f
MD5 514b6bc0883713dc77cbcabd4f3f21df
BLAKE2b-256 ea4f89cdb3bc1ab2f225de57e152460e0f73ee8bbaf7d88bcbb77931928bd575

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