def _prepare_event(self, event, hint, scope): if event.get("timestamp") is None: event["timestamp"] = datetime.utcnow() if scope is not None: event = scope.apply_to_event(event, hint) if event is None: return if ( self.options["attach_stacktrace"] and "exception" not in event and "stacktrace" not in event and "threads" not in event ): with capture_internal_exceptions(): event["threads"] = [ { "stacktrace": current_stacktrace(), "crashed": False, "current": True, } ] for key in "release", "environment", "server_name", "dist": if event.get(key) is None and self.options[key] is not None: event[key] = text_type(self.options[key]).strip() if event.get("sdk") is None: sdk_info = dict(SDK_INFO) sdk_info["integrations"] = sorted(self.integrations.keys()) event["sdk"] = sdk_info if event.get("platform") is None: event["platform"] = "python" event = handle_in_app( event, self.options["in_app_exclude"], self.options["in_app_include"] ) before_send = self.options["before_send"] if before_send is not None: with capture_internal_exceptions(): new_event = before_send(event, hint) if new_event is None: logger.info("before send dropped event (%s)", event) event = new_event # Postprocess the event in the very end so that annotated types do # generally not surface in before_send if event is not None: strip_event_mut(event) event = flatten_metadata(event) event = convert_types(event) return event
def test_strip_exception_vars(): try: a = "A" * 16000 # noqa 1 / 0 except Exception: event, _ = event_from_exception(sys.exc_info()) assert len(json.dumps(event)) > 10000 strip_event_mut(event) event = flatten_metadata(event) event = convert_types(event) assert len(json.dumps(event)) < 10000
def _prepare_event(self, event, hint, scope): if event.get("timestamp") is None: event["timestamp"] = datetime.utcnow() if scope is not None: event = scope.apply_to_event(event, hint) if event is None: return for key in "release", "environment", "server_name", "repos", "dist": if event.get(key) is None: event[key] = self.options[key] if event.get("sdk") is None: event["sdk"] = SDK_INFO if event.get("platform") is None: event["platform"] = "python" event = handle_in_app( event, self.options["in_app_exclude"], self.options["in_app_include"] ) before_send = self.options["before_send"] if before_send is not None: with capture_internal_exceptions(): new_event = before_send(event, hint) if new_event is None: logger.info("before send dropped event (%s)", event) event = new_event # Postprocess the event in the very end so that annotated types do # generally not surface in before_send if event is not None: event = strip_event(event) event = flatten_metadata(event) event = convert_types(event) return event