FrogPilot 0.9.7

This commit is contained in:
James
2025-11-01 12:00:00 -07:00
parent bb7cad0a8b
commit fb26eb3d1b
2728 changed files with 844251 additions and 29127 deletions
+61 -14
View File
@@ -1,20 +1,23 @@
"""Install exception handler for process crash."""
import os
import sentry_sdk
import traceback
from datetime import datetime
from enum import Enum
from sentry_sdk.integrations.threading import ThreadingIntegration
from openpilot.common.params import Params
from openpilot.system.athena.registration import is_registered_device
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, params
class SentryProject(Enum):
# python project
SELFDRIVE = "https://6f3c7076c1e14b2aa10f5dde6dda0cc4@o33823.ingest.sentry.io/77924"
SELFDRIVE = os.environ.get("SENTRY_DSN", "")
# native project
SELFDRIVE_NATIVE = "https://3e4b586ed21a4479ad5d85083b639bc6@o33823.ingest.sentry.io/157615"
SELFDRIVE_NATIVE = os.environ.get("SENTRY_DSN", "")
def report_tombstone(fn: str, message: str, contents: str) -> None:
@@ -27,7 +30,24 @@ def report_tombstone(fn: str, message: str, contents: str) -> None:
sentry_sdk.flush()
def capture_exception(*args, **kwargs) -> None:
def capture_block():
with sentry_sdk.push_scope() as scope:
sentry_sdk.capture_message("Blocked user from using the development branch", level='info')
sentry_sdk.flush()
def capture_exception(*args, crash_log=True, **kwargs) -> None:
exc_text = traceback.format_exc()
phrases_to_check = [
"already exists. To overwrite it, set 'overwrite' to True",
"failed after retry",
]
if any(phrase in exc_text for phrase in phrases_to_check):
return
save_exception(exc_text, crash_log)
cloudlog.error("crash", exc_info=kwargs.get('exc_info', 1))
try:
@@ -41,15 +61,44 @@ 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
comma_remote = build_metadata.openpilot.comma_remote and "commaai" in build_metadata.openpilot.git_origin
if not comma_remote or not is_registered_device() or PC:
FrogPilot = "frogai" in build_metadata.openpilot.git_origin.lower()
if not FrogPilot or PC:
return False
env = "release" if build_metadata.tested_channel else "master"
dongle_id = Params().get("DongleId", encoding='utf-8')
short_branch = build_metadata.channel
if short_branch in ["COMMA", "HEAD"]:
return
elif short_branch == "FrogPilot-Development":
env = "Development"
elif build_metadata.release_channel:
env = "Release"
elif short_branch == "FrogPilot-Testing":
env = "Testing"
elif build_metadata.tested_channel:
env = "Staging"
else:
env = short_branch
dongle_id = params.get("DongleId", encoding="utf-8")
installed = params.get("InstallDate", encoding="utf-8")
updated = params.get("Updated", encoding="utf-8")
integrations = []
if project == SentryProject.SELFDRIVE:
@@ -63,14 +112,12 @@ def init(project: SentryProject) -> bool:
max_value_length=8192,
environment=env)
build_metadata = get_build_metadata()
sentry_sdk.set_user({"id": dongle_id})
sentry_sdk.set_tag("dirty", build_metadata.openpilot.is_dirty)
sentry_sdk.set_tag("origin", build_metadata.openpilot.git_origin)
sentry_sdk.set_tag("branch", build_metadata.channel)
sentry_sdk.set_tag("branch", short_branch)
sentry_sdk.set_tag("commit", build_metadata.openpilot.git_commit)
sentry_sdk.set_tag("device", HARDWARE.get_device_type())
sentry_sdk.set_tag("updated", updated)
sentry_sdk.set_tag("installed", installed)
if project == SentryProject.SELFDRIVE:
sentry_sdk.Hub.current.start_session()