Error logs

This commit is contained in:
James
2025-12-02 17:31:58 -07:00
parent ab487baf0e
commit a05c7b8f80
11 changed files with 112 additions and 12 deletions
+19 -1
View File
@@ -2,6 +2,7 @@
import os
import sentry_sdk
import traceback
from datetime import datetime
from enum import Enum
from sentry_sdk.integrations.threading import ThreadingIntegration
@@ -11,6 +12,8 @@ from openpilot.system.hardware import HARDWARE, PC
from openpilot.common.swaglog import cloudlog
from openpilot.system.version import get_build_metadata, get_version
from openpilot.frogpilot.common.frogpilot_variables import ERROR_LOGS_PATH
class SentryProject(Enum):
# python project
@@ -35,7 +38,7 @@ def capture_block() -> None:
sentry_sdk.flush()
def capture_exception(*args, **kwargs) -> None:
def capture_exception(*args, crash_log=True, **kwargs) -> None:
exc_text = traceback.format_exc()
errors_to_ignore = [
@@ -44,6 +47,7 @@ def capture_exception(*args, **kwargs) -> None:
if any(error in exc_text for error in errors_to_ignore):
return
save_exception(exc_text, crash_log)
cloudlog.error("crash", exc_info=kwargs.get('exc_info', 1))
try:
@@ -57,6 +61,20 @@ def set_tag(key: str, value: str) -> None:
sentry_sdk.set_tag(key, value)
def save_exception(exc_text: str, crash_log) -> None:
files = [
ERROR_LOGS_PATH / datetime.now().astimezone().strftime("%Y-%m-%d--%H-%M-%S.log"),
ERROR_LOGS_PATH / "error.txt"
]
for file_path in files:
if file_path.name == "error.txt" and crash_log:
lines = exc_text.splitlines()[-10:]
file_path.write_text("\n".join(lines))
else:
file_path.write_text(exc_text)
def init(project: SentryProject) -> bool:
build_metadata = get_build_metadata()
# forks like to mess with this, so double check