def _ReportCrash(err): """Report the anonymous crash information to the Error Reporting service. Args: err: Exception, the error that caused the crash. """ stacktrace = traceback.format_exc(err) stacktrace = error_reporting_util.RemovePrivateInformationFromTraceback( stacktrace) command = properties.VALUES.metrics.command_name.Get() cid = metrics.GetCIDIfMetricsEnabled() client = _GetReportingClient() reporter = util.ErrorReporting(client) try: reporter.ReportEvent(error_message=stacktrace, service=CRASH_SERVICE, version=config.CLOUD_SDK_VERSION, project=CRASH_PROJECT, request_url=command, user=cid) except apitools_exceptions.HttpError as http_err: log.file_only_logger.error( 'Unable to report crash stacktrace:\n{0}'.format( console_attr.EncodeForConsole(http_err)))
def ReportError(err, is_crash): """Report the anonymous crash information to the Error Reporting service. Args: err: Exception, the error that caused the crash. is_crash: bool, True if this is a crash, False if it is a user error. """ if properties.VALUES.core.disable_usage_reporting.GetBool(): return stacktrace = traceback.format_exc(err) stacktrace = error_reporting_util.RemovePrivateInformationFromTraceback( stacktrace) command = properties.VALUES.metrics.command_name.Get() cid = metrics.GetCIDIfMetricsEnabled() client = _GetReportingClient(is_crash) reporter = util.ErrorReporting(client) try: method_config = client.projects_events.GetMethodConfig('Report') request = reporter.GenerateReportRequest( error_message=stacktrace, service=SERVICE, version=config.CLOUD_SDK_VERSION, project=CRASH_PROJECT if is_crash else ERROR_PROJECT, request_url=command, user=cid) http_request = client.projects_events.PrepareHttpRequest( method_config, request) metrics.CustomBeacon(http_request.url, http_request.http_method, http_request.body, http_request.headers) except apitools_exceptions.Error as e: log.file_only_logger.error( 'Unable to report crash stacktrace:\n{0}'.format( console_attr.SafeText(e)))
def SetUp(self): self.error_report_instance = util.ErrorReporting() self.api_messages = self.error_report_instance.api_messages self.service = self.api_messages.ServiceContext(service=SERVICE) self.error_event = self.api_messages.ReportedErrorEvent( serviceContext=self.service, message=ERROR_MESSAGE) properties.VALUES.core.project.Set(PROJECT) self.addCleanup(properties.VALUES.core.project.Set, None)
def Run(self, args): """Send an error report based on the given args.""" # Get required message components for API report request error_message = self.GetMessage(args) service = args.service # Get service version if provided, otherwise service_version=None service_version = args.service_version project = self.GetProject(args) # Send error report error_event = util.ErrorReporting() error_event.ReportEvent(error_message, service, service_version, project) log.status.Print('Your error has been reported.')
def _ReportError(err): """Get the command and stacktrace and sends Error to Error Reporting. Args: err: Exception err. """ command = ' '.join(sys.argv[1:]) stacktrace = traceback.format_exc(err) stacktrace = error_reporting_util.RemovePrivateInformationFromTraceback( stacktrace) try: util.ErrorReporting().ReportEvent(error_message=stacktrace, service=command, version=config.CLOUD_SDK_VERSION) except apitools_exceptions.HttpError: pass