-
-
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
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, | ||
| }, | ||
| ) | ||
|
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: Protobuf messages logged without JSON serializationThe response logging passes raw protobuf message objects ( Additional Locations (1) |
||
| 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( | ||
| "Timeseries RPC query response", | ||
| extra={ | ||
| "rpc_rows": rpc_rows, | ||
| "meta": timeseries_response.meta, | ||
| }, | ||
| ) | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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): | ||
|
|
||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.