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 2d4cbca
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 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 @@ -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 2d4cbca

Please sign in to comment.