From 9aaa6cb51e991f0a9559fbbf641769cfdaba7112 Mon Sep 17 00:00:00 2001 From: wsxyt Date: Sun, 11 Jan 2026 15:41:22 +0800 Subject: [PATCH] fix(sentry): limit Sentry initialization to development environment --- main.py | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index 702f498b..fceb92c2 100644 --- a/main.py +++ b/main.py @@ -38,28 +38,26 @@ def main(): logger.remove() configure_logging() - # Sentry 环境与版本号自动识别 - environment = "development" if "0.0.0" in VERSION else "production" - - def before_send(event, hint): - # 如果事件中不包含异常信息(即没有堆栈),则不上传 - if "exception" not in event: - return None - return event - - sentry_sdk.init( - dsn="https://f48074b49e319f7b952583c283046259@o4510289605296128.ingest.de.sentry.io/4510681366659152", - integrations=[ - LoguruIntegration( - level=LoggingLevels.INFO.value, - event_level=LoggingLevels.ERROR.value, - ), - ], - before_send=before_send, - environment=environment, - release=VERSION, - send_default_pii=True, - ) + # 仅在开发环境(版本号包含 0.0.0)下初始化 Sentry + if "0.0.0" in VERSION: + def before_send(event, hint): + # 如果事件中不包含异常信息(即没有堆栈),则不上传 + if "exception" not in event: + return None + return event + + sentry_sdk.init( + dsn="https://f48074b49e319f7b952583c283046259@o4510289605296128.ingest.de.sentry.io/4510681366659152", + integrations=[ + LoguruIntegration( + level=LoggingLevels.INFO.value, + event_level=LoggingLevels.ERROR.value, + ), + ], + before_send=before_send, + release=VERSION, + send_default_pii=True, + ) wm.app_start_time = time.perf_counter()