sentry fixups (#23249)
	
		
	
				
					
				
			* set env
* do init in same place
* no sentry for forks
* start session
* start session
* remove that
* val
old-commit-hash: b63bc89bc9
			
			
				vw-mqb-aeb
			
			
		
							parent
							
								
									58a47e25bb
								
							
						
					
					
						commit
						fa8ba3617b
					
				
				 7 changed files with 88 additions and 69 deletions
			
			
		@ -1,27 +0,0 @@ | 
				
			||||
"""Install exception handler for process crash.""" | 
				
			||||
from selfdrive.swaglog import cloudlog | 
				
			||||
from selfdrive.version import get_version | 
				
			||||
 | 
				
			||||
import sentry_sdk | 
				
			||||
from sentry_sdk.integrations.threading import ThreadingIntegration | 
				
			||||
 | 
				
			||||
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") | 
				
			||||
 | 
				
			||||
def bind_user(**kwargs) -> None: | 
				
			||||
  sentry_sdk.set_user(kwargs) | 
				
			||||
 | 
				
			||||
def bind_extra(**kwargs) -> None: | 
				
			||||
  for k, v in kwargs.items(): | 
				
			||||
    sentry_sdk.set_tag(k, v) | 
				
			||||
 | 
				
			||||
def init() -> None: | 
				
			||||
  sentry_sdk.init("https://a8dc76b5bfb34908a601d67e2aa8bcf9@o33823.ingest.sentry.io/77924", | 
				
			||||
                  default_integrations=False, integrations=[ThreadingIntegration(propagate_hub=True)], | 
				
			||||
                  release=get_version()) | 
				
			||||
@ -0,0 +1,69 @@ | 
				
			||||
"""Install exception handler for process crash.""" | 
				
			||||
import sentry_sdk | 
				
			||||
from enum import Enum | 
				
			||||
from sentry_sdk.integrations.threading import ThreadingIntegration | 
				
			||||
 | 
				
			||||
from common.params import Params | 
				
			||||
from selfdrive.hardware import HARDWARE | 
				
			||||
from selfdrive.swaglog import cloudlog | 
				
			||||
from selfdrive.version import get_branch, get_commit, get_origin, get_version, \ | 
				
			||||
                              is_comma_remote, is_dirty, is_tested_branch | 
				
			||||
 | 
				
			||||
 | 
				
			||||
class SentryProject(Enum): | 
				
			||||
  # python project | 
				
			||||
  SELFDRIVE = "https://a8dc76b5bfb34908a601d67e2aa8bcf9@o33823.ingest.sentry.io/77924" | 
				
			||||
  # native project | 
				
			||||
  SELFDRIVE_NATIVE = "https://a40f22e13cbc4261873333c125fc9d38@o33823.ingest.sentry.io/157615" | 
				
			||||
 | 
				
			||||
 | 
				
			||||
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") | 
				
			||||
 | 
				
			||||
 | 
				
			||||
def init(project: SentryProject) -> None: | 
				
			||||
  # forks like to mess with this, so double check | 
				
			||||
  if not (is_comma_remote() and "commaai" in get_origin(default="")): | 
				
			||||
    return | 
				
			||||
 | 
				
			||||
  env = "production" if is_tested_branch() else "master" | 
				
			||||
  dongle_id = Params().get("DongleId", encoding='utf-8') | 
				
			||||
 | 
				
			||||
  integrations = [] | 
				
			||||
  if project == SentryProject.SELFDRIVE: | 
				
			||||
    integrations.append(ThreadingIntegration(propagate_hub=True)) | 
				
			||||
  else: | 
				
			||||
    sentry_sdk.utils.MAX_STRING_LENGTH = 8192 | 
				
			||||
 | 
				
			||||
  sentry_sdk.init(project.value, | 
				
			||||
                  default_integrations=False, | 
				
			||||
                  release=get_version(), | 
				
			||||
                  integrations=integrations, | 
				
			||||
                  traces_sample_rate=1.0, | 
				
			||||
                  environment=env) | 
				
			||||
 | 
				
			||||
  sentry_sdk.set_user({"id": dongle_id}) | 
				
			||||
  sentry_sdk.set_tag("dirty", is_dirty()) | 
				
			||||
  sentry_sdk.set_tag("origin", get_origin()) | 
				
			||||
  sentry_sdk.set_tag("branch", get_branch()) | 
				
			||||
  sentry_sdk.set_tag("commit", get_commit()) | 
				
			||||
  sentry_sdk.set_tag("device", HARDWARE.get_device_type()) | 
				
			||||
 | 
				
			||||
  if project == SentryProject.SELFDRIVE: | 
				
			||||
    sentry_sdk.Hub.current.start_session() | 
				
			||||
					Loading…
					
					
				
		Reference in new issue