A sentry extension integrates DingTalk robot webhook
Project description
中文 | English
Sentry 集成钉钉机器人通知插件 (Sentry DingTalk Integration)
✨ 特性 (Features)
- 异常通知: 发送 Sentry 捕获的异常通知到钉钉群。
- 关键字过滤:
- 自定义关键字: 为每个 Sentry 项目设置自定义前缀,便于在钉钉中快速识别(也用于满足钉钉机器人的安全设置要求)。
- 包含/排除规则: 支持配置“包含关键字”和“排除关键字”,精确控制哪些报错需要发送通知。
- 环境配置: 支持通过环境变量预配置缺省值。
📦 安装 (Installation)
1. 使用 pip 安装
pip install sentry-dingtalk-notify
2. 通过 requirements.txt 安装 (推荐 Docker/On-Premise)
在你的 Sentry 自定义构建目录 (onpremise/sentry/) 下的 requirements.txt 中添加:
sentry-dingtalk-notify
然后重新构建并启动 Sentry:
./install.sh
docker-compose up -d
⚙️ 配置 (Configuration)
1. 全局环境变量 (可选)
可以在 sentry.conf.py 或环境变量中设置默认值:
DINGTALK_WEBHOOK: 默认钉钉 Webhook URLDINGTALK_CUSTOM_KEYWORD: 默认自定义前缀DINGTALK_INCLUDE_KEYWORDS: 默认包含关键字 (逗号分隔)DINGTALK_EXCLUDE_KEYWORDS: 默认排除关键字 (逗号分隔)
2. 项目级配置 (Project Settings)
进入 Sentry 项目面板 -> Settings -> Integrations -> DingTalk Notify:
| 选项 | 说明 | 示例 |
|---|---|---|
| Webhook | [必填] 钉钉机器人的 Webhook 地址 | https://oapi.dingtalk.com/robot/send?access_token=xxx |
| Custom Keyword | [选填] 自定义前缀。如果钉钉机器人设置了关键字安全策略,此处必须包含该关键字。 | [Sentry Alert] |
| Include Keywords | [选填] 包含关键字。如果设置,只有错误标题或内容中包含其中任意一个关键字时,才会发送通知。(逗号分隔) | Critical, Production |
| Exclude Keywords | [选填] 排除关键字。如果错误标题或内容中包含其中任意一个关键字,将不会发送通知。(逗号分隔) | Timeout, 404 Not Found |
注意: 排除关键字的优先级高于包含关键字。
🛠 开发与测试 (Development & Testing)
运行单元测试
pip install -r requirements-test.txt # (如果需要)
python3 tests/test_plugin_logic.py
手动发送真实通知测试
编辑 tests/manual_test_dingtalk.py,填入你的真实 Webhook URL,然后运行:
python3 tests/manual_test_dingtalk.py
🚀 发布指南 (Publishing)
本项目包含自动化发布流程。
1. 发布到 TestPyPI (测试环境)
你可以使用脚本手动发布测试版本:
./scripts/publish_test.sh
或者在 GitHub Actions 中手动触发 Upload Python Package to TestPyPI workflow。
2. 发布到 PyPI (正式环境 - Trusted Publishing)
自动化: 当你在 GitHub 上创建一个新的 Release 时,GitHub Actions 会自动构建并发布到 PyPI。
配置 Trusted Publishing (推荐): 这是目前最安全的方式(类似 npm 的 OIDC),无需在 GitHub 保存长效 Token。
- 登录 PyPI。
- 进入 Publishing 设置页面。
- 添加一个新的 Trusted Publisher。
- 填写你的 GitHub 仓库信息:
- Owner:
你的GitHub用户名 - Repository:
sentry-dingtalk-notify - Workflow name:
publish.yml - Environment: (留空)
- Owner:
- 提交代码并打 tag,或在 GitHub Release 页面发布新版本,Actions 将自动鉴权并发布。
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
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 sentry_dingtalk_notify-1.1.1.tar.gz.
File metadata
- Download URL: sentry_dingtalk_notify-1.1.1.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef73f04fb6e42ccc6fc0dba7a6ff3b736c3484ab9f6c4e1801a1ee401846c7d8
|
|
| MD5 |
e6c6b6cb3380660a79d0fe9546bef67a
|
|
| BLAKE2b-256 |
be1d5427dfd10cbe36e8be42def9aca05722375fe0921d525d1023a3df928c60
|
Provenance
The following attestation bundles were made for sentry_dingtalk_notify-1.1.1.tar.gz:
Publisher:
publish.yml on lanxuexing/sentry-dingtalk-notify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sentry_dingtalk_notify-1.1.1.tar.gz -
Subject digest:
ef73f04fb6e42ccc6fc0dba7a6ff3b736c3484ab9f6c4e1801a1ee401846c7d8 - Sigstore transparency entry: 833778307
- Sigstore integration time:
-
Permalink:
lanxuexing/sentry-dingtalk-notify@ea32f63e03b775ee359131a656931df6e546aa92 -
Branch / Tag:
refs/tags/1.1.1 - Owner: https://github.com/lanxuexing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea32f63e03b775ee359131a656931df6e546aa92 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sentry_dingtalk_notify-1.1.1-py2.py3-none-any.whl.
File metadata
- Download URL: sentry_dingtalk_notify-1.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5eae0884efb0b45b7f135b3b165b61be6e6b0674fd093c121a60457df15eec0e
|
|
| MD5 |
70ec4da820becd2660a1e8416ec2a8f3
|
|
| BLAKE2b-256 |
f7c1849709c442dbb32cf3d49e1beb85d3c4d0fc2cd7053e43f62de0abc7cd49
|
Provenance
The following attestation bundles were made for sentry_dingtalk_notify-1.1.1-py2.py3-none-any.whl:
Publisher:
publish.yml on lanxuexing/sentry-dingtalk-notify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sentry_dingtalk_notify-1.1.1-py2.py3-none-any.whl -
Subject digest:
5eae0884efb0b45b7f135b3b165b61be6e6b0674fd093c121a60457df15eec0e - Sigstore transparency entry: 833778310
- Sigstore integration time:
-
Permalink:
lanxuexing/sentry-dingtalk-notify@ea32f63e03b775ee359131a656931df6e546aa92 -
Branch / Tag:
refs/tags/1.1.1 - Owner: https://github.com/lanxuexing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea32f63e03b775ee359131a656931df6e546aa92 -
Trigger Event:
release
-
Statement type: