Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 11f62bc

Browse files
committed
refactor: pass CommitStats via extra kwarg
1 parent 507a4ec commit 11f62bc

4 files changed

Lines changed: 14 additions & 4 deletions

File tree

google/cloud/spanner_v1/database.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
657657
self._batch.commit(return_commit_stats=self._database.log_commit_stats)
658658
finally:
659659
if self._database.log_commit_stats:
660-
self._database.logger.info(self._batch.commit_stats)
660+
self._database.logger.info(
661+
"CommitStats: {}".format(self._batch.commit_stats),
662+
extra={"commit_stats": self._batch.commit_stats},
663+
)
661664
self._database._pool.put(self._session)
662665

663666

google/cloud/spanner_v1/session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,10 @@ def run_in_transaction(self, func, *args, **kw):
358358
raise
359359
else:
360360
if self._database.log_commit_stats:
361-
self._database.logger.info(txn.commit_stats)
361+
self._database.logger.info(
362+
"CommitStats: {}".format(txn.commit_stats),
363+
extra={"commit_stats": txn.commit_stats},
364+
)
362365
return return_value
363366

364367

tests/unit/test_database.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,9 @@ def test_context_mgr_w_commit_stats(self):
13741374
request=request, metadata=[("google-cloud-resource-prefix", database.name)],
13751375
)
13761376

1377-
database.logger.info.assert_called_once_with(commit_stats)
1377+
database.logger.info.assert_called_once_with(
1378+
"CommitStats: mutation_count: 4\n", extra={"commit_stats": commit_stats}
1379+
)
13781380

13791381
def test_context_mgr_failure(self):
13801382
from google.cloud.spanner_v1.batch import Batch

tests/unit/test_session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,9 @@ def unit_of_work(txn, *args, **kw):
13781378
gax_api.commit.assert_called_once_with(
13791379
request=request, metadata=[("google-cloud-resource-prefix", database.name)],
13801380
)
1381-
database.logger.info.assert_called_once_with(commit_stats)
1381+
database.logger.info.assert_called_once_with(
1382+
"CommitStats: mutation_count: 4\n", extra={"commit_stats": commit_stats}
1383+
)
13821384

13831385
def test_delay_helper_w_no_delay(self):
13841386
from google.cloud.spanner_v1.session import _delay_until_retry

0 commit comments

Comments
 (0)