Skip to content

Commit

Permalink
feat(eap): Use RPC to fetch tag values (#77510)
Browse files Browse the repository at this point in the history
This uses RPC calls to fetch tag values from eap spans.

depends on getsentry/snuba#6304

---------

Co-authored-by: William Mak <william@wmak.io>
  • Loading branch information
Zylphrex and wmak authored Sep 27, 2024
1 parent fe96e0e commit a8e4e05
Show file tree
Hide file tree
Showing 3 changed files with 385 additions and 72 deletions.
67 changes: 66 additions & 1 deletion src/sentry/api/endpoints/organization_spans_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from rest_framework.request import Request
from rest_framework.response import Response
from sentry_protos.snuba.v1alpha.endpoint_tags_list_pb2 import (
AttributeValuesRequest,
AttributeValuesResponse,
TraceItemAttributesRequest,
TraceItemAttributesResponse,
)
Expand All @@ -20,6 +22,7 @@
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases import NoProjects, OrganizationEventsV2EndpointBase
from sentry.api.event_search import translate_escape_sequences
from sentry.api.paginator import ChainPaginator
from sentry.api.serializers import serialize
from sentry.api.utils import handle_query_errors
Expand Down Expand Up @@ -195,6 +198,68 @@ def get(self, request: Request, organization, key: str) -> Response:

max_span_tag_values = options.get("performance.spans-tags-values.max")

serializer = OrganizationSpansFieldsEndpointSerializer(data=request.GET)
if not serializer.is_valid():
return Response(serializer.errors, status=400)
serialized = serializer.validated_data

if serialized["dataset"] == "spans" and features.has(
"organizations:visibility-explore-dataset", organization, actor=request.user
):
start_timestamp = Timestamp()
start_timestamp.FromDatetime(
snuba_params.start_date.replace(hour=0, minute=0, second=0, microsecond=0)
)

end_timestamp = Timestamp()
end_timestamp.FromDatetime(
snuba_params.end_date.replace(hour=0, minute=0, second=0, microsecond=0)
+ timedelta(days=1)
)

query = translate_escape_sequences(request.GET.get("query", ""))
rpc_request = AttributeValuesRequest(
meta=RequestMeta(
organization_id=organization.id,
cogs_category="performance",
referrer=Referrer.API_SPANS_TAG_VALUES_RPC.value,
project_ids=snuba_params.project_ids,
start_timestamp=start_timestamp,
end_timestamp=end_timestamp,
trace_item_name=TraceItemName.TRACE_ITEM_NAME_EAP_SPANS,
),
name=key,
value_substring_match=query,
limit=max_span_tag_values,
offset=0,
)
rpc_response = snuba.rpc(rpc_request, AttributeValuesResponse)

paginator = ChainPaginator(
[
[
TagValue(
key=key,
value=tag_value,
times_seen=None,
first_seen=None,
last_seen=None,
)
for tag_value in rpc_response.values
if tag_value
]
],
max_limit=max_span_tag_values,
)

return self.paginate(
request=request,
paginator=paginator,
on_results=lambda results: serialize(results, request.user),
default_per_page=max_span_tag_values,
max_per_page=max_span_tag_values,
)

executor = SpanFieldValuesAutocompletionExecutor(
snuba_params=snuba_params,
key=key,
Expand Down Expand Up @@ -339,7 +404,7 @@ def get_autocomplete_query_base(self) -> BaseQueryBuilder:

def get_autocomplete_results(self, query: BaseQueryBuilder) -> list[TagValue]:
with handle_query_errors():
results = query.process_results(query.run_query(Referrer.API_SPANS_TAG_KEYS.value))
results = query.process_results(query.run_query(Referrer.API_SPANS_TAG_VALUES.value))

return [
TagValue(
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/snuba/referrer.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ class Referrer(Enum):
API_TRACE_EXPLORER_TRACE_SPANS_LIST = "api.trace-explorer.trace-spans-list"
API_SPANS_TAG_KEYS = "api.spans.tags-keys"
API_SPANS_TAG_KEYS_RPC = "api.spans.tags-keys.rpc"
API_SPANS_TAG_VALUES = "api.spans.tags-values"
API_SPANS_TAG_VALUES_RPC = "api.spans.tags-values.rpc"
API_SPANS_TRACE_VIEW = "api.spans.trace-view"

# Performance Mobile UI Module
Expand Down
Loading

0 comments on commit a8e4e05

Please sign in to comment.