FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

perf(spanner): eliminate redundant tracing span in run_in_transaction by olavloite · Pull Request #18357 · googleapis/google-cloud-python · GitHub

Repository navigation

perf(spanner): eliminate redundant tracing span in run_in_transaction - #18357

Merged
olavloite merged 2 commits into
mainfrom
spanner-remove-redundant-tracing
Oct 8, 2026
Merged

olavloite merged 2 commits into
mainfrom
spanner-remove-redundant-tracing

Conversation

Copy link
Copy Markdown
Contributor

Eliminate the redundant inner 'CloudSpanner.Session.run_in_transaction' span and duplicate MetricsCapture context, leaving 'CloudSpanner.Database.run_in_transaction' as the single transaction lifecycle span (matching Java and Go client behavior).

  • Attach transaction retry, abort, and rollback events directly to the active span.
  • Guard span event creation, retry delay computation, and exception stringification behind span.is_recording().
  • Refactor the run_in_transaction retry loop by extracting _create_transaction_for_attempt and _handle_aborted helpers.

olavloite requested a review from a team as a code owner September 13, 2026 07:00

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request refactors transaction execution and tracing in Google Cloud Spanner sessions (both sync and async). It extracts transaction creation and abort handling into helper methods (_create_transaction_for_attempt and _handle_aborted), removes the CloudSpanner.Session.run_in_transaction span in favor of using the current span, and updates add_span_event to internally check if the span is recording. The reviewer points out that since add_span_event now internally guards against None or non-recording spans, the explicit if span and span.is_recording(): checks at several call sites in session.py are redundant and should be removed to simplify the code.

olavloite force-pushed the spanner-remove-redundant-tracing branch from 634e058 to cf47962 Compare September 13, 2026 09:57

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request refactors the run_in_transaction method in both the synchronous and asynchronous session implementations by extracting transaction creation and aborted error handling into helper methods (_create_transaction_for_attempt and _handle_aborted). This change simplifies the tracing logic by removing the CloudSpanner.Session.run_in_transaction span and attaching retry events directly to the current active span. Additionally, safe checks were added to OpenTelemetry tracing, and corresponding system and unit tests were updated. Feedback on the changes suggests addressing a potential IndexError in _handle_aborted when accessing exception.errors[0] directly, as exception.errors can sometimes be empty.

olavloite force-pushed the spanner-remove-redundant-tracing branch from cf47962 to 3d6358f Compare September 13, 2026 10:15

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request refactors transaction retry and tracing logic in Google Cloud Spanner sessions. It introduces helper methods _create_transaction_for_attempt and _handle_aborted to simplify run_in_transaction in both synchronous and asynchronous session implementations. It also updates tracing to use get_current_span() instead of creating a new nested span, and updates the corresponding unit and system tests. Feedback on the changes highlights a missing import for get_current_span in _async/session.py which would cause a NameError at runtime.

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request refactors the run_in_transaction method in both synchronous and asynchronous Session classes by extracting transaction creation into _create_transaction_for_attempt and aborted error handling into _handle_aborted. It also removes the redundant CloudSpanner.Session.run_in_transaction span, updates helper functions to safely handle exceptions without an errors attribute, and updates the test suite accordingly. The review feedback suggests simplifying the ternary expressions used to extract the exception cause in session.py and _helpers.py by assigning the result of getattr to a local variable first to avoid redundant attribute lookups.

Eliminate the redundant inner 'CloudSpanner.Session.run_in_transaction' span and duplicate MetricsCapture context, leaving 'CloudSpanner.Database.run_in_transaction' as the single transaction lifecycle span (matching Java and Go client behavior).

- Attach transaction retry, abort, and rollback events directly to the active span.
- Guard span event creation, retry delay computation, and exception stringification behind span.is_recording().
- Refactor the run_in_transaction retry loop by extracting _create_transaction_for_attempt and _handle_aborted helpers.
olavloite force-pushed the spanner-remove-redundant-tracing branch from 3d6358f to dc23e97 Compare September 13, 2026 11:56

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Code Review

This pull request refactors transaction execution and tracing in Google Cloud Spanner. It extracts transaction creation and aborted error handling into helper methods (_create_transaction_for_attempt and _handle_aborted) in both synchronous and asynchronous session implementations. It also simplifies the OpenTelemetry tracing hierarchy by removing the CloudSpanner.Session.run_in_transaction span and instead attaching events directly to the active parent span. Additionally, it updates and adds unit and system tests to verify the new tracing behavior, and makes minor robustness improvements to generate.py and exception attribute lookups. There are no review comments, so I have no feedback to provide.

olavloite added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 13, 2026
yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 13, 2026
olavloite merged commit 181e26a into main Oct 8, 2026
48 checks passed
olavloite deleted the spanner-remove-redundant-tracing branch October 8, 2026 07:02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL