Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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.

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
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
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.

wm.app_start_time = time.perf_counter()

Expand Down
Loading