123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- import uuid
- import pytest
- from tests.snuba.api.endpoints.test_organization_events import OrganizationEventsEndpointTestBase
- class OrganizationEventsSpanIndexedEndpointTest(OrganizationEventsEndpointTestBase):
- """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
- """
- 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,
- ),
- ]
- )
- response = self.do_request(
- {
- "field": ["span.status", "description", "count()"],
- "query": "",
- "orderby": "description",
- "project": self.project.id,
- "dataset": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- def test_sentry_tags_vs_tags(self):
- self.store_spans(
- [
- self.create_span(
- {"sentry_tags": {"transaction.method": "foo"}}, start_ts=self.ten_mins_ago
- ),
- ]
- )
- response = self.do_request(
- {
- "field": ["transaction.method", "count()"],
- "query": "",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- def test_sentry_tags_syntax(self):
- self.store_spans(
- [
- self.create_span(
- {"sentry_tags": {"transaction.method": "foo"}}, start_ts=self.ten_mins_ago
- ),
- ]
- )
- response = self.do_request(
- {
- "field": ["sentry_tags[transaction.method]", "count()"],
- "query": "",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- 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,
- ),
- ]
- )
- response = self.do_request(
- {
- "field": ["span.module", "span.description"],
- "query": "span.module:cache",
- "project": self.project.id,
- "dataset": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- def test_device_class_filter_unknown(self):
- self.store_spans(
- [
- self.create_span({"sentry_tags": {"device.class": ""}}, start_ts=self.ten_mins_ago),
- ]
- )
- response = self.do_request(
- {
- "field": ["device.class", "count()"],
- "query": "device.class:Unknown",
- "orderby": "count()",
- "project": self.project.id,
- "dataset": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- 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,
- ),
- ]
- )
- response = self.do_request(
- {
- "field": ["span.op", "span.status_code"],
- "query": "span.module:http span.status_code:200",
- "project": self.project.id,
- "dataset": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- 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,
- ),
- ]
- )
- 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": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- def test_id_filtering(self):
- span = self.create_span({"description": "foo"}, start_ts=self.ten_mins_ago)
- self.store_span(span)
- response = self.do_request(
- {
- "field": ["description", "count()"],
- "query": f"id:{span['span_id']}",
- "orderby": "description",
- "project": self.project.id,
- "dataset": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- response = self.do_request(
- {
- "field": ["description", "count()"],
- "query": f"transaction.id:{span['event_id']}",
- "orderby": "description",
- "project": self.project.id,
- "dataset": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- 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,
- ),
- ]
- )
- response = self.do_request(
- {
- "field": ["span.op", "count()"],
- "query": 'span.op:"ThIs Is a TraNSActiON"',
- "orderby": "count()",
- "project": self.project.id,
- "dataset": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- 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,
- ),
- ]
- )
- 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": "spansIndexed",
- }
- )
- 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"] == "spansIndexed"
- 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,
- ),
- ]
- )
- 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": "spansIndexed",
- }
- )
- assert response.status_code == 200, response.content
- assert response.data["data"] == [{"foo": "BaR", "count()": 1}]
|