From 730195359231476f02f7c5396fc24b0b5d63b67e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Wed, 18 Dec 2024 16:42:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A5=E5=85=A5=20sentry=20=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ .../vitepress-plugin-github-issues.mts | 1 - pdm.lock | 35 ++++++++++++++++++- pyproject.toml | 1 + xiaomusic.py | 3 +- xiaomusic/cli.py | 34 ++++++++++++++---- xiaomusic/xiaomusic.py | 25 +++++++------ 7 files changed, 80 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b129f91a4..41a40fa46 100644 --- a/README.md +++ b/README.md @@ -335,6 +335,8 @@ docker build -t xiaomusic . - [pure 主题 xiaomusicUI](https://github.com/52fisher/xiaomusicUI) - [移动端的播放器主题](https://github.com/52fisher/XMusicPlayer) - [一个第三方的主题](https://github.com/DarrenWen/xiaomusicui) +- [Umami 统计](https://github.com/umami-software/umami) +- [Sentry 报错监控](https://github.com/getsentry/sentry) - 所有帮忙调试和测试的朋友 - 所有反馈问题和建议的朋友 diff --git a/docs/.vitepress/vitepress-plugin-github-issues.mts b/docs/.vitepress/vitepress-plugin-github-issues.mts index 5c433251a..11ef207a6 100644 --- a/docs/.vitepress/vitepress-plugin-github-issues.mts +++ b/docs/.vitepress/vitepress-plugin-github-issues.mts @@ -146,7 +146,6 @@ function prependToFile(filePath: string, text: string) { function replaceGithubAssetUrls(content: string, githubProxy: string): string { const pattern1 = /https:\/\/github\.com\/[^\/]+\/[^\/]+\/assets\/[\w-]+/g; const pattern2 = /https:\/\/github\.com\/user-attachments\/assets\/[\w-]+/g; - const proxyPrefix = "https://cloudflare-github-proxy.hanxi-info.workers.dev/proxy"; // 使用正则表达式替换符合条件的链接 const transformedContent = content.replace(pattern1, (match) => { diff --git a/pdm.lock b/pdm.lock index 2604627d8..6d42951fc 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev", "lint"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:d22d4b03450cd369683d3ddf827359cd96541ee09e29bfa1fa666d72aa7d3ab0" +content_hash = "sha256:69e5e664520761c67366902346f147c8f750335eb6fb5843277776c1fe439ff3" [[metadata.targets]] requires_python = "==3.10.12" @@ -889,6 +889,39 @@ files = [ {file = "ruff-0.8.1.tar.gz", hash = "sha256:3583db9a6450364ed5ca3f3b4225958b24f78178908d5c4bc0f46251ccca898f"}, ] +[[package]] +name = "sentry-sdk" +version = "2.19.2" +requires_python = ">=3.6" +summary = "Python client for Sentry (https://sentry.io)" +groups = ["default"] +marker = "python_full_version == \"3.10.12\"" +dependencies = [ + "certifi", + "urllib3>=1.26.11", +] +files = [ + {file = "sentry_sdk-2.19.2-py2.py3-none-any.whl", hash = "sha256:ebdc08228b4d131128e568d696c210d846e5b9d70aa0327dec6b1272d9d40b84"}, + {file = "sentry_sdk-2.19.2.tar.gz", hash = "sha256:467df6e126ba242d39952375dd816fbee0f217d119bf454a8ce74cf1e7909e8d"}, +] + +[[package]] +name = "sentry-sdk" +version = "2.19.2" +extras = ["fastapi"] +requires_python = ">=3.6" +summary = "Python client for Sentry (https://sentry.io)" +groups = ["default"] +marker = "python_full_version == \"3.10.12\"" +dependencies = [ + "fastapi>=0.79.0", + "sentry-sdk==2.19.2", +] +files = [ + {file = "sentry_sdk-2.19.2-py2.py3-none-any.whl", hash = "sha256:ebdc08228b4d131128e568d696c210d846e5b9d70aa0327dec6b1272d9d40b84"}, + {file = "sentry_sdk-2.19.2.tar.gz", hash = "sha256:467df6e126ba242d39952375dd816fbee0f217d119bf454a8ce74cf1e7909e8d"}, +] + [[package]] name = "sniffio" version = "1.3.1" diff --git a/pyproject.toml b/pyproject.toml index a1568f045..d278a6af2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ dependencies = [ "pillow>=10.4.0", "python-multipart>=0.0.12", "requests>=2.32.3", + "sentry-sdk[fastapi]>=2.19.2", ] requires-python = ">=3.10,<=3.12" readme = "README.md" diff --git a/xiaomusic.py b/xiaomusic.py index a914b3deb..889a48733 100644 --- a/xiaomusic.py +++ b/xiaomusic.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 -from xiaomusic.cli import main if __name__ == "__main__": + from xiaomusic.cli import main + main() diff --git a/xiaomusic/cli.py b/xiaomusic/cli.py index 1fca6cf9a..abc292a25 100644 --- a/xiaomusic/cli.py +++ b/xiaomusic/cli.py @@ -1,16 +1,13 @@ #!/usr/bin/env python3 import argparse import json +import logging import os import signal -import uvicorn - -from xiaomusic import __version__ -from xiaomusic.config import Config -from xiaomusic.httpserver import HttpInit -from xiaomusic.httpserver import app as HttpApp -from xiaomusic.xiaomusic import XiaoMusic +import sentry_sdk +from sentry_sdk.integrations.asyncio import AsyncioIntegration +from sentry_sdk.integrations.logging import LoggingIntegration LOGO = r""" __ __ _ __ __ _ @@ -22,7 +19,30 @@ """ +sentry_sdk.init( + dsn="https://659690a901a37237df8097a9eb95e60f@github.hanxi.cc/sentry/4508470200434688", + traces_sample_rate=0.1, + profiles_sample_rate=0.05, + integrations=[ + AsyncioIntegration(), + LoggingIntegration( + level=logging.WARNING, + event_level=logging.ERROR, + ), + ], + # debug=True, +) + + def main(): + import uvicorn + + from xiaomusic import __version__ + from xiaomusic.config import Config + from xiaomusic.httpserver import HttpInit + from xiaomusic.httpserver import app as HttpApp + from xiaomusic.xiaomusic import XiaoMusic + parser = argparse.ArgumentParser() parser.add_argument( "--port", diff --git a/xiaomusic/xiaomusic.py b/xiaomusic/xiaomusic.py index 8186a1db5..67ae4d947 100644 --- a/xiaomusic/xiaomusic.py +++ b/xiaomusic/xiaomusic.py @@ -221,16 +221,19 @@ async def init_all_data(self, session): self.cookie_jar = session.cookie_jar async def login_miboy(self, session): - account = MiAccount( - session, - self.config.account, - self.config.password, - str(self.mi_token_home), - ) - # Forced login to refresh to refresh token - await account.login("micoapi") - self.mina_service = MiNAService(account) - self.miio_service = MiIOService(account) + try: + account = MiAccount( + session, + self.config.account, + self.config.password, + str(self.mi_token_home), + ) + # Forced login to refresh to refresh token + await account.login("micoapi") + self.mina_service = MiNAService(account) + self.miio_service = MiIOService(account) + except Exception as e: + self.log.warning(f"可能登录失败. {e}") async def try_update_device_id(self): try: @@ -254,7 +257,7 @@ async def try_update_device_id(self): self.config.devices = devices self.log.info(f"选中的设备: {devices}") except Exception as e: - self.log.exception(f"Execption {e}") + self.log.warning(f"可能登录失败. {e}") def get_cookie(self): if self.config.cookie: