test_organization_spans_trace.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. from uuid import uuid4
  2. from django.urls import reverse
  3. from tests.snuba.api.endpoints.test_organization_events_trace import (
  4. OrganizationEventsTraceEndpointBase,
  5. )
  6. class OrganizationEventsTraceEndpointTest(OrganizationEventsTraceEndpointBase):
  7. url_name = "sentry-api-0-organization-spans-trace"
  8. FEATURES = ["organizations:trace-spans-format"]
  9. check_generation = True
  10. def assert_event(self, result, event_data, message):
  11. assert result["transaction"] == event_data.transaction, message
  12. assert result["event_id"] == event_data.event_id
  13. assert result["start_timestamp"] == event_data.data["start_timestamp"]
  14. assert result["profile_id"] == event_data.data["contexts"]["profile"]["profile_id"]
  15. def assert_trace_data(self, root, gen2_no_children=True):
  16. """see the setUp docstring for an idea of what the response structure looks like"""
  17. self.assert_event(root, self.root_event, "root")
  18. assert root["parent_event_id"] is None
  19. assert root["parent_span_id"] is None
  20. if self.check_generation:
  21. assert root["generation"] == 0
  22. assert root["transaction.duration"] == 3000
  23. assert root["sdk_name"] == "sentry.test.sdk"
  24. assert len(root["children"]) == 3
  25. self.assert_performance_issues(root)
  26. for i, gen1 in enumerate(root["children"]):
  27. self.assert_event(gen1, self.gen1_events[i], f"gen1_{i}")
  28. assert gen1["parent_event_id"] == self.root_event.event_id
  29. assert gen1["parent_span_id"] == self.root_span_ids[i]
  30. if self.check_generation:
  31. assert gen1["generation"] == 1
  32. assert gen1["transaction.duration"] == 2000
  33. assert gen1["sdk_name"] == "sentry.test.sdk"
  34. assert len(gen1["children"]) == 1
  35. gen2 = gen1["children"][0]
  36. self.assert_event(gen2, self.gen2_events[i], f"gen2_{i}")
  37. assert gen2["parent_event_id"] == self.gen1_events[i].event_id
  38. assert gen2["parent_span_id"] == self.gen1_span_ids[i]
  39. if self.check_generation:
  40. assert gen2["generation"] == 2
  41. assert gen2["transaction.duration"] == 1000
  42. assert gen2["sdk_name"] == "sentry.test.sdk"
  43. # Only the first gen2 descendent has a child
  44. if i == 0:
  45. assert len(gen2["children"]) == 1
  46. gen3 = gen2["children"][0]
  47. self.assert_event(gen3, self.gen3_event, f"gen3_{i}")
  48. assert gen3["parent_event_id"] == self.gen2_events[i].event_id
  49. assert gen3["parent_span_id"] == self.gen2_span_id
  50. if self.check_generation:
  51. assert gen3["generation"] == 3
  52. assert gen3["transaction.duration"] == 500
  53. assert gen3["sdk_name"] == "sentry.test.sdk"
  54. assert len(gen3["children"]) == 0
  55. elif gen2_no_children:
  56. assert len(gen2["children"]) == 0
  57. def assert_performance_issues(self, root):
  58. """Broken in the non-spans endpoint, but we're not maintaining that anymore"""
  59. pass
  60. def client_get(self, data, url=None):
  61. if url is None:
  62. url = self.url
  63. return self.client.get(
  64. url,
  65. data,
  66. format="json",
  67. )
  68. def test_no_projects(self):
  69. user = self.create_user()
  70. org = self.create_organization(owner=user)
  71. self.login_as(user=user)
  72. url = reverse(
  73. self.url_name,
  74. kwargs={"organization_id_or_slug": org.slug, "trace_id": uuid4().hex},
  75. )
  76. with self.feature(self.FEATURES):
  77. response = self.client.get(
  78. url,
  79. format="json",
  80. )
  81. assert response.status_code == 404, response.content
  82. def test_simple(self):
  83. self.load_trace()
  84. with self.feature(self.FEATURES):
  85. response = self.client_get(
  86. data={"project": -1},
  87. )
  88. assert response.status_code == 200, response.content
  89. data = response.data
  90. assert len(data) == 21
  91. assert len([row for row in data if row["is_transaction"] == 1]) == 8