test_organization_events_span_indexed.py 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  1. import uuid
  2. from datetime import datetime
  3. from unittest import mock
  4. import pytest
  5. from tests.snuba.api.endpoints.test_organization_events import OrganizationEventsEndpointTestBase
  6. class OrganizationEventsSpanIndexedEndpointTest(OrganizationEventsEndpointTestBase):
  7. is_eap = False
  8. use_rpc = False
  9. """Test the indexed spans dataset.
  10. To run this locally you may need to set the ENABLE_SPANS_CONSUMER flag to True in Snuba.
  11. A way to do this is
  12. 1. run: `sentry devservices down snuba`
  13. 2. clone snuba locally
  14. 3. run: `export ENABLE_SPANS_CONSUMER=True`
  15. 4. run snuba
  16. At this point tests should work locally
  17. Once span ingestion is on by default this will no longer need to be done
  18. """
  19. @property
  20. def dataset(self):
  21. if self.is_eap:
  22. return "spans"
  23. else:
  24. return "spansIndexed"
  25. def do_request(self, query, features=None, **kwargs):
  26. query["useRpc"] = "1" if self.use_rpc else "0"
  27. return super().do_request(query, features, **kwargs)
  28. def setUp(self):
  29. super().setUp()
  30. self.features = {
  31. "organizations:starfish-view": True,
  32. }
  33. @pytest.mark.querybuilder
  34. def test_simple(self):
  35. self.store_spans(
  36. [
  37. self.create_span(
  38. {"description": "foo", "sentry_tags": {"status": "success"}},
  39. start_ts=self.ten_mins_ago,
  40. ),
  41. self.create_span(
  42. {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
  43. start_ts=self.ten_mins_ago,
  44. ),
  45. ],
  46. is_eap=self.is_eap,
  47. )
  48. response = self.do_request(
  49. {
  50. "field": ["span.status", "description", "count()"],
  51. "query": "",
  52. "orderby": "description",
  53. "project": self.project.id,
  54. "dataset": self.dataset,
  55. }
  56. )
  57. assert response.status_code == 200, response.content
  58. data = response.data["data"]
  59. meta = response.data["meta"]
  60. assert len(data) == 2
  61. assert data == [
  62. {
  63. "span.status": "invalid_argument",
  64. "description": "bar",
  65. "count()": 1,
  66. },
  67. {
  68. "span.status": "ok",
  69. "description": "foo",
  70. "count()": 1,
  71. },
  72. ]
  73. assert meta["dataset"] == self.dataset
  74. def test_spm(self):
  75. self.store_spans(
  76. [
  77. self.create_span(
  78. {"description": "foo", "sentry_tags": {"status": "success"}},
  79. start_ts=self.ten_mins_ago,
  80. ),
  81. ],
  82. is_eap=self.is_eap,
  83. )
  84. response = self.do_request(
  85. {
  86. "field": ["description", "spm()"],
  87. "query": "",
  88. "orderby": "description",
  89. "project": self.project.id,
  90. "dataset": self.dataset,
  91. }
  92. )
  93. assert response.status_code == 200, response.content
  94. data = response.data["data"]
  95. meta = response.data["meta"]
  96. assert len(data) == 1
  97. assert data == [
  98. {
  99. "description": "foo",
  100. "spm()": 1 / (90 * 24 * 60),
  101. },
  102. ]
  103. assert meta["dataset"] == self.dataset
  104. def test_id_fields(self):
  105. self.store_spans(
  106. [
  107. self.create_span(
  108. {"description": "foo", "sentry_tags": {"status": "success"}},
  109. start_ts=self.ten_mins_ago,
  110. ),
  111. self.create_span(
  112. {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
  113. start_ts=self.ten_mins_ago,
  114. ),
  115. ],
  116. is_eap=self.is_eap,
  117. )
  118. response = self.do_request(
  119. {
  120. "field": ["id", "span_id"],
  121. "query": "",
  122. "orderby": "id",
  123. "project": self.project.id,
  124. "dataset": self.dataset,
  125. }
  126. )
  127. assert response.status_code == 200, response.content
  128. data = response.data["data"]
  129. meta = response.data["meta"]
  130. assert len(data) == 2
  131. for obj in data:
  132. assert obj["id"] == obj["span_id"]
  133. assert meta["dataset"] == self.dataset
  134. def test_sentry_tags_vs_tags(self):
  135. self.store_spans(
  136. [
  137. self.create_span(
  138. {"sentry_tags": {"transaction.method": "foo"}}, start_ts=self.ten_mins_ago
  139. ),
  140. ],
  141. is_eap=self.is_eap,
  142. )
  143. response = self.do_request(
  144. {
  145. "field": ["transaction.method", "count()"],
  146. "query": "",
  147. "orderby": "count()",
  148. "project": self.project.id,
  149. "dataset": self.dataset,
  150. }
  151. )
  152. assert response.status_code == 200, response.content
  153. data = response.data["data"]
  154. meta = response.data["meta"]
  155. assert len(data) == 1
  156. assert data[0]["transaction.method"] == "foo"
  157. assert meta["dataset"] == self.dataset
  158. def test_sentry_tags_syntax(self):
  159. self.store_spans(
  160. [
  161. self.create_span(
  162. {"sentry_tags": {"transaction.method": "foo"}}, start_ts=self.ten_mins_ago
  163. ),
  164. ],
  165. is_eap=self.is_eap,
  166. )
  167. response = self.do_request(
  168. {
  169. "field": ["sentry_tags[transaction.method]", "count()"],
  170. "query": "",
  171. "orderby": "count()",
  172. "project": self.project.id,
  173. "dataset": self.dataset,
  174. }
  175. )
  176. assert response.status_code == 200, response.content
  177. data = response.data["data"]
  178. meta = response.data["meta"]
  179. assert len(data) == 1
  180. assert data[0]["sentry_tags[transaction.method]"] == "foo"
  181. assert meta["dataset"] == self.dataset
  182. def test_module_alias(self):
  183. # Delegates `span.module` to `sentry_tags[category]`. Maps `"db.redis"` spans to the `"cache"` module
  184. self.store_spans(
  185. [
  186. self.create_span(
  187. {
  188. "op": "db.redis",
  189. "description": "EXEC *",
  190. "sentry_tags": {
  191. "description": "EXEC *",
  192. "category": "db",
  193. "op": "db.redis",
  194. "transaction": "/app/index",
  195. },
  196. },
  197. start_ts=self.ten_mins_ago,
  198. ),
  199. ],
  200. is_eap=self.is_eap,
  201. )
  202. response = self.do_request(
  203. {
  204. "field": ["span.module", "span.description"],
  205. "query": "span.module:cache",
  206. "project": self.project.id,
  207. "dataset": self.dataset,
  208. }
  209. )
  210. assert response.status_code == 200, response.content
  211. data = response.data["data"]
  212. meta = response.data["meta"]
  213. assert len(data) == 1
  214. assert data[0]["span.module"] == "cache"
  215. assert data[0]["span.description"] == "EXEC *"
  216. assert meta["dataset"] == self.dataset
  217. def test_device_class_filter_unknown(self):
  218. self.store_spans(
  219. [
  220. self.create_span({"sentry_tags": {"device.class": ""}}, start_ts=self.ten_mins_ago),
  221. ],
  222. is_eap=self.is_eap,
  223. )
  224. response = self.do_request(
  225. {
  226. "field": ["device.class", "count()"],
  227. "query": "device.class:Unknown",
  228. "orderby": "count()",
  229. "project": self.project.id,
  230. "dataset": self.dataset,
  231. }
  232. )
  233. assert response.status_code == 200, response.content
  234. data = response.data["data"]
  235. meta = response.data["meta"]
  236. assert len(data) == 1
  237. assert data[0]["device.class"] == "Unknown"
  238. assert meta["dataset"] == self.dataset
  239. def test_network_span(self):
  240. self.store_spans(
  241. [
  242. self.create_span(
  243. {
  244. "sentry_tags": {
  245. "action": "GET",
  246. "category": "http",
  247. "description": "GET https://*.resource.com",
  248. "domain": "*.resource.com",
  249. "op": "http.client",
  250. "status_code": "200",
  251. "transaction": "/api/0/data/",
  252. "transaction.method": "GET",
  253. "transaction.op": "http.server",
  254. }
  255. },
  256. start_ts=self.ten_mins_ago,
  257. ),
  258. ],
  259. is_eap=self.is_eap,
  260. )
  261. response = self.do_request(
  262. {
  263. "field": ["span.op", "span.status_code"],
  264. "query": "span.module:http span.status_code:200",
  265. "project": self.project.id,
  266. "dataset": self.dataset,
  267. }
  268. )
  269. assert response.status_code == 200, response.content
  270. data = response.data["data"]
  271. meta = response.data["meta"]
  272. assert len(data) == 1
  273. assert data[0]["span.op"] == "http.client"
  274. assert data[0]["span.status_code"] == "200"
  275. assert meta["dataset"] == self.dataset
  276. def test_other_category_span(self):
  277. self.store_spans(
  278. [
  279. self.create_span(
  280. {
  281. "sentry_tags": {
  282. "action": "GET",
  283. "category": "alternative",
  284. "description": "GET https://*.resource.com",
  285. "domain": "*.resource.com",
  286. "op": "alternative",
  287. "status_code": "200",
  288. "transaction": "/api/0/data/",
  289. "transaction.method": "GET",
  290. "transaction.op": "http.server",
  291. }
  292. },
  293. start_ts=self.ten_mins_ago,
  294. ),
  295. ],
  296. is_eap=self.is_eap,
  297. )
  298. response = self.do_request(
  299. {
  300. "field": ["span.op", "span.status_code"],
  301. "query": "span.module:other span.status_code:200",
  302. "project": self.project.id,
  303. "dataset": self.dataset,
  304. }
  305. )
  306. assert response.status_code == 200, response.content
  307. data = response.data["data"]
  308. meta = response.data["meta"]
  309. assert len(data) == 1
  310. assert data[0]["span.op"] == "alternative"
  311. assert data[0]["span.status_code"] == "200"
  312. assert meta["dataset"] == self.dataset
  313. def test_inp_span(self):
  314. replay_id = uuid.uuid4().hex
  315. self.store_spans(
  316. [
  317. self.create_span(
  318. {
  319. "sentry_tags": {
  320. "replay_id": replay_id,
  321. "browser.name": "Chrome",
  322. "transaction": "/pageloads/",
  323. }
  324. },
  325. start_ts=self.ten_mins_ago,
  326. ),
  327. ],
  328. is_eap=self.is_eap,
  329. )
  330. response = self.do_request(
  331. {
  332. "field": ["replay.id", "browser.name", "origin.transaction", "count()"],
  333. "query": f"replay.id:{replay_id} AND browser.name:Chrome AND origin.transaction:/pageloads/",
  334. "orderby": "count()",
  335. "project": self.project.id,
  336. "dataset": self.dataset,
  337. }
  338. )
  339. assert response.status_code == 200, response.content
  340. data = response.data["data"]
  341. meta = response.data["meta"]
  342. assert len(data) == 1
  343. assert data[0]["replay.id"] == replay_id
  344. assert data[0]["browser.name"] == "Chrome"
  345. assert data[0]["origin.transaction"] == "/pageloads/"
  346. assert meta["dataset"] == self.dataset
  347. def test_id_filtering(self):
  348. span = self.create_span({"description": "foo"}, start_ts=self.ten_mins_ago)
  349. self.store_span(span, is_eap=self.is_eap)
  350. response = self.do_request(
  351. {
  352. "field": ["description", "count()"],
  353. "query": f"id:{span['span_id']}",
  354. "orderby": "description",
  355. "project": self.project.id,
  356. "dataset": self.dataset,
  357. }
  358. )
  359. assert response.status_code == 200, response.content
  360. data = response.data["data"]
  361. meta = response.data["meta"]
  362. assert len(data) == 1
  363. assert data[0]["description"] == "foo"
  364. assert meta["dataset"] == self.dataset
  365. response = self.do_request(
  366. {
  367. "field": ["description", "count()"],
  368. "query": f"transaction.id:{span['event_id']}",
  369. "orderby": "description",
  370. "project": self.project.id,
  371. "dataset": self.dataset,
  372. }
  373. )
  374. assert response.status_code == 200, response.content
  375. data = response.data["data"]
  376. meta = response.data["meta"]
  377. assert len(data) == 1
  378. assert data[0]["description"] == "foo"
  379. assert meta["dataset"] == self.dataset
  380. def test_span_op_casing(self):
  381. self.store_spans(
  382. [
  383. self.create_span(
  384. {
  385. "sentry_tags": {
  386. "replay_id": "abc123",
  387. "browser.name": "Chrome",
  388. "transaction": "/pageloads/",
  389. "op": "this is a transaction",
  390. }
  391. },
  392. start_ts=self.ten_mins_ago,
  393. ),
  394. ],
  395. is_eap=self.is_eap,
  396. )
  397. response = self.do_request(
  398. {
  399. "field": ["span.op", "count()"],
  400. "query": 'span.op:"ThIs Is a TraNSActiON"',
  401. "orderby": "count()",
  402. "project": self.project.id,
  403. "dataset": self.dataset,
  404. }
  405. )
  406. assert response.status_code == 200, response.content
  407. data = response.data["data"]
  408. meta = response.data["meta"]
  409. assert len(data) == 1
  410. assert data[0]["span.op"] == "this is a transaction"
  411. assert meta["dataset"] == self.dataset
  412. def test_queue_span(self):
  413. self.store_spans(
  414. [
  415. self.create_span(
  416. {
  417. "measurements": {
  418. "messaging.message.body.size": {"value": 1024, "unit": "byte"},
  419. "messaging.message.receive.latency": {
  420. "value": 1000,
  421. "unit": "millisecond",
  422. },
  423. "messaging.message.retry.count": {"value": 2, "unit": "none"},
  424. },
  425. "sentry_tags": {
  426. "transaction": "queue-processor",
  427. "messaging.destination.name": "events",
  428. "messaging.message.id": "abc123",
  429. "trace.status": "ok",
  430. },
  431. },
  432. start_ts=self.ten_mins_ago,
  433. ),
  434. ],
  435. is_eap=self.is_eap,
  436. )
  437. response = self.do_request(
  438. {
  439. "field": [
  440. "transaction",
  441. "messaging.destination.name",
  442. "messaging.message.id",
  443. "measurements.messaging.message.receive.latency",
  444. "measurements.messaging.message.body.size",
  445. "measurements.messaging.message.retry.count",
  446. "trace.status",
  447. "count()",
  448. ],
  449. "query": 'messaging.destination.name:"events"',
  450. "orderby": "count()",
  451. "project": self.project.id,
  452. "dataset": self.dataset,
  453. }
  454. )
  455. assert response.status_code == 200, response.content
  456. data = response.data["data"]
  457. meta = response.data["meta"]
  458. assert len(data) == 1
  459. assert data[0]["transaction"] == "queue-processor"
  460. assert data[0]["messaging.destination.name"] == "events"
  461. assert data[0]["messaging.message.id"] == "abc123"
  462. assert data[0]["trace.status"] == "ok"
  463. assert data[0]["measurements.messaging.message.receive.latency"] == 1000
  464. assert data[0]["measurements.messaging.message.body.size"] == 1024
  465. assert data[0]["measurements.messaging.message.retry.count"] == 2
  466. assert meta["dataset"] == self.dataset
  467. def test_tag_wildcards(self):
  468. self.store_spans(
  469. [
  470. self.create_span(
  471. {"description": "foo", "tags": {"foo": "BaR"}},
  472. start_ts=self.ten_mins_ago,
  473. ),
  474. self.create_span(
  475. {"description": "qux", "tags": {"foo": "QuX"}},
  476. start_ts=self.ten_mins_ago,
  477. ),
  478. ],
  479. is_eap=self.is_eap,
  480. )
  481. for query in [
  482. "foo:b*",
  483. "foo:*r",
  484. "foo:*a*",
  485. "foo:b*r",
  486. ]:
  487. response = self.do_request(
  488. {
  489. "field": ["foo", "count()"],
  490. "query": query,
  491. "project": self.project.id,
  492. "dataset": self.dataset,
  493. }
  494. )
  495. assert response.status_code == 200, response.content
  496. assert response.data["data"] == [{"foo": "BaR", "count()": 1}]
  497. def test_query_for_missing_tag(self):
  498. self.store_spans(
  499. [
  500. self.create_span(
  501. {"description": "foo"},
  502. start_ts=self.ten_mins_ago,
  503. ),
  504. self.create_span(
  505. {"description": "qux", "tags": {"foo": "bar"}},
  506. start_ts=self.ten_mins_ago,
  507. ),
  508. ],
  509. is_eap=self.is_eap,
  510. )
  511. response = self.do_request(
  512. {
  513. "field": ["foo", "count()"],
  514. "query": 'foo:""',
  515. "project": self.project.id,
  516. "dataset": self.dataset,
  517. }
  518. )
  519. assert response.status_code == 200, response.content
  520. assert response.data["data"] == [{"foo": "", "count()": 1}]
  521. def test_count_field_type(self):
  522. response = self.do_request(
  523. {
  524. "field": ["count()"],
  525. "project": self.project.id,
  526. "dataset": self.dataset,
  527. }
  528. )
  529. assert response.status_code == 200, response.content
  530. assert response.data["meta"]["fields"] == {"count()": "integer"}
  531. assert response.data["meta"]["units"] == {"count()": None}
  532. assert response.data["data"] == [{"count()": 0}]
  533. def test_simple_measurements(self):
  534. keys = [
  535. ("app_start_cold", "duration", "millisecond"),
  536. ("app_start_warm", "duration", "millisecond"),
  537. ("frames_frozen", "number", None),
  538. ("frames_frozen_rate", "percentage", None),
  539. ("frames_slow", "number", None),
  540. ("frames_slow_rate", "percentage", None),
  541. ("frames_total", "number", None),
  542. ("time_to_initial_display", "duration", "millisecond"),
  543. ("time_to_full_display", "duration", "millisecond"),
  544. ("stall_count", "number", None),
  545. ("stall_percentage", "percentage", None),
  546. ("stall_stall_longest_time", "number", None),
  547. ("stall_stall_total_time", "number", None),
  548. ("cls", "number", None),
  549. ("fcp", "duration", "millisecond"),
  550. ("fid", "duration", "millisecond"),
  551. ("fp", "duration", "millisecond"),
  552. ("inp", "duration", "millisecond"),
  553. ("lcp", "duration", "millisecond"),
  554. ("ttfb", "duration", "millisecond"),
  555. ("ttfb.requesttime", "duration", "millisecond"),
  556. ("score.cls", "number", None),
  557. ("score.fcp", "number", None),
  558. ("score.fid", "number", None),
  559. ("score.inp", "number", None),
  560. ("score.lcp", "number", None),
  561. ("score.ttfb", "number", None),
  562. ("score.total", "number", None),
  563. ("score.weight.cls", "number", None),
  564. ("score.weight.fcp", "number", None),
  565. ("score.weight.fid", "number", None),
  566. ("score.weight.inp", "number", None),
  567. ("score.weight.lcp", "number", None),
  568. ("score.weight.ttfb", "number", None),
  569. ("cache.item_size", "number", None),
  570. ("messaging.message.body.size", "number", None),
  571. ("messaging.message.receive.latency", "number", None),
  572. ("messaging.message.retry.count", "number", None),
  573. ("http.response_content_length", "number", None),
  574. ]
  575. self.store_spans(
  576. [
  577. self.create_span(
  578. {
  579. "description": "foo",
  580. "sentry_tags": {"status": "success"},
  581. "tags": {"bar": "bar2"},
  582. },
  583. measurements={k: {"value": i + 1} for i, (k, _, _) in enumerate(keys)},
  584. start_ts=self.ten_mins_ago,
  585. ),
  586. ],
  587. is_eap=self.is_eap,
  588. )
  589. for i, (k, type, unit) in enumerate(keys):
  590. key = f"measurements.{k}"
  591. response = self.do_request(
  592. {
  593. "field": [key],
  594. "query": "description:foo",
  595. "project": self.project.id,
  596. "dataset": self.dataset,
  597. }
  598. )
  599. assert response.status_code == 200, response.content
  600. assert response.data["meta"] == {
  601. "dataset": mock.ANY,
  602. "datasetReason": "unchanged",
  603. "fields": {
  604. key: type,
  605. "id": "string",
  606. "project.name": "string",
  607. },
  608. "isMetricsData": False,
  609. "isMetricsExtractedData": False,
  610. "tips": {},
  611. "units": {
  612. key: unit,
  613. "id": None,
  614. "project.name": None,
  615. },
  616. }
  617. assert response.data["data"] == [
  618. {
  619. key: i + 1,
  620. "id": mock.ANY,
  621. "project.name": self.project.slug,
  622. }
  623. ]
  624. def test_environment(self):
  625. self.create_environment(self.project, name="prod")
  626. self.create_environment(self.project, name="test")
  627. self.store_spans(
  628. [
  629. self.create_span(
  630. {"description": "foo", "sentry_tags": {"environment": "prod"}},
  631. start_ts=self.ten_mins_ago,
  632. ),
  633. self.create_span(
  634. {"description": "foo", "sentry_tags": {"environment": "test"}},
  635. start_ts=self.ten_mins_ago,
  636. ),
  637. ],
  638. is_eap=self.is_eap,
  639. )
  640. response = self.do_request(
  641. {
  642. "field": ["environment", "count()"],
  643. "project": self.project.id,
  644. "environment": "prod",
  645. "dataset": self.dataset,
  646. }
  647. )
  648. assert response.status_code == 200, response.content
  649. assert response.data["data"] == [
  650. {"environment": "prod", "count()": 1},
  651. ]
  652. def test_transaction(self):
  653. self.store_spans(
  654. [
  655. self.create_span(
  656. {"description": "foo", "sentry_tags": {"transaction": "bar"}},
  657. start_ts=self.ten_mins_ago,
  658. ),
  659. ],
  660. is_eap=self.is_eap,
  661. )
  662. response = self.do_request(
  663. {
  664. "field": ["description", "count()"],
  665. "query": "transaction:bar",
  666. "orderby": "description",
  667. "project": self.project.id,
  668. "dataset": self.dataset,
  669. }
  670. )
  671. assert response.status_code == 200, response.content
  672. data = response.data["data"]
  673. meta = response.data["meta"]
  674. assert len(data) == 1
  675. assert data == [
  676. {
  677. "description": "foo",
  678. "count()": 1,
  679. },
  680. ]
  681. assert meta["dataset"] == self.dataset
  682. def test_orderby_alias(self):
  683. self.store_spans(
  684. [
  685. self.create_span(
  686. {"description": "foo", "sentry_tags": {"status": "success"}},
  687. start_ts=self.ten_mins_ago,
  688. ),
  689. self.create_span(
  690. {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
  691. duration=2000,
  692. start_ts=self.ten_mins_ago,
  693. ),
  694. ],
  695. is_eap=self.is_eap,
  696. )
  697. response = self.do_request(
  698. {
  699. "field": ["span.description", "sum(span.self_time)"],
  700. "query": "",
  701. "orderby": "sum_span_self_time",
  702. "project": self.project.id,
  703. "dataset": self.dataset,
  704. }
  705. )
  706. assert response.status_code == 200, response.content
  707. data = response.data["data"]
  708. meta = response.data["meta"]
  709. assert len(data) == 2
  710. assert data == [
  711. {
  712. "span.description": "foo",
  713. "sum(span.self_time)": 1000,
  714. },
  715. {
  716. "span.description": "bar",
  717. "sum(span.self_time)": 2000,
  718. },
  719. ]
  720. assert meta["dataset"] == self.dataset
  721. @pytest.mark.querybuilder
  722. def test_explore_sample_query(self):
  723. spans = [
  724. self.create_span(
  725. {"description": "foo", "sentry_tags": {"status": "success"}},
  726. start_ts=self.ten_mins_ago,
  727. ),
  728. self.create_span(
  729. {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
  730. start_ts=self.nine_mins_ago,
  731. ),
  732. ]
  733. self.store_spans(
  734. spans,
  735. is_eap=self.is_eap,
  736. )
  737. response = self.do_request(
  738. {
  739. "field": [
  740. "id",
  741. "project",
  742. "span.op",
  743. "span.description",
  744. "span.duration",
  745. "timestamp",
  746. "trace",
  747. "transaction.span_id",
  748. ],
  749. # This is to skip INP spans
  750. "query": "!transaction.span_id:00",
  751. "orderby": "timestamp",
  752. "statsPeriod": "1h",
  753. "project": self.project.id,
  754. "dataset": self.dataset,
  755. }
  756. )
  757. assert response.status_code == 200, response.content
  758. data = response.data["data"]
  759. meta = response.data["meta"]
  760. assert len(data) == 2
  761. for source, result in zip(spans, data):
  762. assert result["id"] == source["span_id"], "id"
  763. assert result["span.duration"] == 1000.0, "duration"
  764. assert result["span.op"] == "", "op"
  765. assert result["span.description"] == source["description"], "description"
  766. assert datetime.fromisoformat(result["timestamp"]).timestamp() == pytest.approx(
  767. source["end_timestamp_precise"], abs=5
  768. ), "timestamp"
  769. assert result["transaction.span_id"] == source["segment_id"], "transaction.span_id"
  770. assert result["project"] == result["project.name"] == self.project.slug, "project"
  771. assert meta["dataset"] == self.dataset
  772. def test_span_status(self):
  773. self.store_spans(
  774. [
  775. self.create_span(
  776. {"description": "foo", "sentry_tags": {"status": "internal_error"}},
  777. start_ts=self.ten_mins_ago,
  778. ),
  779. ],
  780. is_eap=self.is_eap,
  781. )
  782. response = self.do_request(
  783. {
  784. "field": ["description", "count()"],
  785. "query": "span.status:internal_error",
  786. "orderby": "description",
  787. "project": self.project.id,
  788. "dataset": self.dataset,
  789. }
  790. )
  791. assert response.status_code == 200, response.content
  792. data = response.data["data"]
  793. meta = response.data["meta"]
  794. assert len(data) == 1
  795. assert data == [
  796. {
  797. "description": "foo",
  798. "count()": 1,
  799. },
  800. ]
  801. assert meta["dataset"] == self.dataset
  802. class OrganizationEventsEAPSpanEndpointTest(OrganizationEventsSpanIndexedEndpointTest):
  803. is_eap = True
  804. use_rpc = False
  805. def test_simple(self):
  806. self.store_spans(
  807. [
  808. self.create_span(
  809. {"description": "foo", "sentry_tags": {"status": "success"}},
  810. start_ts=self.ten_mins_ago,
  811. ),
  812. self.create_span(
  813. {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
  814. start_ts=self.ten_mins_ago,
  815. ),
  816. ],
  817. is_eap=self.is_eap,
  818. )
  819. response = self.do_request(
  820. {
  821. "field": ["span.status", "description", "count()"],
  822. "query": "",
  823. "orderby": "description",
  824. "project": self.project.id,
  825. "dataset": self.dataset,
  826. }
  827. )
  828. assert response.status_code == 200, response.content
  829. data = response.data["data"]
  830. meta = response.data["meta"]
  831. assert len(data) == 2
  832. assert data == [
  833. {
  834. "span.status": "invalid_argument",
  835. "description": "bar",
  836. "count()": 1,
  837. },
  838. {
  839. "span.status": "success",
  840. "description": "foo",
  841. "count()": 1,
  842. },
  843. ]
  844. assert meta["dataset"] == self.dataset
  845. @pytest.mark.xfail(reason="event_id isn't being written to the new table")
  846. def test_id_filtering(self):
  847. super().test_id_filtering()
  848. def test_span_duration(self):
  849. spans = [
  850. self.create_span(
  851. {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
  852. start_ts=self.ten_mins_ago,
  853. ),
  854. self.create_span(
  855. {"description": "foo", "sentry_tags": {"status": "success"}},
  856. start_ts=self.ten_mins_ago,
  857. ),
  858. ]
  859. self.store_spans(spans, is_eap=self.is_eap)
  860. response = self.do_request(
  861. {
  862. "field": ["span.duration", "description"],
  863. "query": "",
  864. "orderby": "description",
  865. "project": self.project.id,
  866. "dataset": self.dataset,
  867. }
  868. )
  869. assert response.status_code == 200, response.content
  870. data = response.data["data"]
  871. meta = response.data["meta"]
  872. assert len(data) == 2
  873. assert data == [
  874. {
  875. "span.duration": 1000.0,
  876. "description": "bar",
  877. "project.name": self.project.slug,
  878. "id": spans[0]["span_id"],
  879. },
  880. {
  881. "span.duration": 1000.0,
  882. "description": "foo",
  883. "project.name": self.project.slug,
  884. "id": spans[1]["span_id"],
  885. },
  886. ]
  887. assert meta["dataset"] == self.dataset
  888. def test_aggregate_numeric_attr_weighted(self):
  889. self.store_spans(
  890. [
  891. self.create_span(
  892. {
  893. "description": "foo",
  894. "sentry_tags": {"status": "success"},
  895. "tags": {"bar": "bar1"},
  896. },
  897. start_ts=self.ten_mins_ago,
  898. ),
  899. self.create_span(
  900. {
  901. "description": "foo",
  902. "sentry_tags": {"status": "success"},
  903. "tags": {"bar": "bar2"},
  904. },
  905. measurements={"foo": {"value": 5}},
  906. start_ts=self.ten_mins_ago,
  907. ),
  908. self.create_span(
  909. {
  910. "description": "foo",
  911. "sentry_tags": {"status": "success"},
  912. "tags": {"bar": "bar3"},
  913. },
  914. start_ts=self.ten_mins_ago,
  915. ),
  916. ],
  917. is_eap=self.is_eap,
  918. )
  919. response = self.do_request(
  920. {
  921. "field": [
  922. "description",
  923. "count_unique(bar)",
  924. "count_unique(tags[bar])",
  925. "count_unique(tags[bar,string])",
  926. "count()",
  927. "count(span.duration)",
  928. "count(tags[foo, number])",
  929. "sum(tags[foo,number])",
  930. "avg(tags[foo,number])",
  931. "p50(tags[foo,number])",
  932. "p75(tags[foo,number])",
  933. "p95(tags[foo,number])",
  934. "p99(tags[foo,number])",
  935. "p100(tags[foo,number])",
  936. "min(tags[foo,number])",
  937. "max(tags[foo,number])",
  938. ],
  939. "query": "",
  940. "orderby": "description",
  941. "project": self.project.id,
  942. "dataset": self.dataset,
  943. }
  944. )
  945. assert response.status_code == 200, response.content
  946. assert len(response.data["data"]) == 1
  947. data = response.data["data"]
  948. assert data[0] == {
  949. "description": "foo",
  950. "count_unique(bar)": 3,
  951. "count_unique(tags[bar])": 3,
  952. "count_unique(tags[bar,string])": 3,
  953. "count()": 3,
  954. "count(span.duration)": 3,
  955. "count(tags[foo, number])": 1,
  956. "sum(tags[foo,number])": 5.0,
  957. "avg(tags[foo,number])": 5.0,
  958. "p50(tags[foo,number])": 5.0,
  959. "p75(tags[foo,number])": 5.0,
  960. "p95(tags[foo,number])": 5.0,
  961. "p99(tags[foo,number])": 5.0,
  962. "p100(tags[foo,number])": 5.0,
  963. "min(tags[foo,number])": 5.0,
  964. "max(tags[foo,number])": 5.0,
  965. }
  966. def test_numeric_attr_without_space(self):
  967. self.store_spans(
  968. [
  969. self.create_span(
  970. {
  971. "description": "foo",
  972. "sentry_tags": {"status": "success"},
  973. "tags": {"foo": "five"},
  974. },
  975. measurements={"foo": {"value": 5}},
  976. start_ts=self.ten_mins_ago,
  977. ),
  978. ],
  979. is_eap=self.is_eap,
  980. )
  981. response = self.do_request(
  982. {
  983. "field": ["description", "tags[foo,number]", "tags[foo,string]", "tags[foo]"],
  984. "query": "",
  985. "orderby": "description",
  986. "project": self.project.id,
  987. "dataset": self.dataset,
  988. }
  989. )
  990. assert response.status_code == 200, response.content
  991. assert len(response.data["data"]) == 1
  992. data = response.data["data"]
  993. assert data[0]["tags[foo,number]"] == 5
  994. assert data[0]["tags[foo,string]"] == "five"
  995. assert data[0]["tags[foo]"] == "five"
  996. def test_numeric_attr_with_spaces(self):
  997. self.store_spans(
  998. [
  999. self.create_span(
  1000. {
  1001. "description": "foo",
  1002. "sentry_tags": {"status": "success"},
  1003. "tags": {"foo": "five"},
  1004. },
  1005. measurements={"foo": {"value": 5}},
  1006. start_ts=self.ten_mins_ago,
  1007. ),
  1008. ],
  1009. is_eap=self.is_eap,
  1010. )
  1011. response = self.do_request(
  1012. {
  1013. "field": ["description", "tags[foo, number]", "tags[foo, string]", "tags[foo]"],
  1014. "query": "",
  1015. "orderby": "description",
  1016. "project": self.project.id,
  1017. "dataset": self.dataset,
  1018. }
  1019. )
  1020. assert response.status_code == 200, response.content
  1021. assert len(response.data["data"]) == 1
  1022. data = response.data["data"]
  1023. assert data[0]["tags[foo, number]"] == 5
  1024. assert data[0]["tags[foo, string]"] == "five"
  1025. assert data[0]["tags[foo]"] == "five"
  1026. def test_numeric_attr_filtering(self):
  1027. self.store_spans(
  1028. [
  1029. self.create_span(
  1030. {
  1031. "description": "foo",
  1032. "sentry_tags": {"status": "success"},
  1033. "tags": {"foo": "five"},
  1034. },
  1035. measurements={"foo": {"value": 5}},
  1036. start_ts=self.ten_mins_ago,
  1037. ),
  1038. self.create_span(
  1039. {"description": "bar", "sentry_tags": {"status": "success", "foo": "five"}},
  1040. measurements={"foo": {"value": 8}},
  1041. start_ts=self.ten_mins_ago,
  1042. ),
  1043. ],
  1044. is_eap=self.is_eap,
  1045. )
  1046. response = self.do_request(
  1047. {
  1048. "field": ["description", "tags[foo,number]"],
  1049. "query": "tags[foo,number]:5",
  1050. "orderby": "description",
  1051. "project": self.project.id,
  1052. "dataset": self.dataset,
  1053. }
  1054. )
  1055. assert response.status_code == 200, response.content
  1056. assert len(response.data["data"]) == 1
  1057. data = response.data["data"]
  1058. assert data[0]["tags[foo,number]"] == 5
  1059. assert data[0]["description"] == "foo"
  1060. def test_long_attr_name(self):
  1061. response = self.do_request(
  1062. {
  1063. "field": ["description", "z" * 201],
  1064. "query": "",
  1065. "orderby": "description",
  1066. "project": self.project.id,
  1067. "dataset": self.dataset,
  1068. }
  1069. )
  1070. assert response.status_code == 400, response.content
  1071. assert "Is Too Long" in response.data["detail"].title()
  1072. def test_numeric_attr_orderby(self):
  1073. self.store_spans(
  1074. [
  1075. self.create_span(
  1076. {
  1077. "description": "baz",
  1078. "sentry_tags": {"status": "success"},
  1079. "tags": {"foo": "five"},
  1080. },
  1081. measurements={"foo": {"value": 71}},
  1082. start_ts=self.ten_mins_ago,
  1083. ),
  1084. self.create_span(
  1085. {
  1086. "description": "foo",
  1087. "sentry_tags": {"status": "success"},
  1088. "tags": {"foo": "five"},
  1089. },
  1090. measurements={"foo": {"value": 5}},
  1091. start_ts=self.ten_mins_ago,
  1092. ),
  1093. self.create_span(
  1094. {
  1095. "description": "bar",
  1096. "sentry_tags": {"status": "success"},
  1097. "tags": {"foo": "five"},
  1098. },
  1099. measurements={"foo": {"value": 8}},
  1100. start_ts=self.ten_mins_ago,
  1101. ),
  1102. ],
  1103. is_eap=self.is_eap,
  1104. )
  1105. response = self.do_request(
  1106. {
  1107. "field": ["description", "tags[foo,number]"],
  1108. "query": "",
  1109. "orderby": ["tags[foo,number]"],
  1110. "project": self.project.id,
  1111. "dataset": self.dataset,
  1112. }
  1113. )
  1114. assert response.status_code == 200, response.content
  1115. assert len(response.data["data"]) == 3
  1116. data = response.data["data"]
  1117. assert data[0]["tags[foo,number]"] == 5
  1118. assert data[0]["description"] == "foo"
  1119. assert data[1]["tags[foo,number]"] == 8
  1120. assert data[1]["description"] == "bar"
  1121. assert data[2]["tags[foo,number]"] == 71
  1122. assert data[2]["description"] == "baz"
  1123. def test_aggregate_numeric_attr(self):
  1124. self.store_spans(
  1125. [
  1126. self.create_span(
  1127. {
  1128. "description": "foo",
  1129. "sentry_tags": {"status": "success"},
  1130. "tags": {"bar": "bar1"},
  1131. },
  1132. start_ts=self.ten_mins_ago,
  1133. ),
  1134. self.create_span(
  1135. {
  1136. "description": "foo",
  1137. "sentry_tags": {"status": "success"},
  1138. "tags": {"bar": "bar2"},
  1139. },
  1140. measurements={"foo": {"value": 5}},
  1141. start_ts=self.ten_mins_ago,
  1142. ),
  1143. ],
  1144. is_eap=self.is_eap,
  1145. )
  1146. response = self.do_request(
  1147. {
  1148. "field": [
  1149. "description",
  1150. "count_unique(bar)",
  1151. "count_unique(tags[bar])",
  1152. "count_unique(tags[bar,string])",
  1153. "count()",
  1154. "count(span.duration)",
  1155. "count(tags[foo, number])",
  1156. "sum(tags[foo,number])",
  1157. "avg(tags[foo,number])",
  1158. "p50(tags[foo,number])",
  1159. "p75(tags[foo,number])",
  1160. "p95(tags[foo,number])",
  1161. "p99(tags[foo,number])",
  1162. "p100(tags[foo,number])",
  1163. "min(tags[foo,number])",
  1164. "max(tags[foo,number])",
  1165. ],
  1166. "query": "",
  1167. "orderby": "description",
  1168. "project": self.project.id,
  1169. "dataset": self.dataset,
  1170. }
  1171. )
  1172. assert response.status_code == 200, response.content
  1173. assert len(response.data["data"]) == 1
  1174. data = response.data["data"]
  1175. assert data[0] == {
  1176. "description": "foo",
  1177. "count_unique(bar)": 2,
  1178. "count_unique(tags[bar])": 2,
  1179. "count_unique(tags[bar,string])": 2,
  1180. "count()": 2,
  1181. "count(span.duration)": 2,
  1182. "count(tags[foo, number])": 1,
  1183. "sum(tags[foo,number])": 5.0,
  1184. "avg(tags[foo,number])": 5.0,
  1185. "p50(tags[foo,number])": 5.0,
  1186. "p75(tags[foo,number])": 5.0,
  1187. "p95(tags[foo,number])": 5.0,
  1188. "p99(tags[foo,number])": 5.0,
  1189. "p100(tags[foo,number])": 5.0,
  1190. "min(tags[foo,number])": 5.0,
  1191. "max(tags[foo,number])": 5.0,
  1192. }
  1193. def test_margin_of_error(self):
  1194. total_samples = 10
  1195. in_group = 5
  1196. spans = []
  1197. for _ in range(in_group):
  1198. spans.append(
  1199. self.create_span(
  1200. {
  1201. "description": "foo",
  1202. "sentry_tags": {"status": "success"},
  1203. "measurements": {"client_sample_rate": {"value": 0.00001}},
  1204. },
  1205. start_ts=self.ten_mins_ago,
  1206. )
  1207. )
  1208. for _ in range(total_samples - in_group):
  1209. spans.append(
  1210. self.create_span(
  1211. {
  1212. "description": "bar",
  1213. "sentry_tags": {"status": "success"},
  1214. "measurements": {"client_sample_rate": {"value": 0.00001}},
  1215. },
  1216. )
  1217. )
  1218. self.store_spans(
  1219. spans,
  1220. is_eap=self.is_eap,
  1221. )
  1222. response = self.do_request(
  1223. {
  1224. "field": [
  1225. "margin_of_error()",
  1226. "lower_count_limit()",
  1227. "upper_count_limit()",
  1228. "count()",
  1229. ],
  1230. "query": "description:foo",
  1231. "project": self.project.id,
  1232. "dataset": self.dataset,
  1233. }
  1234. )
  1235. assert response.status_code == 200, response.content
  1236. assert len(response.data["data"]) == 1
  1237. data = response.data["data"][0]
  1238. margin_of_error = data["margin_of_error()"]
  1239. lower_limit = data["lower_count_limit()"]
  1240. upper_limit = data["upper_count_limit()"]
  1241. extrapolated = data["count()"]
  1242. assert margin_of_error == pytest.approx(0.306, rel=1e-1)
  1243. # How to read this; these results mean that the extrapolated count is
  1244. # 500k, with a lower estimated bound of ~200k, and an upper bound of 800k
  1245. assert lower_limit == pytest.approx(190_000, abs=5000)
  1246. assert extrapolated == pytest.approx(500_000, abs=5000)
  1247. assert upper_limit == pytest.approx(810_000, abs=5000)
  1248. def test_skip_aggregate_conditions_option(self):
  1249. span_1 = self.create_span(
  1250. {"description": "foo", "sentry_tags": {"status": "success"}},
  1251. start_ts=self.ten_mins_ago,
  1252. )
  1253. span_2 = self.create_span(
  1254. {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
  1255. start_ts=self.ten_mins_ago,
  1256. )
  1257. self.store_spans(
  1258. [span_1, span_2],
  1259. is_eap=self.is_eap,
  1260. )
  1261. response = self.do_request(
  1262. {
  1263. "field": ["description"],
  1264. "query": "description:foo count():>1",
  1265. "orderby": "description",
  1266. "project": self.project.id,
  1267. "dataset": self.dataset,
  1268. "allowAggregateConditions": "0",
  1269. }
  1270. )
  1271. assert response.status_code == 200, response.content
  1272. data = response.data["data"]
  1273. meta = response.data["meta"]
  1274. assert len(data) == 1
  1275. assert data == [
  1276. {
  1277. "description": "foo",
  1278. "project.name": self.project.slug,
  1279. "id": span_1["span_id"],
  1280. },
  1281. ]
  1282. assert meta["dataset"] == self.dataset
  1283. class OrganizationEventsEAPRPCSpanEndpointTest(OrganizationEventsEAPSpanEndpointTest):
  1284. """These tests aren't fully passing yet, currently inheriting xfail from the eap tests"""
  1285. is_eap = True
  1286. use_rpc = True
  1287. def test_extrapolation(self):
  1288. """Extrapolation only changes the number when there's a sample rate"""
  1289. spans = []
  1290. spans.append(
  1291. self.create_span(
  1292. {
  1293. "description": "foo",
  1294. "sentry_tags": {"status": "success"},
  1295. "measurements": {"client_sample_rate": {"value": 0.1}},
  1296. },
  1297. start_ts=self.ten_mins_ago,
  1298. )
  1299. )
  1300. spans.append(
  1301. self.create_span(
  1302. {
  1303. "description": "bar",
  1304. "sentry_tags": {"status": "success"},
  1305. },
  1306. start_ts=self.ten_mins_ago,
  1307. )
  1308. )
  1309. self.store_spans(spans, is_eap=self.is_eap)
  1310. response = self.do_request(
  1311. {
  1312. "field": ["description", "count()"],
  1313. "orderby": "-count()",
  1314. "query": "",
  1315. "project": self.project.id,
  1316. "dataset": self.dataset,
  1317. }
  1318. )
  1319. assert response.status_code == 200, response.content
  1320. data = response.data["data"]
  1321. confidence = response.data["confidence"]
  1322. assert len(data) == 2
  1323. assert len(confidence) == 2
  1324. assert data[0]["count()"] == 10
  1325. assert confidence[0]["count()"] == "low"
  1326. assert data[1]["count()"] == 1
  1327. # Skipping this assert for now, IMO confidence for "bar" should be high, but checking with sns
  1328. # assert confidence[1]["count()"] == "high"
  1329. def test_span_duration(self):
  1330. spans = [
  1331. self.create_span(
  1332. {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
  1333. start_ts=self.ten_mins_ago,
  1334. ),
  1335. self.create_span(
  1336. {"description": "foo", "sentry_tags": {"status": "success"}},
  1337. start_ts=self.ten_mins_ago,
  1338. ),
  1339. ]
  1340. self.store_spans(spans, is_eap=self.is_eap)
  1341. response = self.do_request(
  1342. {
  1343. "field": ["span.duration", "description"],
  1344. "query": "",
  1345. "orderby": "description",
  1346. "project": self.project.id,
  1347. "dataset": self.dataset,
  1348. }
  1349. )
  1350. assert response.status_code == 200, response.content
  1351. data = response.data["data"]
  1352. meta = response.data["meta"]
  1353. assert len(data) == 2
  1354. assert data == [
  1355. {
  1356. "span.duration": 1000.0,
  1357. "description": "bar",
  1358. "project.name": self.project.slug,
  1359. "id": spans[0]["span_id"],
  1360. },
  1361. {
  1362. "span.duration": 1000.0,
  1363. "description": "foo",
  1364. "project.name": self.project.slug,
  1365. "id": spans[1]["span_id"],
  1366. },
  1367. ]
  1368. assert meta["dataset"] == self.dataset
  1369. @pytest.mark.xfail(reason="weighted functions will not be moved to the RPC")
  1370. def test_aggregate_numeric_attr_weighted(self):
  1371. super().test_aggregate_numeric_attr_weighted()
  1372. def test_aggregate_numeric_attr(self):
  1373. self.store_spans(
  1374. [
  1375. self.create_span(
  1376. {
  1377. "description": "foo",
  1378. "sentry_tags": {"status": "success"},
  1379. "tags": {"bar": "bar1"},
  1380. },
  1381. start_ts=self.ten_mins_ago,
  1382. ),
  1383. self.create_span(
  1384. {
  1385. "description": "foo",
  1386. "sentry_tags": {"status": "success"},
  1387. "tags": {"bar": "bar2"},
  1388. },
  1389. measurements={"foo": {"value": 5}},
  1390. start_ts=self.ten_mins_ago,
  1391. ),
  1392. ],
  1393. is_eap=self.is_eap,
  1394. )
  1395. response = self.do_request(
  1396. {
  1397. "field": [
  1398. "description",
  1399. "count_unique(bar)",
  1400. "count_unique(tags[bar])",
  1401. "count_unique(tags[bar,string])",
  1402. "count()",
  1403. "count(span.duration)",
  1404. "count(tags[foo, number])",
  1405. "sum(tags[foo,number])",
  1406. "avg(tags[foo,number])",
  1407. "p50(tags[foo,number])",
  1408. "p75(tags[foo,number])",
  1409. "p95(tags[foo,number])",
  1410. "p99(tags[foo,number])",
  1411. "p100(tags[foo,number])",
  1412. "min(tags[foo,number])",
  1413. "max(tags[foo,number])",
  1414. ],
  1415. "query": "",
  1416. "orderby": "description",
  1417. "project": self.project.id,
  1418. "dataset": self.dataset,
  1419. }
  1420. )
  1421. assert response.status_code == 200, response.content
  1422. assert len(response.data["data"]) == 1
  1423. data = response.data["data"]
  1424. assert data[0] == {
  1425. "description": "foo",
  1426. "count_unique(bar)": 2,
  1427. "count_unique(tags[bar])": 2,
  1428. "count_unique(tags[bar,string])": 2,
  1429. "count()": 2,
  1430. "count(span.duration)": 2,
  1431. "count(tags[foo, number])": 1,
  1432. "sum(tags[foo,number])": 5.0,
  1433. "avg(tags[foo,number])": 5.0,
  1434. "p50(tags[foo,number])": 5.0,
  1435. "p75(tags[foo,number])": 5.0,
  1436. "p95(tags[foo,number])": 5.0,
  1437. "p99(tags[foo,number])": 5.0,
  1438. "p100(tags[foo,number])": 5.0,
  1439. "min(tags[foo,number])": 5.0,
  1440. "max(tags[foo,number])": 5.0,
  1441. }
  1442. @pytest.mark.xfail(reason="margin will not be moved to the RPC")
  1443. def test_margin_of_error(self):
  1444. super().test_margin_of_error()
  1445. @pytest.mark.xfail(reason="rpc not handling attr_str vs attr_num with same alias")
  1446. def test_numeric_attr_without_space(self):
  1447. super().test_numeric_attr_without_space()
  1448. @pytest.mark.xfail(reason="rpc not handling attr_str vs attr_num with same alias")
  1449. def test_numeric_attr_with_spaces(self):
  1450. super().test_numeric_attr_with_spaces()
  1451. @pytest.mark.xfail(reason="module not migrated over")
  1452. def test_module_alias(self):
  1453. super().test_module_alias()
  1454. @pytest.mark.xfail(reason="wip: not implemented yet")
  1455. def test_inp_span(self):
  1456. super().test_inp_span()
  1457. @pytest.mark.xfail(reason="wip: not implemented yet")
  1458. def test_network_span(self):
  1459. super().test_network_span()
  1460. @pytest.mark.xfail(reason="wip: not implemented yet")
  1461. def test_other_category_span(self):
  1462. super().test_other_category_span()
  1463. @pytest.mark.xfail(reason="wip: not implemented yet")
  1464. def test_queue_span(self):
  1465. super().test_queue_span()
  1466. @pytest.mark.xfail(reason="wip: not implemented yet")
  1467. def test_sentry_tags_syntax(self):
  1468. super().test_sentry_tags_syntax()
  1469. @pytest.mark.xfail(reason="wip: not implemented yet")
  1470. def test_span_op_casing(self):
  1471. super().test_span_op_casing()
  1472. def test_tag_wildcards(self):
  1473. self.store_spans(
  1474. [
  1475. self.create_span(
  1476. {"description": "foo", "tags": {"foo": "bar"}},
  1477. start_ts=self.ten_mins_ago,
  1478. ),
  1479. self.create_span(
  1480. {"description": "qux", "tags": {"foo": "qux"}},
  1481. start_ts=self.ten_mins_ago,
  1482. ),
  1483. ],
  1484. is_eap=self.is_eap,
  1485. )
  1486. for query in [
  1487. "foo:b*",
  1488. "foo:*r",
  1489. "foo:*a*",
  1490. "foo:b*r",
  1491. ]:
  1492. response = self.do_request(
  1493. {
  1494. "field": ["foo", "count()"],
  1495. "query": query,
  1496. "project": self.project.id,
  1497. "dataset": self.dataset,
  1498. }
  1499. )
  1500. assert response.status_code == 200, response.content
  1501. assert response.data["data"] == [{"foo": "bar", "count()": 1}]
  1502. @pytest.mark.xfail(reason="rate not implemented yet")
  1503. def test_spm(self):
  1504. super().test_spm()
  1505. @pytest.mark.xfail(reason="units not implemented yet")
  1506. def test_simple_measurements(self):
  1507. super().test_simple_measurements()