-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(rpc): Add more query logging #104480
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import os | ||
| from concurrent.futures import ThreadPoolExecutor | ||
| from dataclasses import dataclass | ||
|
|
@@ -9,6 +10,7 @@ | |
| import sentry_sdk | ||
| import sentry_sdk.scope | ||
| import urllib3 | ||
| from google.protobuf.json_format import MessageToJson | ||
| from google.protobuf.message import Message as ProtobufMessage | ||
| from rest_framework.exceptions import NotFound | ||
| from sentry_protos.snuba.v1.endpoint_create_subscription_pb2 import ( | ||
|
|
@@ -44,8 +46,10 @@ | |
| from sentry_protos.snuba.v1.request_common_pb2 import RequestMeta | ||
| from urllib3.response import BaseHTTPResponse | ||
|
|
||
| from sentry.utils import json, metrics | ||
| from sentry.utils.snuba import SnubaError, _snuba_pool | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| RPCResponseType = TypeVar("RPCResponseType", bound=ProtobufMessage) | ||
|
|
||
| # Show the snuba query params and the corresponding sql or errors in the server logs | ||
|
|
@@ -109,10 +113,23 @@ def _make_rpc_requests( | |
| timeseries_requests = [] if timeseries_requests is None else timeseries_requests | ||
| requests = table_requests + timeseries_requests | ||
|
|
||
| endpoint_names = [ | ||
| "EndpointTraceItemTable" if isinstance(req, TraceItemTableRequest) else "EndpointTimeSeries" | ||
| for req in requests | ||
| ] | ||
| endpoint_names: list[str] = [] | ||
| for request in requests: | ||
| endpoint_name = ( | ||
| "EndpointTraceItemTable" | ||
| if isinstance(request, TraceItemTableRequest) | ||
| else "EndpointTimeSeries" | ||
| ) | ||
| endpoint_names.append(endpoint_name) | ||
| logger.info( | ||
| f"Running a {endpoint_name} RPC query", # noqa: LOG011 | ||
| extra={ | ||
| "rpc_query": json.loads(MessageToJson(request)), | ||
| "referrer": request.meta.referrer, | ||
| "organization_id": request.meta.organization_id, | ||
| "trace_item_type": request.meta.trace_item_type, | ||
| }, | ||
| ) | ||
|
|
||
| referrers = [req.meta.referrer for req in requests] | ||
| assert ( | ||
|
|
@@ -150,10 +167,37 @@ def _make_rpc_requests( | |
| table_response = TraceItemTableResponse() | ||
| table_response.ParseFromString(item.data) | ||
| table_results.append(table_response) | ||
|
|
||
| if len(table_response.column_values) > 0: | ||
| rpc_rows = len(table_response.column_values[0].results) | ||
| else: | ||
| rpc_rows = 0 | ||
| logger.info( | ||
| "Table RPC query response", | ||
| extra={ | ||
| "rpc_rows": rpc_rows, | ||
| "page_token": table_response.page_token, | ||
| "meta": table_response.meta, | ||
| }, | ||
| ) | ||
| metrics.distribution("snuba_rpc.table_response.length", rpc_rows) | ||
| elif isinstance(request, TimeSeriesRequest): | ||
| timeseries_response = TimeSeriesResponse() | ||
| timeseries_response.ParseFromString(item.data) | ||
| timeseries_results.append(timeseries_response) | ||
|
|
||
| if len(timeseries_response.result_timeseries) > 0: | ||
| rpc_rows = len(timeseries_response.result_timeseries[0].data_points) | ||
| else: | ||
| rpc_rows = 0 | ||
| logger.info( | ||
| "Table RPC query response", | ||
| extra={ | ||
| "rpc_rows": rpc_rows, | ||
| "meta": timeseries_response.meta, | ||
| }, | ||
| ) | ||
|
Contributor
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. Bug: Incorrect log message for timeseries responseThe log message for timeseries responses incorrectly states "Table RPC query response" when it should indicate a timeseries response. This appears to be a copy-paste error from the table response logging block above. This will make it difficult to distinguish between table and timeseries query responses in logs, hindering debugging and monitoring efforts. |
||
| metrics.distribution("snuba_rpc.timeseries_response.length", rpc_rows) | ||
| return MultiRpcResponse(table_results, timeseries_results) | ||
|
|
||
|
|
||
|
|
@@ -271,8 +315,6 @@ def _make_rpc_request( | |
| sentry_sdk.get_current_scope() if thread_current_scope is None else thread_current_scope | ||
| ) | ||
| if SNUBA_INFO: | ||
| from google.protobuf.json_format import MessageToJson | ||
|
|
||
| log_snuba_info(f"{referrer}.body:\n{MessageToJson(req)}") # type: ignore[arg-type] | ||
| with sentry_sdk.scope.use_isolation_scope(thread_isolation_scope): | ||
| with sentry_sdk.scope.use_scope(thread_current_scope): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Removed
log_rpc_request()function but left an orphaned call site inspans_rpc.py, causing anAttributeErroron timeout.Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The pull request removed the
log_rpc_request()function fromrpc_dataset_common.py, but a call site inspans_rpc.py(around line 323) was not removed. When a trace query times out during pagination, this orphaned call will attempt to executerpc_dataset_common.log_rpc_request(), leading to anAttributeError: module 'sentry.snuba.rpc_dataset_common' has no attribute 'log_rpc_request'. This unhandled exception will crash the request handler.💡 Suggested Fix
Remove the orphaned call to
rpc_dataset_common.log_rpc_request()inspans_rpc.py(around line 323) or migrate its logging logic to the newsnuba_rpc.py.🤖 Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID:
5900602