-
Notifications
You must be signed in to change notification settings - Fork 17
增加sentry的开发环境和远程环境判断,以及版本上报 #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0fe1b53
6f20886
db590a3
109ef7d
85f2368
2d82f70
28feef5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,26 +38,28 @@ def main(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.remove() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| configure_logging() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if VERSION != "v0.0.0": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| send_default_pii=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enable_logs=True, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # 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, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+50
to
+62
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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, | |
| ) | |
| # 在开发环境中不初始化 Sentry,以避免将开发错误上报到生产日志 | |
| if environment != "development": | |
| 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, | |
| ) |
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'enable_logs' parameter has been removed from the Sentry initialization. This was explicitly enabled in the previous code and its removal may affect log forwarding to Sentry. If this was intentional, ensure that log reporting still works as expected. If it was removed accidentally, it should be restored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The environment detection logic is flawed. This checks if the string "0.0.0" appears anywhere in VERSION, which means a production version like "v10.0.0" or "v2.0.0.1" would incorrectly be classified as "development" because they contain "0.0.0" as a substring. Consider using an exact equality check instead:
environment = "development" if VERSION == "v0.0.0" else "production"