def _payload(self): # Fetch the notifier version from the package notifier_version = package_version("bugsnag") or "unknown" # Construct the payload dictionary filters = self.config.params_filters encoder = SanitizingJSONEncoder(separators=(',', ':'), keyword_filters=filters) return encoder.encode({ "apiKey": self.api_key, "notifier": { "name": self.NOTIFIER_NAME, "url": self.NOTIFIER_URL, "version": notifier_version, }, "events": [{ "payloadVersion": self.PAYLOAD_VERSION, "severity": self.severity, "releaseStage": self.release_stage, "appVersion": self.app_version, "context": self.context, "groupingHash": self.grouping_hash, "exceptions": [{ "errorClass": class_name(self.exception), "message": self.exception, "stacktrace": self.stacktrace, }], "metaData": self.meta_data, "user": self.user, "device": { "hostname": self.hostname }, "projectRoot": self.config.get("project_root"), "libRoot": self.config.get("lib_root") }] })
def _payload(self): # Fetch the notifier version from the package notifier_version = package_version("bugsnag") or "unknown" filters = self.config.params_filters encoder = SanitizingJSONEncoder(separators=(',', ':'), keyword_filters=filters) # Construct the payload dictionary return encoder.encode({ "apiKey": self.api_key, "notifier": { "name": self.NOTIFIER_NAME, "url": self.NOTIFIER_URL, "version": notifier_version, }, "events": [{ "severity": self.severity, "severityReason": self.severity_reason, "unhandled": self.unhandled, "releaseStage": self.release_stage, "app": { "version": self.app_version, "type": self.app_type, }, "context": self.context, "groupingHash": self.grouping_hash, "exceptions": [{ "errorClass": class_name(self.exception), "message": self.exception, "stacktrace": self.stacktrace, }], "metaData": FilterDict(self.metadata), "user": FilterDict(self.user), "device": FilterDict({ "hostname": self.hostname, "runtimeVersions": self.runtime_versions }), "projectRoot": self.config.project_root, "libRoot": self.config.lib_root, "session": self.session }] })
def __generate_payload(self): try: # Set up the lib root lib_root = self.config.get("lib_root", self.options) if lib_root and lib_root[-1] != os.sep: lib_root += os.sep # Set up the project root project_root = self.config.get("project_root", self.options) if project_root and project_root[-1] != os.sep: project_root += os.sep # Build the stacktrace tb = self.options.get("traceback", sys.exc_info()[2]) if tb: trace = traceback.extract_tb(tb) else: trace = traceback.extract_stack() bugsnag_module_path = os.path.dirname(bugsnag.__file__) stacktrace = [] for line in trace: file_name = os.path.abspath(str(line[0])) in_project = False if file_name.startswith(bugsnag_module_path): continue if lib_root and file_name.startswith(lib_root): file_name = file_name[len(lib_root):] elif project_root and file_name.startswith(project_root): file_name = file_name[len(project_root):] in_project = True stacktrace.append({ "file": file_name, "lineNumber": int(str(line[1])), "method": str(line[2]), "inProject": in_project, }) stacktrace.reverse() # Fetch the notifier version from the package notifier_version = package_version("bugsnag_python") or "unknown" # Construct the payload dictionary payload = { "apiKey": self.config.api_key, "notifier": { "name": self.NOTIFIER_NAME, "url": self.NOTIFIER_URL, "version": notifier_version, }, "events": [{ "releaseStage": self.config.get("release_stage", self.options), "appVersion": self.config.get("app_version", self.options), "context": self.request_config.get("context", self.options), "userId": self.request_config.get("user_id", self.options), "groupingHash": self.request_config.get("grouping_hash", self.options), "exceptions": [{ "errorClass": class_name(self.exception), "message": str(self.exception), "stacktrace": stacktrace, }], "metaData": self.__generate_metadata(), }], "device": { "hostname": self.config.get("hostname", self.options) } } # JSON-encode and return the payload return json.dumps(payload) finally: del tb