base.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from django.utils.encoding import force_str
  2. from sentry.culprit import generate_culprit
  3. from sentry.utils.strings import truncatechars, strip
  4. from sentry.utils.safe import get_path
  5. class BaseEvent:
  6. id = None
  7. def get_metadata(self, data):
  8. raise NotImplementedError
  9. def get_title(self, metadata):
  10. raise NotImplementedError
  11. def get_location(self, data):
  12. return None
  13. class DefaultEvent(BaseEvent):
  14. key = "default"
  15. def get_metadata(self, data):
  16. message = strip(
  17. get_path(data, "logentry", "formatted")
  18. or get_path(data, "logentry", "message")
  19. or get_path(data, "message")
  20. )
  21. if message:
  22. title = truncatechars(message.splitlines()[0], 100)
  23. else:
  24. title = "<unlabeled event>"
  25. return {"title": title}
  26. def get_title(self, metadata):
  27. return metadata.get("title") or "<untitled>"
  28. def get_location(self, data):
  29. return force_str(
  30. data.get("culprit")
  31. or data.get("transaction")
  32. or generate_culprit(data)
  33. or ""
  34. )