12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619 |
- import uuid
- from datetime import datetime
- from unittest import mock
- import pytest
- from tests.snuba.api.endpoints.test_organization_events import OrganizationEventsEndpointTestBase
- class OrganizationEventsSpanIndexedEndpointTest(OrganizationEventsEndpointTestBase):
- is_eap = False
- use_rpc = False
- """Test the indexed spans dataset.
- To run this locally you may need to set the ENABLE_SPANS_CONSUMER flag to True in Snuba.
- A way to do this is
- 1. run: `sentry devservices down snuba`
- 2. clone snuba locally
- 3. run: `export ENABLE_SPANS_CONSUMER=True`
- 4. run snuba
- At this point tests should work locally
- Once span ingestion is on by default this will no longer need to be done
- """
- @property
- def dataset(self):
- if self.is_eap:
- return "spans"
- else:
- return "spansIndexed"
- def do_request(self, query, features=None, **kwargs):
- query["useRpc"] = "1" if self.use_rpc else "0"
- return super().do_request(query, features, **kwargs)
- def setUp(self):
- super().setUp()
- self.features = {
- "organizations:starfish-view": True,
- }
- @pytest.mark.querybuilder
- def test_simple(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "sentry_tags": {"status": "success"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["span.status", "description", "count()"],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- assert data == [
- {
- "span.status": "invalid_argument",
- "description": "bar",
- "count()": 1,
- },
- {
- "span.status": "ok",
- "description": "foo",
- "count()": 1,
- },
- ]
- assert meta["dataset"] == self.dataset
- def test_spm(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "sentry_tags": {"status": "success"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["description", "spm()"],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data == [
- {
- "description": "foo",
- "spm()": 1 / (90 * 24 * 60),
- },
- ]
- assert meta["dataset"] == self.dataset
- def test_id_fields(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "sentry_tags": {"status": "success"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["id", "span_id"],
- "query": "",
- "orderby": "id",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- for obj in data:
- assert obj["id"] == obj["span_id"]
- assert meta["dataset"] == self.dataset
- def test_sentry_tags_vs_tags(self):
- self.store_spans(
- [
- self.create_span(
- {"sentry_tags": {"transaction.method": "foo"}}, start_ts=self.ten_mins_ago
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["transaction.method", "count()"],
- "query": "",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["transaction.method"] == "foo"
- assert meta["dataset"] == self.dataset
- def test_sentry_tags_syntax(self):
- self.store_spans(
- [
- self.create_span(
- {"sentry_tags": {"transaction.method": "foo"}}, start_ts=self.ten_mins_ago
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["sentry_tags[transaction.method]", "count()"],
- "query": "",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["sentry_tags[transaction.method]"] == "foo"
- assert meta["dataset"] == self.dataset
- def test_module_alias(self):
- # Delegates `span.module` to `sentry_tags[category]`. Maps `"db.redis"` spans to the `"cache"` module
- self.store_spans(
- [
- self.create_span(
- {
- "op": "db.redis",
- "description": "EXEC *",
- "sentry_tags": {
- "description": "EXEC *",
- "category": "db",
- "op": "db.redis",
- "transaction": "/app/index",
- },
- },
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["span.module", "span.description"],
- "query": "span.module:cache",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["span.module"] == "cache"
- assert data[0]["span.description"] == "EXEC *"
- assert meta["dataset"] == self.dataset
- def test_device_class_filter_unknown(self):
- self.store_spans(
- [
- self.create_span({"sentry_tags": {"device.class": ""}}, start_ts=self.ten_mins_ago),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["device.class", "count()"],
- "query": "device.class:Unknown",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["device.class"] == "Unknown"
- assert meta["dataset"] == self.dataset
- def test_network_span(self):
- self.store_spans(
- [
- self.create_span(
- {
- "sentry_tags": {
- "action": "GET",
- "category": "http",
- "description": "GET https://*.resource.com",
- "domain": "*.resource.com",
- "op": "http.client",
- "status_code": "200",
- "transaction": "/api/0/data/",
- "transaction.method": "GET",
- "transaction.op": "http.server",
- }
- },
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["span.op", "span.status_code"],
- "query": "span.module:http span.status_code:200",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["span.op"] == "http.client"
- assert data[0]["span.status_code"] == "200"
- assert meta["dataset"] == self.dataset
- def test_other_category_span(self):
- self.store_spans(
- [
- self.create_span(
- {
- "sentry_tags": {
- "action": "GET",
- "category": "alternative",
- "description": "GET https://*.resource.com",
- "domain": "*.resource.com",
- "op": "alternative",
- "status_code": "200",
- "transaction": "/api/0/data/",
- "transaction.method": "GET",
- "transaction.op": "http.server",
- }
- },
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["span.op", "span.status_code"],
- "query": "span.module:other span.status_code:200",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["span.op"] == "alternative"
- assert data[0]["span.status_code"] == "200"
- assert meta["dataset"] == self.dataset
- def test_inp_span(self):
- replay_id = uuid.uuid4().hex
- self.store_spans(
- [
- self.create_span(
- {
- "sentry_tags": {
- "replay_id": replay_id,
- "browser.name": "Chrome",
- "transaction": "/pageloads/",
- }
- },
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["replay.id", "browser.name", "origin.transaction", "count()"],
- "query": f"replay.id:{replay_id} AND browser.name:Chrome AND origin.transaction:/pageloads/",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["replay.id"] == replay_id
- assert data[0]["browser.name"] == "Chrome"
- assert data[0]["origin.transaction"] == "/pageloads/"
- assert meta["dataset"] == self.dataset
- def test_id_filtering(self):
- span = self.create_span({"description": "foo"}, start_ts=self.ten_mins_ago)
- self.store_span(span, is_eap=self.is_eap)
- response = self.do_request(
- {
- "field": ["description", "count()"],
- "query": f"id:{span['span_id']}",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["description"] == "foo"
- assert meta["dataset"] == self.dataset
- response = self.do_request(
- {
- "field": ["description", "count()"],
- "query": f"transaction.id:{span['event_id']}",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["description"] == "foo"
- assert meta["dataset"] == self.dataset
- def test_span_op_casing(self):
- self.store_spans(
- [
- self.create_span(
- {
- "sentry_tags": {
- "replay_id": "abc123",
- "browser.name": "Chrome",
- "transaction": "/pageloads/",
- "op": "this is a transaction",
- }
- },
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["span.op", "count()"],
- "query": 'span.op:"ThIs Is a TraNSActiON"',
- "orderby": "count()",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["span.op"] == "this is a transaction"
- assert meta["dataset"] == self.dataset
- def test_queue_span(self):
- self.store_spans(
- [
- self.create_span(
- {
- "measurements": {
- "messaging.message.body.size": {"value": 1024, "unit": "byte"},
- "messaging.message.receive.latency": {
- "value": 1000,
- "unit": "millisecond",
- },
- "messaging.message.retry.count": {"value": 2, "unit": "none"},
- },
- "sentry_tags": {
- "transaction": "queue-processor",
- "messaging.destination.name": "events",
- "messaging.message.id": "abc123",
- "trace.status": "ok",
- },
- },
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": [
- "transaction",
- "messaging.destination.name",
- "messaging.message.id",
- "measurements.messaging.message.receive.latency",
- "measurements.messaging.message.body.size",
- "measurements.messaging.message.retry.count",
- "trace.status",
- "count()",
- ],
- "query": 'messaging.destination.name:"events"',
- "orderby": "count()",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data[0]["transaction"] == "queue-processor"
- assert data[0]["messaging.destination.name"] == "events"
- assert data[0]["messaging.message.id"] == "abc123"
- assert data[0]["trace.status"] == "ok"
- assert data[0]["measurements.messaging.message.receive.latency"] == 1000
- assert data[0]["measurements.messaging.message.body.size"] == 1024
- assert data[0]["measurements.messaging.message.retry.count"] == 2
- assert meta["dataset"] == self.dataset
- def test_tag_wildcards(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "tags": {"foo": "BaR"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "qux", "tags": {"foo": "QuX"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- for query in [
- "foo:b*",
- "foo:*r",
- "foo:*a*",
- "foo:b*r",
- ]:
- response = self.do_request(
- {
- "field": ["foo", "count()"],
- "query": query,
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert response.data["data"] == [{"foo": "BaR", "count()": 1}]
- def test_query_for_missing_tag(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo"},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "qux", "tags": {"foo": "bar"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["foo", "count()"],
- "query": 'foo:""',
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert response.data["data"] == [{"foo": "", "count()": 1}]
- def test_count_field_type(self):
- response = self.do_request(
- {
- "field": ["count()"],
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert response.data["meta"]["fields"] == {"count()": "integer"}
- assert response.data["meta"]["units"] == {"count()": None}
- assert response.data["data"] == [{"count()": 0}]
- def test_simple_measurements(self):
- keys = [
- ("app_start_cold", "duration", "millisecond"),
- ("app_start_warm", "duration", "millisecond"),
- ("frames_frozen", "number", None),
- ("frames_frozen_rate", "percentage", None),
- ("frames_slow", "number", None),
- ("frames_slow_rate", "percentage", None),
- ("frames_total", "number", None),
- ("time_to_initial_display", "duration", "millisecond"),
- ("time_to_full_display", "duration", "millisecond"),
- ("stall_count", "number", None),
- ("stall_percentage", "percentage", None),
- ("stall_stall_longest_time", "number", None),
- ("stall_stall_total_time", "number", None),
- ("cls", "number", None),
- ("fcp", "duration", "millisecond"),
- ("fid", "duration", "millisecond"),
- ("fp", "duration", "millisecond"),
- ("inp", "duration", "millisecond"),
- ("lcp", "duration", "millisecond"),
- ("ttfb", "duration", "millisecond"),
- ("ttfb.requesttime", "duration", "millisecond"),
- ("score.cls", "number", None),
- ("score.fcp", "number", None),
- ("score.fid", "number", None),
- ("score.inp", "number", None),
- ("score.lcp", "number", None),
- ("score.ttfb", "number", None),
- ("score.total", "number", None),
- ("score.weight.cls", "number", None),
- ("score.weight.fcp", "number", None),
- ("score.weight.fid", "number", None),
- ("score.weight.inp", "number", None),
- ("score.weight.lcp", "number", None),
- ("score.weight.ttfb", "number", None),
- ("cache.item_size", "number", None),
- ("messaging.message.body.size", "number", None),
- ("messaging.message.receive.latency", "number", None),
- ("messaging.message.retry.count", "number", None),
- ("http.response_content_length", "number", None),
- ]
- self.store_spans(
- [
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"bar": "bar2"},
- },
- measurements={k: {"value": i + 1} for i, (k, _, _) in enumerate(keys)},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- for i, (k, type, unit) in enumerate(keys):
- key = f"measurements.{k}"
- response = self.do_request(
- {
- "field": [key],
- "query": "description:foo",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert response.data["meta"] == {
- "dataset": mock.ANY,
- "datasetReason": "unchanged",
- "fields": {
- key: type,
- "id": "string",
- "project.name": "string",
- },
- "isMetricsData": False,
- "isMetricsExtractedData": False,
- "tips": {},
- "units": {
- key: unit,
- "id": None,
- "project.name": None,
- },
- }
- assert response.data["data"] == [
- {
- key: i + 1,
- "id": mock.ANY,
- "project.name": self.project.slug,
- }
- ]
- def test_environment(self):
- self.create_environment(self.project, name="prod")
- self.create_environment(self.project, name="test")
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "sentry_tags": {"environment": "prod"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "foo", "sentry_tags": {"environment": "test"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["environment", "count()"],
- "project": self.project.id,
- "environment": "prod",
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert response.data["data"] == [
- {"environment": "prod", "count()": 1},
- ]
- def test_transaction(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "sentry_tags": {"transaction": "bar"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["description", "count()"],
- "query": "transaction:bar",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data == [
- {
- "description": "foo",
- "count()": 1,
- },
- ]
- assert meta["dataset"] == self.dataset
- def test_orderby_alias(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "sentry_tags": {"status": "success"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
- duration=2000,
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["span.description", "sum(span.self_time)"],
- "query": "",
- "orderby": "sum_span_self_time",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- assert data == [
- {
- "span.description": "foo",
- "sum(span.self_time)": 1000,
- },
- {
- "span.description": "bar",
- "sum(span.self_time)": 2000,
- },
- ]
- assert meta["dataset"] == self.dataset
- @pytest.mark.querybuilder
- def test_explore_sample_query(self):
- spans = [
- self.create_span(
- {"description": "foo", "sentry_tags": {"status": "success"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
- start_ts=self.nine_mins_ago,
- ),
- ]
- self.store_spans(
- spans,
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": [
- "id",
- "project",
- "span.op",
- "span.description",
- "span.duration",
- "timestamp",
- "trace",
- "transaction.span_id",
- ],
- # This is to skip INP spans
- "query": "!transaction.span_id:00",
- "orderby": "timestamp",
- "statsPeriod": "1h",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- for source, result in zip(spans, data):
- assert result["id"] == source["span_id"], "id"
- assert result["span.duration"] == 1000.0, "duration"
- assert result["span.op"] == "", "op"
- assert result["span.description"] == source["description"], "description"
- assert datetime.fromisoformat(result["timestamp"]).timestamp() == pytest.approx(
- source["end_timestamp_precise"], abs=5
- ), "timestamp"
- assert result["transaction.span_id"] == source["segment_id"], "transaction.span_id"
- assert result["project"] == result["project.name"] == self.project.slug, "project"
- assert meta["dataset"] == self.dataset
- def test_span_status(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "sentry_tags": {"status": "internal_error"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["description", "count()"],
- "query": "span.status:internal_error",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data == [
- {
- "description": "foo",
- "count()": 1,
- },
- ]
- assert meta["dataset"] == self.dataset
- class OrganizationEventsEAPSpanEndpointTest(OrganizationEventsSpanIndexedEndpointTest):
- is_eap = True
- use_rpc = False
- def test_simple(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "sentry_tags": {"status": "success"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["span.status", "description", "count()"],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- assert data == [
- {
- "span.status": "invalid_argument",
- "description": "bar",
- "count()": 1,
- },
- {
- "span.status": "success",
- "description": "foo",
- "count()": 1,
- },
- ]
- assert meta["dataset"] == self.dataset
- @pytest.mark.xfail(reason="event_id isn't being written to the new table")
- def test_id_filtering(self):
- super().test_id_filtering()
- def test_span_duration(self):
- spans = [
- self.create_span(
- {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "foo", "sentry_tags": {"status": "success"}},
- start_ts=self.ten_mins_ago,
- ),
- ]
- self.store_spans(spans, is_eap=self.is_eap)
- response = self.do_request(
- {
- "field": ["span.duration", "description"],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- assert data == [
- {
- "span.duration": 1000.0,
- "description": "bar",
- "project.name": self.project.slug,
- "id": spans[0]["span_id"],
- },
- {
- "span.duration": 1000.0,
- "description": "foo",
- "project.name": self.project.slug,
- "id": spans[1]["span_id"],
- },
- ]
- assert meta["dataset"] == self.dataset
- def test_aggregate_numeric_attr_weighted(self):
- self.store_spans(
- [
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"bar": "bar1"},
- },
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"bar": "bar2"},
- },
- measurements={"foo": {"value": 5}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"bar": "bar3"},
- },
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": [
- "description",
- "count_unique(bar)",
- "count_unique(tags[bar])",
- "count_unique(tags[bar,string])",
- "count()",
- "count(span.duration)",
- "count(tags[foo, number])",
- "sum(tags[foo,number])",
- "avg(tags[foo,number])",
- "p50(tags[foo,number])",
- "p75(tags[foo,number])",
- "p95(tags[foo,number])",
- "p99(tags[foo,number])",
- "p100(tags[foo,number])",
- "min(tags[foo,number])",
- "max(tags[foo,number])",
- ],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0] == {
- "description": "foo",
- "count_unique(bar)": 3,
- "count_unique(tags[bar])": 3,
- "count_unique(tags[bar,string])": 3,
- "count()": 3,
- "count(span.duration)": 3,
- "count(tags[foo, number])": 1,
- "sum(tags[foo,number])": 5.0,
- "avg(tags[foo,number])": 5.0,
- "p50(tags[foo,number])": 5.0,
- "p75(tags[foo,number])": 5.0,
- "p95(tags[foo,number])": 5.0,
- "p99(tags[foo,number])": 5.0,
- "p100(tags[foo,number])": 5.0,
- "min(tags[foo,number])": 5.0,
- "max(tags[foo,number])": 5.0,
- }
- def test_numeric_attr_without_space(self):
- self.store_spans(
- [
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"foo": "five"},
- },
- measurements={"foo": {"value": 5}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["description", "tags[foo,number]", "tags[foo,string]", "tags[foo]"],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["tags[foo,number]"] == 5
- assert data[0]["tags[foo,string]"] == "five"
- assert data[0]["tags[foo]"] == "five"
- def test_numeric_attr_with_spaces(self):
- self.store_spans(
- [
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"foo": "five"},
- },
- measurements={"foo": {"value": 5}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["description", "tags[foo, number]", "tags[foo, string]", "tags[foo]"],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["tags[foo, number]"] == 5
- assert data[0]["tags[foo, string]"] == "five"
- assert data[0]["tags[foo]"] == "five"
- def test_numeric_attr_filtering(self):
- self.store_spans(
- [
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"foo": "five"},
- },
- measurements={"foo": {"value": 5}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "bar", "sentry_tags": {"status": "success", "foo": "five"}},
- measurements={"foo": {"value": 8}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["description", "tags[foo,number]"],
- "query": "tags[foo,number]:5",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0]["tags[foo,number]"] == 5
- assert data[0]["description"] == "foo"
- def test_long_attr_name(self):
- response = self.do_request(
- {
- "field": ["description", "z" * 201],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 400, response.content
- assert "Is Too Long" in response.data["detail"].title()
- def test_numeric_attr_orderby(self):
- self.store_spans(
- [
- self.create_span(
- {
- "description": "baz",
- "sentry_tags": {"status": "success"},
- "tags": {"foo": "five"},
- },
- measurements={"foo": {"value": 71}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"foo": "five"},
- },
- measurements={"foo": {"value": 5}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {
- "description": "bar",
- "sentry_tags": {"status": "success"},
- "tags": {"foo": "five"},
- },
- measurements={"foo": {"value": 8}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["description", "tags[foo,number]"],
- "query": "",
- "orderby": ["tags[foo,number]"],
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 3
- data = response.data["data"]
- assert data[0]["tags[foo,number]"] == 5
- assert data[0]["description"] == "foo"
- assert data[1]["tags[foo,number]"] == 8
- assert data[1]["description"] == "bar"
- assert data[2]["tags[foo,number]"] == 71
- assert data[2]["description"] == "baz"
- def test_aggregate_numeric_attr(self):
- self.store_spans(
- [
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"bar": "bar1"},
- },
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"bar": "bar2"},
- },
- measurements={"foo": {"value": 5}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": [
- "description",
- "count_unique(bar)",
- "count_unique(tags[bar])",
- "count_unique(tags[bar,string])",
- "count()",
- "count(span.duration)",
- "count(tags[foo, number])",
- "sum(tags[foo,number])",
- "avg(tags[foo,number])",
- "p50(tags[foo,number])",
- "p75(tags[foo,number])",
- "p95(tags[foo,number])",
- "p99(tags[foo,number])",
- "p100(tags[foo,number])",
- "min(tags[foo,number])",
- "max(tags[foo,number])",
- ],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0] == {
- "description": "foo",
- "count_unique(bar)": 2,
- "count_unique(tags[bar])": 2,
- "count_unique(tags[bar,string])": 2,
- "count()": 2,
- "count(span.duration)": 2,
- "count(tags[foo, number])": 1,
- "sum(tags[foo,number])": 5.0,
- "avg(tags[foo,number])": 5.0,
- "p50(tags[foo,number])": 5.0,
- "p75(tags[foo,number])": 5.0,
- "p95(tags[foo,number])": 5.0,
- "p99(tags[foo,number])": 5.0,
- "p100(tags[foo,number])": 5.0,
- "min(tags[foo,number])": 5.0,
- "max(tags[foo,number])": 5.0,
- }
- def test_margin_of_error(self):
- total_samples = 10
- in_group = 5
- spans = []
- for _ in range(in_group):
- spans.append(
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "measurements": {"client_sample_rate": {"value": 0.00001}},
- },
- start_ts=self.ten_mins_ago,
- )
- )
- for _ in range(total_samples - in_group):
- spans.append(
- self.create_span(
- {
- "description": "bar",
- "sentry_tags": {"status": "success"},
- "measurements": {"client_sample_rate": {"value": 0.00001}},
- },
- )
- )
- self.store_spans(
- spans,
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": [
- "margin_of_error()",
- "lower_count_limit()",
- "upper_count_limit()",
- "count()",
- ],
- "query": "description:foo",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"][0]
- margin_of_error = data["margin_of_error()"]
- lower_limit = data["lower_count_limit()"]
- upper_limit = data["upper_count_limit()"]
- extrapolated = data["count()"]
- assert margin_of_error == pytest.approx(0.306, rel=1e-1)
- # How to read this; these results mean that the extrapolated count is
- # 500k, with a lower estimated bound of ~200k, and an upper bound of 800k
- assert lower_limit == pytest.approx(190_000, abs=5000)
- assert extrapolated == pytest.approx(500_000, abs=5000)
- assert upper_limit == pytest.approx(810_000, abs=5000)
- def test_skip_aggregate_conditions_option(self):
- span_1 = self.create_span(
- {"description": "foo", "sentry_tags": {"status": "success"}},
- start_ts=self.ten_mins_ago,
- )
- span_2 = self.create_span(
- {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
- start_ts=self.ten_mins_ago,
- )
- self.store_spans(
- [span_1, span_2],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": ["description"],
- "query": "description:foo count():>1",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- "allowAggregateConditions": "0",
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 1
- assert data == [
- {
- "description": "foo",
- "project.name": self.project.slug,
- "id": span_1["span_id"],
- },
- ]
- assert meta["dataset"] == self.dataset
- class OrganizationEventsEAPRPCSpanEndpointTest(OrganizationEventsEAPSpanEndpointTest):
- """These tests aren't fully passing yet, currently inheriting xfail from the eap tests"""
- is_eap = True
- use_rpc = True
- def test_extrapolation(self):
- """Extrapolation only changes the number when there's a sample rate"""
- spans = []
- spans.append(
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "measurements": {"client_sample_rate": {"value": 0.1}},
- },
- start_ts=self.ten_mins_ago,
- )
- )
- spans.append(
- self.create_span(
- {
- "description": "bar",
- "sentry_tags": {"status": "success"},
- },
- start_ts=self.ten_mins_ago,
- )
- )
- self.store_spans(spans, is_eap=self.is_eap)
- response = self.do_request(
- {
- "field": ["description", "count()"],
- "orderby": "-count()",
- "query": "",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- confidence = response.data["confidence"]
- assert len(data) == 2
- assert len(confidence) == 2
- assert data[0]["count()"] == 10
- assert confidence[0]["count()"] == "low"
- assert data[1]["count()"] == 1
- # Skipping this assert for now, IMO confidence for "bar" should be high, but checking with sns
- # assert confidence[1]["count()"] == "high"
- def test_span_duration(self):
- spans = [
- self.create_span(
- {"description": "bar", "sentry_tags": {"status": "invalid_argument"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "foo", "sentry_tags": {"status": "success"}},
- start_ts=self.ten_mins_ago,
- ),
- ]
- self.store_spans(spans, is_eap=self.is_eap)
- response = self.do_request(
- {
- "field": ["span.duration", "description"],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- data = response.data["data"]
- meta = response.data["meta"]
- assert len(data) == 2
- assert data == [
- {
- "span.duration": 1000.0,
- "description": "bar",
- "project.name": self.project.slug,
- "id": spans[0]["span_id"],
- },
- {
- "span.duration": 1000.0,
- "description": "foo",
- "project.name": self.project.slug,
- "id": spans[1]["span_id"],
- },
- ]
- assert meta["dataset"] == self.dataset
- @pytest.mark.xfail(reason="weighted functions will not be moved to the RPC")
- def test_aggregate_numeric_attr_weighted(self):
- super().test_aggregate_numeric_attr_weighted()
- def test_aggregate_numeric_attr(self):
- self.store_spans(
- [
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"bar": "bar1"},
- },
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {
- "description": "foo",
- "sentry_tags": {"status": "success"},
- "tags": {"bar": "bar2"},
- },
- measurements={"foo": {"value": 5}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- response = self.do_request(
- {
- "field": [
- "description",
- "count_unique(bar)",
- "count_unique(tags[bar])",
- "count_unique(tags[bar,string])",
- "count()",
- "count(span.duration)",
- "count(tags[foo, number])",
- "sum(tags[foo,number])",
- "avg(tags[foo,number])",
- "p50(tags[foo,number])",
- "p75(tags[foo,number])",
- "p95(tags[foo,number])",
- "p99(tags[foo,number])",
- "p100(tags[foo,number])",
- "min(tags[foo,number])",
- "max(tags[foo,number])",
- ],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert len(response.data["data"]) == 1
- data = response.data["data"]
- assert data[0] == {
- "description": "foo",
- "count_unique(bar)": 2,
- "count_unique(tags[bar])": 2,
- "count_unique(tags[bar,string])": 2,
- "count()": 2,
- "count(span.duration)": 2,
- "count(tags[foo, number])": 1,
- "sum(tags[foo,number])": 5.0,
- "avg(tags[foo,number])": 5.0,
- "p50(tags[foo,number])": 5.0,
- "p75(tags[foo,number])": 5.0,
- "p95(tags[foo,number])": 5.0,
- "p99(tags[foo,number])": 5.0,
- "p100(tags[foo,number])": 5.0,
- "min(tags[foo,number])": 5.0,
- "max(tags[foo,number])": 5.0,
- }
- @pytest.mark.xfail(reason="margin will not be moved to the RPC")
- def test_margin_of_error(self):
- super().test_margin_of_error()
- @pytest.mark.xfail(reason="rpc not handling attr_str vs attr_num with same alias")
- def test_numeric_attr_without_space(self):
- super().test_numeric_attr_without_space()
- @pytest.mark.xfail(reason="rpc not handling attr_str vs attr_num with same alias")
- def test_numeric_attr_with_spaces(self):
- super().test_numeric_attr_with_spaces()
- @pytest.mark.xfail(reason="module not migrated over")
- def test_module_alias(self):
- super().test_module_alias()
- @pytest.mark.xfail(reason="wip: not implemented yet")
- def test_inp_span(self):
- super().test_inp_span()
- @pytest.mark.xfail(reason="wip: not implemented yet")
- def test_network_span(self):
- super().test_network_span()
- @pytest.mark.xfail(reason="wip: not implemented yet")
- def test_other_category_span(self):
- super().test_other_category_span()
- @pytest.mark.xfail(reason="wip: not implemented yet")
- def test_queue_span(self):
- super().test_queue_span()
- @pytest.mark.xfail(reason="wip: not implemented yet")
- def test_sentry_tags_syntax(self):
- super().test_sentry_tags_syntax()
- @pytest.mark.xfail(reason="wip: not implemented yet")
- def test_span_op_casing(self):
- super().test_span_op_casing()
- def test_tag_wildcards(self):
- self.store_spans(
- [
- self.create_span(
- {"description": "foo", "tags": {"foo": "bar"}},
- start_ts=self.ten_mins_ago,
- ),
- self.create_span(
- {"description": "qux", "tags": {"foo": "qux"}},
- start_ts=self.ten_mins_ago,
- ),
- ],
- is_eap=self.is_eap,
- )
- for query in [
- "foo:b*",
- "foo:*r",
- "foo:*a*",
- "foo:b*r",
- ]:
- response = self.do_request(
- {
- "field": ["foo", "count()"],
- "query": query,
- "project": self.project.id,
- "dataset": self.dataset,
- }
- )
- assert response.status_code == 200, response.content
- assert response.data["data"] == [{"foo": "bar", "count()": 1}]
- @pytest.mark.xfail(reason="rate not implemented yet")
- def test_spm(self):
- super().test_spm()
- @pytest.mark.xfail(reason="units not implemented yet")
- def test_simple_measurements(self):
- super().test_simple_measurements()
|