models.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from django.contrib.postgres.fields import HStoreField
  2. from django.contrib.postgres.search import SearchVectorField
  3. from django.db import models
  4. from events.models import AbstractEvent
  5. from glitchtip.base_models import CreatedModel
  6. class TransactionGroup(CreatedModel):
  7. transaction = models.CharField(max_length=1024)
  8. project = models.ForeignKey("projects.Project", on_delete=models.CASCADE)
  9. op = models.CharField(max_length=255)
  10. method = models.CharField(max_length=255, null=True, blank=True)
  11. tags = models.JSONField(default=dict)
  12. search_vector = SearchVectorField(null=True, editable=False)
  13. class Meta:
  14. unique_together = (("transaction", "project", "op", "method"),)
  15. def __str__(self):
  16. return self.transaction
  17. class TransactionEvent(AbstractEvent):
  18. group = models.ForeignKey(TransactionGroup, on_delete=models.CASCADE)
  19. trace_id = models.UUIDField(db_index=True)
  20. start_timestamp = models.DateTimeField()
  21. duration = models.DurationField(db_index=True)
  22. tags = HStoreField(default=dict)
  23. class Meta:
  24. ordering = ["-created"]
  25. def __str__(self):
  26. return str(self.trace_id)
  27. class Span(CreatedModel):
  28. transaction = models.ForeignKey(TransactionEvent, on_delete=models.CASCADE)
  29. span_id = models.CharField(max_length=16)
  30. parent_span_id = models.CharField(max_length=16, null=True, blank=True)
  31. # same_process_as_parent bool - we don't use this currently
  32. op = models.CharField(max_length=255)
  33. description = models.CharField(max_length=2000, null=True, blank=True)
  34. start_timestamp = models.DateTimeField()
  35. timestamp = models.DateTimeField()
  36. tags = HStoreField(default=dict)
  37. data = models.JSONField(default=dict)
  38. def __str__(self):
  39. return self.span_id