22import sentry_sdk
33from enum import Enum
44from sentry_sdk .integrations .threading import ThreadingIntegration
5+ import os
6+ from datetime import datetime
7+ import shutil
8+ import traceback
59
610from common .params import Params
711from selfdrive .athena .registration import is_registered_device
1216
1317from common .op_params import opParams
1418
19+ CRASHES_DIR = '/data/community/crashes'
20+
1521
1622class SentryProject (Enum ):
1723 # python project
@@ -31,6 +37,7 @@ def report_tombstone(fn: str, message: str, contents: str) -> None:
3137
3238
3339def 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+
4762def 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