__init__.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import os
  2. import re
  3. from sentry.utils.safe import get_path
  4. def get_fixture_path(name):
  5. return os.path.join(os.path.dirname(__file__), os.pardir, "fixtures", "native", name)
  6. def strip_frame(frame):
  7. if frame:
  8. frame = {
  9. "data": {
  10. "symbolicator_status": get_path(frame, "data", "symbolicator_status"),
  11. "orig_in_app": get_path(frame, "data", "orig_in_app"),
  12. },
  13. "function": frame.get("function"),
  14. "instruction_addr": frame.get("instruction_addr"),
  15. "symbol": frame.get("symbol"),
  16. "package": frame.get("package"),
  17. "lineno": frame.get("lineno"),
  18. "in_app": frame.get("in_app"),
  19. "trust": frame.get("trust"),
  20. }
  21. return frame
  22. NORMALIZED_REGISTERS = {}
  23. def normalize_register(name):
  24. return NORMALIZED_REGISTERS.get(name, name)
  25. def strip_stacktrace(stacktrace):
  26. if stacktrace:
  27. stacktrace = dict(stacktrace)
  28. stacktrace["frames"] = [strip_frame(x) for x in stacktrace.get("frames") or ()]
  29. try:
  30. stacktrace["registers"] = {
  31. normalize_register(k): v for k, v in stacktrace["registers"].items()
  32. }
  33. except KeyError:
  34. pass
  35. return stacktrace
  36. STRIP_TRAILING_ADDR_RE = re.compile(" ?/ 0x[0-9a-fA-F]+$")
  37. def strip_trailing_addr(value):
  38. return STRIP_TRAILING_ADDR_RE.sub("", value)
  39. def normalize_exception(exc):
  40. if exc:
  41. exc = dict(exc)
  42. exc["type"] = strip_trailing_addr(exc["type"])
  43. exc["value"] = strip_trailing_addr(exc["value"])
  44. return exc
  45. def strip_stacktrace_container(container):
  46. if container:
  47. container = dict(container)
  48. container["stacktrace"] = strip_stacktrace(container.get("stacktrace"))
  49. container["raw_stacktrace"] = strip_stacktrace(container.get("raw_stacktrace"))
  50. return container
  51. def insta_snapshot_stacktrace_data(self, event, **kwargs):
  52. # limit amount of data going into a snapshot so that they don't break all
  53. # the time due to unrelated changes.
  54. self.insta_snapshot(
  55. {
  56. "stacktrace": strip_stacktrace(event.get("stacktrace")),
  57. "exception": {
  58. "values": [
  59. normalize_exception(strip_stacktrace_container(x))
  60. for x in get_path(event, "exception", "values") or ()
  61. ]
  62. },
  63. "threads": {
  64. "values": [
  65. strip_stacktrace_container(x)
  66. for x in get_path(event, "threads", "values") or ()
  67. ]
  68. },
  69. "debug_meta": event.get("debug_meta"),
  70. "contexts": {
  71. k: v for k, v in (event.get("contexts") or {}).items() if k != "reprocessing"
  72. }
  73. or None,
  74. "errors": [e for e in event.get("errors") or () if e.get("name") != "timestamp"],
  75. },
  76. **kwargs,
  77. )