common_event_schema.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from datetime import datetime
  2. from typing import Annotated, Any, Literal, Optional, Union
  3. from ninja import Schema
  4. from pydantic import (
  5. WrapValidator,
  6. )
  7. from .common_event_utils import invalid_to_none
  8. Level = Literal["fatal", "error", "warning", "info", "debug"]
  9. class EventBreadcrumb(Schema):
  10. type: str = "default"
  11. category: Optional[str] = None
  12. message: Optional[str] = None
  13. data: Optional[dict[str, Any]] = None
  14. level: Annotated[Optional[Level], WrapValidator(invalid_to_none)] = "info"
  15. timestamp: Optional[datetime] = None
  16. ListKeyValue = list[list[Optional[str]]]
  17. """
  18. dict[str, list[str]] but stored as a list[list[:2]] for OSS Sentry compatibility
  19. [["animal", "cat"], ["animal", "dog"], ["thing": "kettle"]]
  20. This format is often used for http needs including headers and querystrings
  21. """
  22. class BaseRequest(Schema):
  23. """Base Request class for event ingest and issue event API"""
  24. api_target: Optional[str] = None
  25. body_size: Optional[int] = None
  26. cookies: Optional[
  27. Union[str, list[list[Optional[str]]], dict[str, Optional[str]]]
  28. ] = None
  29. data: Optional[Union[str, dict, list, Any]] = None
  30. env: Optional[dict[str, Any]] = None
  31. fragment: Optional[str] = None
  32. method: Optional[str] = None
  33. protocol: Optional[str] = None
  34. url: Optional[str] = None
  35. class BaseIssueEvent(Schema):
  36. """
  37. Base Issue Event for fields present from the SDK data, json event, and api event
  38. """
  39. platform: Optional[str] = None