test_organization_events_span_indexed.py 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603
  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. self.store_spans(spans, is_eap=self.is_eap)
  1301. response = self.do_request(
  1302. {
  1303. "field": ["count()"],
  1304. "query": "",
  1305. "project": self.project.id,
  1306. "dataset": self.dataset,
  1307. }
  1308. )
  1309. assert response.status_code == 200, response.content
  1310. data = response.data["data"]
  1311. assert len(data) == 1
  1312. assert data[0]["count()"] == 10
  1313. def test_span_duration(self):
  1314. spans = [
  1315. self.create_span(
  1316. {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
  1317. start_ts=self.ten_mins_ago,
  1318. ),
  1319. self.create_span(
  1320. {"description": "foo", "sentry_tags": {"status": "success"}},
  1321. start_ts=self.ten_mins_ago,
  1322. ),
  1323. ]
  1324. self.store_spans(spans, is_eap=self.is_eap)
  1325. response = self.do_request(
  1326. {
  1327. "field": ["span.duration", "description"],
  1328. "query": "",
  1329. "orderby": "description",
  1330. "project": self.project.id,
  1331. "dataset": self.dataset,
  1332. }
  1333. )
  1334. assert response.status_code == 200, response.content
  1335. data = response.data["data"]
  1336. meta = response.data["meta"]
  1337. assert len(data) == 2
  1338. assert data == [
  1339. {
  1340. "span.duration": 1000.0,
  1341. "description": "bar",
  1342. "project.name": self.project.slug,
  1343. "id": spans[0]["span_id"],
  1344. },
  1345. {
  1346. "span.duration": 1000.0,
  1347. "description": "foo",
  1348. "project.name": self.project.slug,
  1349. "id": spans[1]["span_id"],
  1350. },
  1351. ]
  1352. assert meta["dataset"] == self.dataset
  1353. @pytest.mark.xfail(reason="weighted functions will not be moved to the RPC")
  1354. def test_aggregate_numeric_attr_weighted(self):
  1355. super().test_aggregate_numeric_attr_weighted()
  1356. def test_aggregate_numeric_attr(self):
  1357. self.store_spans(
  1358. [
  1359. self.create_span(
  1360. {
  1361. "description": "foo",
  1362. "sentry_tags": {"status": "success"},
  1363. "tags": {"bar": "bar1"},
  1364. },
  1365. start_ts=self.ten_mins_ago,
  1366. ),
  1367. self.create_span(
  1368. {
  1369. "description": "foo",
  1370. "sentry_tags": {"status": "success"},
  1371. "tags": {"bar": "bar2"},
  1372. },
  1373. measurements={"foo": {"value": 5}},
  1374. start_ts=self.ten_mins_ago,
  1375. ),
  1376. ],
  1377. is_eap=self.is_eap,
  1378. )
  1379. response = self.do_request(
  1380. {
  1381. "field": [
  1382. "description",
  1383. "count_unique(bar)",
  1384. "count_unique(tags[bar])",
  1385. "count_unique(tags[bar,string])",
  1386. "count()",
  1387. "count(span.duration)",
  1388. "count(tags[foo, number])",
  1389. "sum(tags[foo,number])",
  1390. "avg(tags[foo,number])",
  1391. "p50(tags[foo,number])",
  1392. "p75(tags[foo,number])",
  1393. "p95(tags[foo,number])",
  1394. "p99(tags[foo,number])",
  1395. "p100(tags[foo,number])",
  1396. "min(tags[foo,number])",
  1397. "max(tags[foo,number])",
  1398. ],
  1399. "query": "",
  1400. "orderby": "description",
  1401. "project": self.project.id,
  1402. "dataset": self.dataset,
  1403. }
  1404. )
  1405. assert response.status_code == 200, response.content
  1406. assert len(response.data["data"]) == 1
  1407. data = response.data["data"]
  1408. assert data[0] == {
  1409. "description": "foo",
  1410. "count_unique(bar)": 2,
  1411. "count_unique(tags[bar])": 2,
  1412. "count_unique(tags[bar,string])": 2,
  1413. "count()": 2,
  1414. "count(span.duration)": 2,
  1415. "count(tags[foo, number])": 1,
  1416. "sum(tags[foo,number])": 5.0,
  1417. "avg(tags[foo,number])": 5.0,
  1418. "p50(tags[foo,number])": 5.0,
  1419. "p75(tags[foo,number])": 5.0,
  1420. "p95(tags[foo,number])": 5.0,
  1421. "p99(tags[foo,number])": 5.0,
  1422. "p100(tags[foo,number])": 5.0,
  1423. "min(tags[foo,number])": 5.0,
  1424. "max(tags[foo,number])": 5.0,
  1425. }
  1426. @pytest.mark.xfail(reason="margin will not be moved to the RPC")
  1427. def test_margin_of_error(self):
  1428. super().test_margin_of_error()
  1429. @pytest.mark.xfail(reason="rpc not handling attr_str vs attr_num with same alias")
  1430. def test_numeric_attr_without_space(self):
  1431. super().test_numeric_attr_without_space()
  1432. @pytest.mark.xfail(reason="rpc not handling attr_str vs attr_num with same alias")
  1433. def test_numeric_attr_with_spaces(self):
  1434. super().test_numeric_attr_with_spaces()
  1435. @pytest.mark.xfail(reason="module not migrated over")
  1436. def test_module_alias(self):
  1437. super().test_module_alias()
  1438. @pytest.mark.xfail(reason="wip: not implemented yet")
  1439. def test_inp_span(self):
  1440. super().test_inp_span()
  1441. @pytest.mark.xfail(reason="wip: not implemented yet")
  1442. def test_network_span(self):
  1443. super().test_network_span()
  1444. @pytest.mark.xfail(reason="wip: not implemented yet")
  1445. def test_other_category_span(self):
  1446. super().test_other_category_span()
  1447. @pytest.mark.xfail(reason="wip: not implemented yet")
  1448. def test_queue_span(self):
  1449. super().test_queue_span()
  1450. @pytest.mark.xfail(reason="wip: not implemented yet")
  1451. def test_sentry_tags_syntax(self):
  1452. super().test_sentry_tags_syntax()
  1453. @pytest.mark.xfail(reason="wip: not implemented yet")
  1454. def test_span_op_casing(self):
  1455. super().test_span_op_casing()
  1456. def test_tag_wildcards(self):
  1457. self.store_spans(
  1458. [
  1459. self.create_span(
  1460. {"description": "foo", "tags": {"foo": "bar"}},
  1461. start_ts=self.ten_mins_ago,
  1462. ),
  1463. self.create_span(
  1464. {"description": "qux", "tags": {"foo": "qux"}},
  1465. start_ts=self.ten_mins_ago,
  1466. ),
  1467. ],
  1468. is_eap=self.is_eap,
  1469. )
  1470. for query in [
  1471. "foo:b*",
  1472. "foo:*r",
  1473. "foo:*a*",
  1474. "foo:b*r",
  1475. ]:
  1476. response = self.do_request(
  1477. {
  1478. "field": ["foo", "count()"],
  1479. "query": query,
  1480. "project": self.project.id,
  1481. "dataset": self.dataset,
  1482. }
  1483. )
  1484. assert response.status_code == 200, response.content
  1485. assert response.data["data"] == [{"foo": "bar", "count()": 1}]
  1486. @pytest.mark.xfail(reason="rate not implemented yet")
  1487. def test_spm(self):
  1488. super().test_spm()
  1489. @pytest.mark.xfail(reason="units not implemented yet")
  1490. def test_simple_measurements(self):
  1491. super().test_simple_measurements()