You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					79 lines
				
				2.7 KiB
			
		
		
			
		
	
	
					79 lines
				
				2.7 KiB
			| 
											4 years ago
										 | """Install exception handler for process crash."""
 | ||
|  | import sentry_sdk
 | ||
|  | from enum import Enum
 | ||
|  | from sentry_sdk.integrations.threading import ThreadingIntegration
 | ||
|  | 
 | ||
| 
											2 years ago
										 | from openpilot.common.params import Params
 | ||
| 
											1 year ago
										 | from openpilot.system.athena.registration import is_registered_device
 | ||
| 
											2 years ago
										 | from openpilot.system.hardware import HARDWARE, PC
 | ||
| 
											2 years ago
										 | from openpilot.common.swaglog import cloudlog
 | ||
| 
											2 years ago
										 | from openpilot.system.version import get_build_metadata, get_version
 | ||
| 
											4 years ago
										 | 
 | ||
|  | 
 | ||
|  | class SentryProject(Enum):
 | ||
|  |   # python project
 | ||
| 
											4 years ago
										 |   SELFDRIVE = "https://6f3c7076c1e14b2aa10f5dde6dda0cc4@o33823.ingest.sentry.io/77924"
 | ||
| 
											4 years ago
										 |   # native project
 | ||
| 
											4 years ago
										 |   SELFDRIVE_NATIVE = "https://3e4b586ed21a4479ad5d85083b639bc6@o33823.ingest.sentry.io/157615"
 | ||
| 
											4 years ago
										 | 
 | ||
|  | 
 | ||
|  | def report_tombstone(fn: str, message: str, contents: str) -> None:
 | ||
|  |   cloudlog.error({'tombstone': message})
 | ||
|  | 
 | ||
|  |   with sentry_sdk.configure_scope() as scope:
 | ||
|  |     scope.set_extra("tombstone_fn", fn)
 | ||
|  |     scope.set_extra("tombstone", contents)
 | ||
|  |     sentry_sdk.capture_message(message=message)
 | ||
|  |     sentry_sdk.flush()
 | ||
|  | 
 | ||
|  | 
 | ||
|  | def capture_exception(*args, **kwargs) -> None:
 | ||
|  |   cloudlog.error("crash", exc_info=kwargs.get('exc_info', 1))
 | ||
|  | 
 | ||
|  |   try:
 | ||
|  |     sentry_sdk.capture_exception(*args, **kwargs)
 | ||
|  |     sentry_sdk.flush()  # https://github.com/getsentry/sentry-python/issues/291
 | ||
|  |   except Exception:
 | ||
|  |     cloudlog.exception("sentry exception")
 | ||
|  | 
 | ||
|  | 
 | ||
| 
											4 years ago
										 | def set_tag(key: str, value: str) -> None:
 | ||
|  |   sentry_sdk.set_tag(key, value)
 | ||
|  | 
 | ||
|  | 
 | ||
| 
											2 years ago
										 | def init(project: SentryProject) -> bool:
 | ||
| 
											2 years ago
										 |   build_metadata = get_build_metadata()
 | ||
| 
											4 years ago
										 |   # forks like to mess with this, so double check
 | ||
| 
											2 years ago
										 |   comma_remote = build_metadata.openpilot.comma_remote and "commaai" in build_metadata.openpilot.git_origin
 | ||
| 
											4 years ago
										 |   if not comma_remote or not is_registered_device() or PC:
 | ||
| 
											2 years ago
										 |     return False
 | ||
| 
											4 years ago
										 | 
 | ||
| 
											2 years ago
										 |   env = "release" if build_metadata.tested_channel else "master"
 | ||
| 
											4 years ago
										 |   dongle_id = Params().get("DongleId", encoding='utf-8')
 | ||
|  | 
 | ||
|  |   integrations = []
 | ||
|  |   if project == SentryProject.SELFDRIVE:
 | ||
|  |     integrations.append(ThreadingIntegration(propagate_hub=True))
 | ||
|  | 
 | ||
|  |   sentry_sdk.init(project.value,
 | ||
|  |                   default_integrations=False,
 | ||
|  |                   release=get_version(),
 | ||
|  |                   integrations=integrations,
 | ||
|  |                   traces_sample_rate=1.0,
 | ||
| 
											2 years ago
										 |                   max_value_length=8192,
 | ||
| 
											4 years ago
										 |                   environment=env)
 | ||
|  | 
 | ||
| 
											2 years ago
										 |   build_metadata = get_build_metadata()
 | ||
|  | 
 | ||
| 
											4 years ago
										 |   sentry_sdk.set_user({"id": dongle_id})
 | ||
| 
											2 years ago
										 |   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("commit", build_metadata.openpilot.git_commit)
 | ||
| 
											4 years ago
										 |   sentry_sdk.set_tag("device", HARDWARE.get_device_type())
 | ||
|  | 
 | ||
|  |   if project == SentryProject.SELFDRIVE:
 | ||
|  |     sentry_sdk.Hub.current.start_session()
 | ||
| 
											2 years ago
										 | 
 | ||
|  |   return True
 |