-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(events): Add logging to debug queries #103766
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 |
|---|---|---|
|
|
@@ -108,6 +108,18 @@ def check_timeseries_has_data(timeseries: SnubaData, y_axes: list[str]): | |
| return False | ||
|
|
||
|
|
||
| def log_rpc_request(message: str, rpc_request): | ||
| rpc_debug_json = json.loads(MessageToJson(rpc_request)) | ||
| logger.info( | ||
| message, | ||
| extra={ | ||
| "rpc_query": rpc_debug_json, | ||
| "referrer": rpc_request.meta.referrer, | ||
| "trace_item_type": rpc_request.meta.trace_item_type, | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| class RPCBase: | ||
| """Utility Methods""" | ||
|
|
||
|
|
@@ -322,6 +334,8 @@ def _run_table_query( | |
| """Run the query""" | ||
| table_request = cls.get_table_rpc_request(query) | ||
| rpc_request = table_request.rpc_request | ||
| if debug: | ||
| log_rpc_request("Running a table query with debug on", rpc_request) | ||
| try: | ||
| rpc_response = snuba_rpc.table_rpc([rpc_request])[0] | ||
| except Exception as e: | ||
|
|
@@ -531,6 +545,8 @@ def update_timestamps( | |
| def _run_timeseries_rpc( | ||
| self, debug: bool, rpc_request: TimeSeriesRequest | ||
| ) -> TimeSeriesResponse: | ||
| if debug: | ||
| log_rpc_request("Running a timeseries query with debug on", rpc_request) | ||
| try: | ||
| return snuba_rpc.timeseries_rpc([rpc_request])[0] | ||
| except Exception as e: | ||
|
|
@@ -793,10 +809,19 @@ def run_top_events_timeseries_query( | |
| requests.append(other_request) | ||
|
|
||
| """Run the query""" | ||
| timeseries_rpc_response = snuba_rpc.timeseries_rpc(requests) | ||
| rpc_response = timeseries_rpc_response[0] | ||
| if len(timeseries_rpc_response) > 1: | ||
| other_response = timeseries_rpc_response[1] | ||
| if params.debug: | ||
| for rpc_request in requests: | ||
| log_rpc_request("Running a top events query with debug on", rpc_request) | ||
| try: | ||
| timeseries_rpc_response = snuba_rpc.timeseries_rpc(requests) | ||
| rpc_response = timeseries_rpc_response[0] | ||
| if len(timeseries_rpc_response) > 1: | ||
| other_response = timeseries_rpc_response[1] | ||
| except Exception as e: | ||
| # add the rpc to the error so we can include it in the response | ||
| if params.debug: | ||
| setattr(e, "debug", MessageToJson(rpc_request)) | ||
|
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: Wrong request attached to exception in error handlerThe exception handler references |
||
| raise | ||
|
Comment on lines
+820
to
+824
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: The 🔍 Detailed AnalysisThe 💡 Suggested FixRename the loop variable 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
|
|
||
| """Process the results""" | ||
| map_result_key_to_timeseries = defaultdict(list) | ||
|
|
||
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: Variable shadowing causes wrong request in debug metadata
The logging loop reuses the variable name
rpc_request, shadowing the first request that was assigned on line 786. This causesset_debug_metaon line 832 to receive the wrong request (the last one from the loop instead of the first one), mismatching it withrpc_responsewhich is always the first response.