1. 前言
sentry使用时间长了,容易产生很多不再care的issues,如何批量resolve它们,本文重点介绍。
对于上述情况,官方建议重建一个project,但是,重建project,需要修改product环境的sentry-dsn,可能还需要重启服务,有点得不偿失。
https://forum.sentry.io/t/delete-all-issues-in-a-project/45
所以,本文将采用sentry api的方式,clean所有issues。
2. 创建一个Auth Token
不同版本的sentry,创建token的page不太一样,不过path基本不变。下图供参考。
3. 基于Sentry API开发脚本
https://docs.sentry.io/api/events/get-project-group-index/
import requests
from functools import reduce
SENTRY_API_HEADERS = dict(
Authorization="Bearer e5bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1e"
)
def get_issues():
url = "https://sentry.xxxxxx.cn/api/0/projects/project-slug/azure_blackeye/issues/"
resp = requests.get(url, headers=SENTRY_API_HEADERS, data=dict(statsPeriod='14d'))
return [issue['id'] for issue in resp.json()]
def resolve_issues(ids):
url = "https://sentry.xxxxxx.cn/api/0/projects/project-slug/azure_blackeye/issues/?status=unresolved&id="
url += reduce(lambda x, y: f'{x}&id={y}', ids)
requests.put(url, headers=SENTRY_API_HEADERS, json=dict(status="resolved"))
if __name__ == "__main__":
for index in range(0, 10000):
issues = get_issues()
print(f'page index: {index:04d}, issues count: {len(issues)}')
if len(issues) == 0:
print('deal over')
break
resolve_issues(issues)