Skip to content

Commit

Permalink
Move attempts into try block
Browse files Browse the repository at this point in the history
  • Loading branch information
odeke-em committed Dec 10, 2024
1 parent 7ed482e commit a194c3f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions google/cloud/spanner_v1/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,17 @@ def run_in_transaction(self, func, *args, **kw):
else:
txn = self._transaction

attempts += 1
span_attributes = {"attempt": attempts}
txn_id = getattr(txn, "_transaction_id", "") or ""
if txn_id:
span_attributes["transaction.id"] = txn_id
span_attributes = dict()

try:
attempts += 1
span_attributes["attempt"] = attempts
txn_id = getattr(txn, "_transaction_id", "") or ""
if txn_id:
span_attributes["transaction.id"] = txn_id

return_value = func(txn, *args, **kw)

except Aborted as exc:
del self._transaction
if span:
Expand Down

0 comments on commit a194c3f

Please sign in to comment.