Skip to content

Conversation

@WSXYT
Copy link
Collaborator

@WSXYT WSXYT commented Jan 11, 2026

This pull request updates the Sentry integration in main.py to 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:

  • Added automatic detection of the Sentry environment (development or production) based on the VERSION string.
  • Configured Sentry to include the application version in the release field and set the environment field accordingly.

Copilot AI review requested due to automatic review settings January 11, 2026 07:29
Copy link
Contributor

Copilot AI left a 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"
Copy link

Copilot AI Jan 11, 2026

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"

Suggested change
environment = "development" if "0.0.0" in VERSION else "production"
environment = "development" if VERSION == "v0.0.0" else "production"

Copilot uses AI. Check for mistakes.
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,
)
Copy link

Copilot AI Jan 11, 2026

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.

Suggested change
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 uses AI. Check for mistakes.
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,
)
Copy link

Copilot AI Jan 11, 2026

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.

Copilot uses AI. Check for mistakes.
@lzy98276 lzy98276 merged commit 50df05f into SECTL:master Jan 11, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants