1- import dataclasses
21import math
32from collections import defaultdict
43from collections .abc import Generator , Mapping , MutableMapping
2322from sentry .api .paginator import GenericOffsetPaginator
2423from sentry .api .utils import handle_query_errors
2524from sentry .models .organization import Organization
25+ from sentry .models .project import Project
2626from sentry .search .events .builder import QueryBuilder , SpansIndexedQueryBuilder
2727from sentry .search .events .constants import TIMEOUT_SPAN_ERROR_MESSAGE
2828from sentry .search .events .types import ParamsType , QueryBuilderConfig , SnubaParams , WhereType
2929from sentry .sentry_metrics .querying .samples_list import SpanKey , get_sample_list_executor_cls
30+ from sentry .services .hybrid_cloud .organization import RpcOrganization
3031from sentry .snuba .dataset import Dataset
3132from sentry .snuba .referrer import Referrer
3233from sentry .utils .iterators import chunked
@@ -98,8 +99,39 @@ def handle_span_query_errors() -> Generator[None, None, None]:
9899 raise ParseError (detail = TIMEOUT_SPAN_ERROR_MESSAGE )
99100
100101
102+ class OrganizationTracesEndpointBase (OrganizationEventsV2EndpointBase ):
103+ def get_snuba_dataclass (
104+ self , request : Request , organization : Organization , check_global_views : bool = True
105+ ) -> tuple [SnubaParams , dict [str , Any ]]:
106+ """The trace endpoint always wants to get all projects regardless of what's passed into the API.
107+ This is because a trace can span any number of projects in an organization. So disable the
108+ check_global_views condition."""
109+ return super ().get_snuba_dataclass (request , organization , check_global_views = False )
110+
111+ def get_projects ( # type: ignore[override]
112+ self ,
113+ request : Request ,
114+ organization : Organization | RpcOrganization ,
115+ project_ids : set [int ] | None = None ,
116+ project_slugs : set [str ] | None = None ,
117+ include_all_accessible : bool = True ,
118+ ) -> list [Project ]:
119+ """The trace endpoint always wants to get all projects regardless of what's passed into the API.
120+
121+ This is because a trace can span any number of projects in an organization. But we still want to
122+ use the get_projects function to check for any permissions. So we'll just pass project_ids=-1 everytime
123+ which is what would be sent if we wanted all projects"""
124+ return super ().get_projects (
125+ request ,
126+ organization ,
127+ project_ids = {- 1 },
128+ project_slugs = None ,
129+ include_all_accessible = True ,
130+ )
131+
132+
101133@region_silo_endpoint
102- class OrganizationTracesEndpoint (OrganizationEventsV2EndpointBase ):
134+ class OrganizationTracesEndpoint (OrganizationTracesEndpointBase ):
103135 publish_status = {
104136 "GET" : ApiPublishStatus .EXPERIMENTAL ,
105137 }
@@ -113,17 +145,6 @@ def get(self, request: Request, organization: Organization) -> Response:
113145
114146 try :
115147 snuba_params , params = self .get_snuba_dataclass (request , organization )
116- all_projects = self .get_projects (
117- request ,
118- organization ,
119- project_ids = {- 1 },
120- project_slugs = None ,
121- include_all_accessible = True ,
122- )
123- snuba_params = dataclasses .replace (snuba_params , projects = all_projects )
124- params ["projects" ] = snuba_params .projects
125- params ["projects_objects" ] = snuba_params .projects
126- params ["projects_id" ] = snuba_params .project_ids
127148 except NoProjects :
128149 return Response (status = 404 )
129150
0 commit comments