def to_json(self): return prune_empty_keys({ "type": self.type, "synthetic": self.synthetic, "description": self.description, "help_link": self.help_link, "handled": self.handled, "data": self.data or None, "meta": prune_empty_keys(self.meta) or None, })
def to_json(self): return prune_empty_keys({ "values": [ prune_empty_keys({ "type": crumb["type"], "level": crumb["level"], "timestamp": crumb["timestamp"], "message": crumb["message"], "category": crumb["category"], "event_id": crumb["event_id"], "data": crumb["data"] or None, }) for crumb in self.values ] or None })
def to_json(self): mechanism = ( isinstance(self.mechanism, Mechanism) and self.mechanism.to_json() or self.mechanism or None ) if self.stacktrace: stacktrace = self.stacktrace.to_json() else: stacktrace = None if self.raw_stacktrace: raw_stacktrace = self.raw_stacktrace.to_json() else: raw_stacktrace = None return prune_empty_keys( { "type": self.type, "value": self.value, "mechanism": mechanism, "module": self.module, "stacktrace": stacktrace, "thread_id": self.thread_id, "raw_stacktrace": raw_stacktrace, } )
def to_json(self): return prune_empty_keys( { "values": [v and v.to_json() for v in self.values] or None, "exc_omitted": self.exc_omitted, } )
def to_json(self): return prune_empty_keys({ "abs_path": self.abs_path or None, "filename": self.filename or None, "platform": self.platform or None, "module": self.module or None, "function": self.function or None, "raw_function": self.raw_function or None, "package": self.package or None, "image_addr": self.image_addr, "symbol": self.symbol, "symbol_addr": self.symbol_addr, "instruction_addr": self.instruction_addr, "addr_mode": self.addr_mode, "trust": self.trust, "in_app": self.in_app, "context_line": self.context_line, "pre_context": self.pre_context or None, "post_context": self.post_context or None, "vars": self.vars or None, "data": self.data or None, "errors": self.errors or None, "lineno": self.lineno, "colno": self.colno, })
def to_json(self): return prune_empty_keys({ "prefix": self.prefix, "subscope": self.subscope, "limit": self.limit, "window": self.window, "reasonCode": self.reason_code, })
def meta(self): return prune_empty_keys({ "id": self.id, "name": self.name, "content_type": self.content_type, "type": self.type, "chunks": self.chunks, })
def to_json(self): return prune_empty_keys({ "frames": [f and f.to_json() for f in self.frames] or None, "frames_omitted": self.frames_omitted, "registers": self.registers, })
def to_json(self): return prune_empty_keys( { "images": self.images or None, "sdk_info": self.sdk_info or None, "is_debug_build": self.is_debug_build, } )
def to_json(self): return prune_empty_keys( { "name": self.name, "version": self.version, "integrations": self.integrations or None, "packages": self.packages or None, } )
def to_json(self): return prune_empty_keys( { "prefix": six.text_type(self.prefix) if self.prefix is not None else None, "subscope": six.text_type(self.subscope) if self.subscope is not None else None, "limit": self.limit, "window": self.window, "reasonCode": self.reason_code, } )
def meta(self): return prune_empty_keys({ "id": self.id, "name": self.name, "content_type": self.content_type, "type": self.type, "chunks": self.chunks, "size": self.size or None, # None for backwards compatibility "rate_limited": self.rate_limited, })
def _get_tags_with_meta(self, event): meta = get_path(event.data, "_meta", "tags") or {} # If we have meta, we need to get the tags in their original order # from the raw event body as the indexes need to line up with the # metadata indexes. In other cases we can use event.tags if meta: raw_tags = event.data.get("tags") or [] else: raw_tags = event.tags tags = sorted( [ { "key": kv[0] and kv[0].split("sentry:", 1)[-1], "value": kv[1], "_meta": prune_empty_keys( { "key": get_path(meta, six.text_type(i), "0"), "value": get_path(meta, six.text_type(i), "1"), } ) or None, } for i, kv in enumerate(raw_tags) if kv is not None ], key=lambda x: x["key"] if x["key"] is not None else "", ) # Add 'query' for each tag to tell the UI what to use as query # params for this tag. for tag in tags: query = convert_user_tag_to_query(tag["key"], tag["value"]) if query: tag["query"] = query tags_meta = prune_empty_keys({six.text_type(i): e.pop("_meta") for i, e in enumerate(tags)}) return (tags, meta_with_chunks(tags, tags_meta))
def to_json_legacy(self): data = { "prefix": six.text_type(self.id) if self.id is not None else None, "subscope": six.text_type(self.scope_id) if self.scope_id is not None else None, "limit": self.limit, "window": self.window, "reasonCode": self.reason_code, } if self.scope != QuotaScope.ORGANIZATION and self.scope_id is not None: data["subscope"] = self.scope_id return prune_empty_keys(data)
def to_json(self): return prune_empty_keys( { "method": self.method, "url": self.url, "query_string": self.query_string or None, "fragment": self.fragment or None, "cookies": self.cookies or None, "headers": self.headers or None, "data": self.data, "env": self.env or None, "inferred_content_type": self.inferred_content_type, } )
def export_thread(data): if data is None: return None rv = { "id": data["id"], "current": data["current"], "crashed": data["crashed"], "name": data["name"], "stacktrace": None, } if data["stacktrace"]: rv["stacktrace"] = data["stacktrace"].to_json() if data["raw_stacktrace"]: rv["raw_stacktrace"] = data["raw_stacktrace"].to_json() return prune_empty_keys(rv)
def to_json(self): categories = None if self.categories: categories = [c.api_name() for c in self.categories] data = { "id": six.text_type(self.id) if self.id is not None else None, "scope": self.scope.api_name(), "scopeId": self.scope_id, "categories": categories, "limit": self.limit, "window": self.window, "reasonCode": self.reason_code, } return prune_empty_keys(data)
def _assert_tree_labels(event, functions): # This should really be its own test, but it is cheaper to run as part of an existing test. assert [ prune_empty_keys(frame) for frame in event.data["exception"]["values"] [0]["stacktrace"]["frames"] ] == [{ "data": { "min_grouping_level": len(functions) - i - 1, "orig_in_app": -1, }, "function": function, "in_app": False, } for i, function in enumerate(functions)] assert event.data["metadata"]["finest_tree_label"] == [{ "function": function } for function in reversed(functions)]
def to_json(self): return prune_empty_keys({ "id": self.id, "email": self.email, "username": self.username, "ip_address": self.ip_address, "name": self.name, "geo": self.geo.to_json() if self.geo is not None else None, "data": self.data or None, })
def to_json(self): def export_thread(data): if data is None: return None rv = { "id": data["id"], "current": data["current"], "crashed": data["crashed"], "name": data["name"], "stacktrace": None, } if data["stacktrace"]: rv["stacktrace"] = data["stacktrace"].to_json() if data["raw_stacktrace"]: rv["raw_stacktrace"] = data["raw_stacktrace"].to_json() return prune_empty_keys(rv) return prune_empty_keys({"values": [export_thread(x) for x in self.values]})
def track_outcome( self, event_id=None, key_id=None, outcome=None, reason=None, remote_addr=None, timestamp=None, ): message = { "project_id": self.project.id, "org_id": self.organization.id, "event_id": event_id, "key_id": key_id, "outcome": outcome, "reason": reason, "remote_addr": remote_addr, "timestamp": timestamp, } message = json.dumps(prune_empty_keys(message)) self.producer.produce(self.topic_name, message)
def to_json(self): rv = dict(self.data) rv["type"] = self.type return prune_empty_keys(rv)
def upgrade_legacy_mechanism(data): """ Conversion from mechanism objects sent by old sentry-cocoa SDKs. It assumes "type": "generic" and moves "posix_signal", "mach_exception" into "meta". All other keys are moved into "data". Example old payload: >>> { >>> "posix_signal": { >>> "name": "SIGSEGV", >>> "code_name": "SEGV_NOOP", >>> "signal": 11, >>> "code": 0 >>> }, >>> "relevant_address": "0x1", >>> "mach_exception": { >>> "exception": 1, >>> "exception_name": "EXC_BAD_ACCESS", >>> "subcode": 8, >>> "code": 1 >>> } >>> } Example normalization: >>> { >>> "type": "generic", >>> "data": { >>> "relevant_address": "0x1" >>> }, >>> "meta": { >>> "mach_exception": { >>> "exception": 1, >>> "subcode": 8, >>> "code": 1, >>> "name": "EXC_BAD_ACCESS" >>> }, >>> "signal": { >>> "number": 11, >>> "code": 0, >>> "name": "SIGSEGV", >>> "code_name": "SEGV_NOOP" >>> } >>> } >>> } """ # Early exit for current protocol. We assume that when someone sends a # "type", we do not need to preprocess and can immediately validate if data is None or data.get("type") is not None: return data result = {"type": "generic"} # "posix_signal" and "mach_exception" were optional root-level objects, # which have now moved to special keys inside "meta". We only create "meta" # if there is actual data to add. posix_signal = data.pop("posix_signal", None) if posix_signal and posix_signal.get("signal"): result.setdefault("meta", {})["signal"] = prune_empty_keys({ "number": posix_signal.get("signal"), "code": posix_signal.get("code"), "name": posix_signal.get("name"), "code_name": posix_signal.get("code_name"), }) mach_exception = data.pop("mach_exception", None) if mach_exception: result.setdefault("meta", {})["mach_exception"] = prune_empty_keys({ "exception": mach_exception.get("exception"), "code": mach_exception.get("code"), "subcode": mach_exception.get("subcode"), "name": mach_exception.get("exception_name"), }) # All remaining data has to be moved to the "data" key. We assume that even # if someone accidentally sent a corret top-level key (such as "handled"), # it will not pass our interface validation and should be moved to "data" # instead. result.setdefault("data", {}).update(data) return result
def to_json(self): return prune_empty_keys(self._data)
def to_json(self): return prune_empty_keys({ "message": self.message, "formatted": self.formatted, "params": self.params or None })