-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(trace-view): Update trace-view to use snql #29709
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,9 +28,10 @@ | |
| from sentry.api.serializers.models.event import get_tags_with_meta | ||
| from sentry.eventstore.models import Event | ||
| from sentry.models import Organization | ||
| from sentry.search.events.builder import QueryBuilder | ||
| from sentry.snuba import discover | ||
| from sentry.utils.numbers import format_grouped_length | ||
| from sentry.utils.snuba import Dataset, SnubaQueryParams, bulk_raw_query | ||
| from sentry.utils.snuba import Dataset, SnubaQueryParams, bulk_raw_query, bulk_snql_query | ||
| from sentry.utils.validators import INVALID_ID_DETAILS, is_event_id | ||
|
|
||
| logger: logging.Logger = logging.getLogger(__name__) | ||
|
|
@@ -204,8 +205,61 @@ def child_sort_key(item: TraceEvent) -> List[int]: | |
|
|
||
|
|
||
| def query_trace_data( | ||
| trace_id: str, params: Mapping[str, str] | ||
| trace_id: str, params: Mapping[str, str], use_snql: bool = False | ||
| ) -> Tuple[Sequence[SnubaTransaction], Sequence[SnubaError]]: | ||
| if use_snql: | ||
| transaction_query = QueryBuilder( | ||
| Dataset.Transactions, | ||
| params, | ||
| query=f"trace:{trace_id}", | ||
| selected_columns=[ | ||
| "id", | ||
| "transaction.status", | ||
| "transaction.op", | ||
| "transaction.duration", | ||
| "transaction", | ||
| "timestamp", | ||
| "project", | ||
| "project.id", | ||
wmak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "trace.span", | ||
| "trace.parent_span", | ||
| 'to_other(trace.parent_span, "", 0, 1) AS root', | ||
| ], | ||
| # We want to guarantee at least getting the root, and hopefully events near it with timestamp | ||
| # id is just for consistent results | ||
| orderby=["-root", "timestamp", "id"], | ||
| ) | ||
| error_query = QueryBuilder( | ||
| Dataset.Events, | ||
| params, | ||
| query=f"trace:{trace_id}", | ||
| selected_columns=[ | ||
| "id", | ||
| "project", | ||
| "project.id", | ||
wmak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "timestamp", | ||
| "trace.span", | ||
| "transaction", | ||
| "issue", | ||
| "title", | ||
| "tags[level]", | ||
| ], | ||
| # Don't add timestamp to this orderby as snuba will have to split the time range up and make multiple queries | ||
| orderby=["id"], | ||
| auto_fields=False, | ||
| ) | ||
| results = bulk_snql_query( | ||
| [transaction_query.get_snql_query(), error_query.get_snql_query()], | ||
| referrer="api.trace-view.get-events", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to ignore this but using the same referrer for each of the bulk queries has been a pet peeve of mine since the two queries are different but we have no way of distinguishing between the two in the transaction.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, but the current bulk APIs don't support a way to provide >1 referrer yet. I have this mentally backlogged but let me create something in Jira |
||
| ) | ||
| transformed_results = [ | ||
| discover.transform_results(result, query.function_alias_map, {}, None)["data"] | ||
| for result, query in zip(results, [transaction_query, error_query]) | ||
| ] | ||
| return cast(Sequence[SnubaTransaction], transformed_results[0]), cast( | ||
| Sequence[SnubaError], transformed_results[1] | ||
| ) | ||
|
|
||
| transaction_query = discover.prepare_discover_query( | ||
| selected_columns=[ | ||
| "id", | ||
|
|
@@ -280,6 +334,11 @@ def has_feature(self, organization: Organization, request: HttpRequest) -> bool: | |
| features.has("organizations:performance-view", organization, actor=request.user) | ||
| ) | ||
|
|
||
| def has_snql_feature(self, organization: Organization, request: HttpRequest) -> bool: | ||
| return bool( | ||
| features.has("organizations:performance-use-snql", organization, actor=request.user) | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def serialize_error(event: SnubaError) -> TraceError: | ||
| return { | ||
|
|
@@ -356,7 +415,9 @@ def get(self, request: HttpRequest, organization: Organization, trace_id: str) - | |
| return Response({"detail": INVALID_ID_DETAILS.format("Event ID")}, status=400) | ||
|
|
||
| with self.handle_query_errors(): | ||
| transactions, errors = query_trace_data(trace_id, params) | ||
| transactions, errors = query_trace_data( | ||
| trace_id, params, self.has_snql_feature(organization, request) | ||
| ) | ||
| if len(transactions) == 0: | ||
| return Response(status=404) | ||
| self.record_analytics(transactions, trace_id, self.request.user.id, organization.id) | ||
|
|
@@ -707,6 +768,7 @@ def get(self, request: HttpRequest, organization: Organization, trace_id: str) - | |
| query=f"trace:{trace_id}", | ||
| limit=1, | ||
| referrer="api.trace-view.get-meta", | ||
| use_snql=self.has_snql_feature(organization, request), | ||
| ) | ||
| if len(result["data"]) == 0: | ||
| return Response(status=404) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,14 +114,15 @@ | |
| default_manager.add("organizations:native-stack-trace-v2", OrganizationFeature, True) | ||
| default_manager.add("organizations:onboarding", OrganizationFeature) | ||
| default_manager.add("organizations:org-subdomains", OrganizationFeature) | ||
| default_manager.add("organizations:performance-chart-interpolation", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-events-page", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-landing-widgets", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-mobile-vitals", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-ops-breakdown", OrganizationFeature) | ||
| default_manager.add("organizations:performance-suspect-spans-view", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-tag-explorer", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-tag-page", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-events-page", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-chart-interpolation", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-suspect-spans-view", OrganizationFeature, True) | ||
| default_manager.add("organizations:performance-use-snql", OrganizationFeature, True) | ||
|
Comment on lines
+117
to
+125
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorted these which is why there's additional diffs |
||
| default_manager.add("organizations:performance-view", OrganizationFeature) | ||
| default_manager.add("organizations:prompt-dashboards", OrganizationFeature) | ||
| default_manager.add("organizations:related-events", OrganizationFeature) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.