Skip to content

fix(trace-explorer): Query trace meta across all projects #69062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/sentry/api/endpoints/organization_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rest_framework.response import Response
from snuba_sdk import Column, Condition, Op

from sentry import options
from sentry import features, options
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
Expand Down Expand Up @@ -56,6 +56,11 @@ class OrganizationTracesEndpoint(OrganizationEventsV2EndpointBase):
owner = ApiOwner.PERFORMANCE

def get(self, request: Request, organization: Organization) -> Response:
if not features.has(
"organizations:performance-trace-explorer", organization, actor=request.user
):
return Response(status=404)

try:
snuba_params, params = self.get_snuba_dataclass(request, organization)
except NoProjects:
Expand Down Expand Up @@ -131,6 +136,18 @@ def data_fn(offset: int, limit: int):
snuba_params.start = min_timestamp - buffer
snuba_params.end = max_timestamp + buffer

all_projects = self.get_projects(
request,
organization,
project_ids={-1},
project_slugs=None,
include_all_accessible=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you technically don't need to set this to true since pasisng in -1 will set it

if ALL_ACCESS_PROJECT_ID in ids:

)
snuba_params.projects = all_projects
params["projects"] = snuba_params.projects
params["projects_objects"] = snuba_params.projects
params["projects_id"] = snuba_params.project_ids

trace_condition = f"trace:[{', '.join(spans_by_trace.keys())}]"

with handle_query_errors():
Expand Down
67 changes: 53 additions & 14 deletions tests/sentry/api/endpoints/test_organization_traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ def setUp(self):
super().setUp()
self.login_as(user=self.user)

def do_request(self, query, **kwargs):
return self.client.get(
reverse(self.view, kwargs={"organization_slug": self.organization.slug}),
query,
format="json",
**kwargs,
)
def do_request(self, query, features=None, **kwargs):
if features is None:
features = ["organizations:performance-trace-explorer"]
with self.feature(features):
return self.client.get(
reverse(self.view, kwargs={"organization_slug": self.organization.slug}),
query,
format="json",
**kwargs,
)

def test_no_feature(self):
query = {
"field": ["id"],
"project": [self.project.id],
}

response = self.do_request(query, features=[])
assert response.status_code == 404, response.data

def test_no_project(self):
query = {
Expand Down Expand Up @@ -131,14 +143,17 @@ def test_no_traces(self):
}

def test_matching_tag(self):
project_1 = self.create_project()
project_2 = self.create_project()

# Hack: ensure that no span ids with leading 0s are generated for the test
span_ids = ["1" + uuid4().hex[:15] for _ in range(7)]
timestamps = []

trace_id_1 = uuid4().hex
timestamps.append(before_now(days=0, minutes=10).replace(microsecond=0))
self.store_segment(
self.project.id,
project_1.id,
trace_id_1,
uuid4().hex,
span_id=span_ids[0],
Expand All @@ -150,7 +165,7 @@ def test_matching_tag(self):
for idx, i in enumerate(range(1, 4)):
timestamps.append(before_now(days=0, minutes=9, seconds=45 - i).replace(microsecond=0))
self.store_segment(
self.project.id,
project_2.id,
trace_id_1,
uuid4().hex,
span_id=span_ids[i],
Expand All @@ -165,7 +180,7 @@ def test_matching_tag(self):
trace_id_2 = uuid4().hex
timestamps.append(before_now(days=0, minutes=20).replace(microsecond=0))
self.store_segment(
self.project.id,
project_1.id,
trace_id_2,
uuid4().hex,
span_id=span_ids[4],
Expand All @@ -177,7 +192,7 @@ def test_matching_tag(self):
for i in range(5, 7):
timestamps.append(before_now(days=0, minutes=19, seconds=55 - i).replace(microsecond=0))
self.store_segment(
self.project.id,
project_2.id,
trace_id_2,
uuid4().hex,
span_id=span_ids[i],
Expand All @@ -190,7 +205,7 @@ def test_matching_tag(self):
)

query = {
"project": [self.project.id],
"project": [project_2.id],
"field": ["id", "parent_span"],
"query": "foo:bar",
"maxSpansPerTrace": 2,
Expand Down Expand Up @@ -230,8 +245,20 @@ def test_matching_tag(self):
"end": int(timestamps[0].timestamp() * 1000) + 60_100,
"breakdowns": [
{
"project": self.project.slug,
"project": project_1.slug,
"start": int(timestamps[0].timestamp() * 1000),
"end": int(timestamps[1].timestamp() * 1000),
"kind": "project",
},
{
"project": project_2.slug,
"start": int(timestamps[1].timestamp() * 1000),
"end": int(timestamps[3].timestamp() * 1000) + 30_000,
"kind": "project",
},
{
"project": project_1.slug,
"start": int(timestamps[3].timestamp() * 1000) + 30_000,
"end": int(timestamps[0].timestamp() * 1000) + 60_100,
"kind": "project",
},
Expand All @@ -254,8 +281,20 @@ def test_matching_tag(self):
"end": int(timestamps[4].timestamp() * 1000) + 90_123,
"breakdowns": [
{
"project": self.project.slug,
"project": project_1.slug,
"start": int(timestamps[4].timestamp() * 1000),
"end": int(timestamps[5].timestamp() * 1000),
"kind": "project",
},
{
"project": project_2.slug,
"start": int(timestamps[5].timestamp() * 1000),
"end": int(timestamps[6].timestamp() * 1000) + 20_000,
"kind": "project",
},
{
"project": project_1.slug,
"start": int(timestamps[6].timestamp() * 1000) + 20_000,
"end": int(timestamps[4].timestamp() * 1000) + 90_123,
"kind": "project",
},
Expand Down
Loading