-
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
Conversation
# Conflicts: # main.py
…ved configuration
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.
Pull request overview
This pull request modifies the Sentry error tracking integration to automatically detect the environment (development vs production) and include version information in error reports. The changes remove the conditional that previously prevented Sentry initialization during development.
Changes:
- Added automatic environment detection based on VERSION string
- Configured Sentry to always initialize with environment and release fields
- Removed the conditional that skipped Sentry initialization when VERSION was "v0.0.0"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| enable_logs=True, | ||
| ) | ||
| # Sentry 环境与版本号自动识别 | ||
| environment = "development" if "0.0.0" in VERSION else "production" |
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 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"
| environment = "development" if "0.0.0" in VERSION else "production" | |
| environment = "development" if VERSION == "v0.0.0" else "production" |
| 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.
Sentry is now initialized unconditionally, even in development environments with VERSION="v0.0.0". The previous code prevented Sentry initialization during development to avoid polluting production error logs with development errors. This change means development errors will now be sent to Sentry, which may not be desired. Consider adding a conditional check to skip Sentry initialization entirely when in development mode, or provide a way to disable Sentry through configuration.
| 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, | |
| ) |
| 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.
This pull request updates the Sentry integration in
main.pyto improve environment and version detection. The changes make Sentry reporting more accurate by automatically setting the environment and release fields based on the application version.Sentry integration improvements:
developmentorproduction) based on theVERSIONstring.releasefield and set theenvironmentfield accordingly.