base.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from django.utils.encoding import force_str
  2. from sentry.culprit import generate_culprit
  3. from sentry.utils.safe import get_path
  4. from sentry.utils.strings import strip, truncatechars
  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", "formatted")
  20. or get_path(data, "message")
  21. )
  22. if message:
  23. title = truncatechars(message.splitlines()[0], 100)
  24. else:
  25. title = "<unlabeled event>"
  26. return {"title": title}
  27. def get_title(self, metadata):
  28. return metadata.get("title") or "<untitled>"
  29. def get_location(self, data):
  30. return force_str(
  31. data.get("culprit")
  32. or data.get("transaction")
  33. or generate_culprit(data)
  34. or ""
  35. )