__init__.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import os
  2. from sentry.utils.safe import get_path
  3. def get_fixture_path(name):
  4. return os.path.join(os.path.dirname(__file__), os.pardir, "fixtures", "native", name)
  5. def strip_frame(frame):
  6. if frame:
  7. frame = {
  8. "data": {
  9. "symbolicator_status": get_path(frame, "data", "symbolicator_status"),
  10. "orig_in_app": get_path(frame, "data", "orig_in_app"),
  11. },
  12. "function": frame.get("function"),
  13. "instruction_addr": frame.get("instruction_addr"),
  14. "symbol": frame.get("symbol"),
  15. "package": frame.get("package"),
  16. "lineno": frame.get("lineno"),
  17. "in_app": frame.get("in_app"),
  18. "trust": frame.get("trust"),
  19. }
  20. return frame
  21. def strip_stacktrace(stacktrace):
  22. if stacktrace:
  23. stacktrace = dict(stacktrace)
  24. stacktrace["frames"] = [strip_frame(x) for x in stacktrace.get("frames") or ()]
  25. return stacktrace
  26. def strip_stacktrace_container(container):
  27. if container:
  28. container = dict(container)
  29. container["stacktrace"] = strip_stacktrace(container.get("stacktrace"))
  30. container["raw_stacktrace"] = strip_stacktrace(container.get("raw_stacktrace"))
  31. return container
  32. def insta_snapshot_stacktrace_data(self, event, **kwargs):
  33. # limit amount of data going into a snapshot so that they don't break all
  34. # the time due to unrelated changes.
  35. self.insta_snapshot(
  36. {
  37. "stacktrace": strip_stacktrace(event.get("stacktrace")),
  38. "exception": {
  39. "values": [
  40. strip_stacktrace_container(x)
  41. for x in get_path(event, "exception", "values") or ()
  42. ]
  43. },
  44. "threads": {
  45. "values": [
  46. strip_stacktrace_container(x)
  47. for x in get_path(event, "threads", "values") or ()
  48. ]
  49. },
  50. "debug_meta": event.get("debug_meta"),
  51. "contexts": {
  52. k: v for k, v in (event.get("contexts") or {}).items() if k != "reprocessing"
  53. }
  54. or None,
  55. "errors": [e for e in event.get("errors") or () if e.get("name") != "timestamp"],
  56. },
  57. **kwargs,
  58. )