Skip to content

Commit

Permalink
Check if span is not None before annotations in beforeNextRetry
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Nov 15, 2024
1 parent b5067da commit 47d6e17
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions google/cloud/spanner_v1/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ def begin(self):
)

def beforeNextRetry(nthRetry, delayInSeconds):
span.add_event(
"Transaction Begin Attempt Failed. Retrying",
{"attempt": nthRetry, "sleep_seconds": delayInSeconds},
)
if span:
span.add_event(
"Transaction Begin Attempt Failed. Retrying",
{"attempt": nthRetry, "sleep_seconds": delayInSeconds},
)

response = _retry(
method,
Expand Down Expand Up @@ -246,6 +247,7 @@ def commit(
if not_began:
raise ValueError("Transaction is not begun")

database = self._session._database
trace_attributes = {"num_mutations": len(self._mutations)}
observability_options = getattr(database, "observability_options", None)
with trace_call(
Expand All @@ -260,7 +262,6 @@ def commit(
if span:
span.add_event("Starting Commit")

database = self._session._database
api = database.spanner_api
metadata = _metadata_with_prefix(database.name)
if database._route_to_leader_enabled:
Expand Down Expand Up @@ -294,17 +295,20 @@ def commit(
)

def beforeNextRetry(nthRetry, delayInSeconds):
span.add_event(
"Transaction Commit Attempt Failed. Retrying",
{"attempt": nthRetry, "sleep_seconds": delayInSeconds},
)
if span:
span.add_event(
"Transaction Commit Attempt Failed. Retrying",
{"attempt": nthRetry, "sleep_seconds": delayInSeconds},
)

response = _retry(
method,
allowed_exceptions={InternalServerError: _check_rst_stream_error},
beforeNextRetry=beforeNextRetry,
)
span.add_event("Commit Done")

if span:
span.add_event("Commit Done")
self.committed = response.commit_timestamp
if return_commit_stats:
self.commit_stats = response.commit_stats
Expand Down

0 comments on commit 47d6e17

Please sign in to comment.