events.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import uuid
  2. from typing import Any, Optional
  3. class BaseTelemetryEvent:
  4. def __init__(self, event_type: str, properties: dict[str, Any]):
  5. self.event_type = event_type
  6. self.properties = properties
  7. self.event_id = str(uuid.uuid4())
  8. class FeatureUsageEvent(BaseTelemetryEvent):
  9. def __init__(
  10. self,
  11. user_id: str,
  12. feature: str,
  13. properties: Optional[dict[str, Any]] = None,
  14. ):
  15. super().__init__(
  16. "FeatureUsage",
  17. {
  18. "user_id": user_id,
  19. "feature": feature,
  20. "properties": properties or {},
  21. },
  22. )
  23. class ErrorEvent(BaseTelemetryEvent):
  24. def __init__(
  25. self,
  26. user_id: str,
  27. endpoint: str,
  28. error_message: str,
  29. properties: Optional[dict[str, Any]] = None,
  30. ):
  31. super().__init__(
  32. "Error",
  33. {
  34. "user_id": user_id,
  35. "endpoint": endpoint,
  36. "error_message": error_message,
  37. "properties": properties or {},
  38. },
  39. )