Skip to content

Commit 315c092

Browse files
committed
save crash to file
1 parent 7c40425 commit 315c092

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

selfdrive/sentry.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import sentry_sdk
33
from enum import Enum
44
from sentry_sdk.integrations.threading import ThreadingIntegration
5+
import os
6+
from datetime import datetime
7+
import shutil
8+
import traceback
59

610
from common.params import Params
711
from selfdrive.athena.registration import is_registered_device
@@ -12,6 +16,8 @@
1216

1317
from common.op_params import opParams
1418

19+
CRASHES_DIR = '/data/community/crashes'
20+
1521

1622
class SentryProject(Enum):
1723
# python project
@@ -31,6 +37,7 @@ def report_tombstone(fn: str, message: str, contents: str) -> None:
3137

3238

3339
def capture_exception(*args, **kwargs) -> None:
40+
save_exception(traceback.format_exc())
3441
cloudlog.error("crash", exc_info=kwargs.get('exc_info', 1))
3542

3643
try:
@@ -44,12 +51,23 @@ def set_tag(key: str, value: str) -> None:
4451
sentry_sdk.set_tag(key, value)
4552

4653

54+
def save_exception(exc_text):
55+
log_file = '{}/{}'.format(CRASHES_DIR, datetime.now().strftime('%Y-%m-%d--%H:%M.log'))
56+
with open(log_file, 'w') as f:
57+
f.write(exc_text)
58+
shutil.copyfile(log_file, '{}/latest.log'.format(CRASHES_DIR))
59+
print('Logged current crash to {} and {}'.format(log_file, '{}/latest.log'.format(CRASHES_DIR)))
60+
61+
4762
def init(project: SentryProject) -> None:
4863
fork_remote = is_fork_remote() and "sshane" in get_origin(default="")
4964
# only report crashes to fork maintainer's sentry repo, skip native project
5065
if not fork_remote or not is_registered_device() or PC or project == SentryProject.SELFDRIVE_NATIVE:
5166
return
5267

68+
if not os.path.exists(CRASHES_DIR):
69+
os.makedirs(CRASHES_DIR)
70+
5371
env = "release" if is_tested_branch() else "master"
5472
dongle_id = Params().get("DongleId", encoding='utf-8')
5573

0 commit comments

Comments
 (0)