Skip to content

Commit 6f400f9

Browse files
committed
Add span events
1 parent 3dba0fa commit 6f400f9

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

google/cloud/spanner_v1/pool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def bind(self, database):
223223
if self._sessions.full():
224224
if span:
225225
span.add_event(
226-
"Session pool is already full", {"kind": "fixed_size_pool"}
226+
"Session pool is already full", span_event_attributes
227227
)
228228
return
229229

@@ -395,7 +395,6 @@ def get(self):
395395
)
396396
session = self._new_session()
397397
session.create()
398-
399398
return session
400399

401400
def put(self, session):

google/cloud/spanner_v1/session.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,16 @@ def exists(self):
171171
:rtype: bool
172172
:returns: True if the session exists on the back-end, else False.
173173
"""
174+
current_span = get_current_span()
174175
if self._session_id is None:
176+
current_span.add_event("Checking if Session failed due to unset session_id")
175177
return False
178+
179+
if current_span:
180+
current_span.add_event(
181+
"Checking if Session exists", {"session.id": self._session_id}
182+
)
183+
176184
api = self._database.spanner_api
177185
metadata = _metadata_with_prefix(self._database.name)
178186
if self._database._route_to_leader_enabled:
@@ -206,8 +214,17 @@ def delete(self):
206214
:raises ValueError: if :attr:`session_id` is not already set.
207215
:raises NotFound: if the session does not exist
208216
"""
217+
current_span = get_current_span()
209218
if self._session_id is None:
219+
if current_span:
220+
current_span.add_event(
221+
"Deleting Session failed due to unset session_id"
222+
)
210223
raise ValueError("Session ID not set by back-end")
224+
225+
if current_span:
226+
current_span.add_event("Deleting Session", {"session.id": self._session_id})
227+
211228
api = self._database.spanner_api
212229
metadata = _metadata_with_prefix(self._database.name)
213230
observability_options = getattr(self._database, "observability_options", None)

google/cloud/spanner_v1/transaction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ def commit(
261261
request_options = RequestOptions(request_options)
262262
if self.transaction_tag is not None:
263263
request_options.transaction_tag = self.transaction_tag
264+
264265
# Request tags are not supported for commit requests.
265266
request_options.request_tag = None
266267

@@ -308,6 +309,7 @@ def beforeNextRetry(nthRetry, delayInSeconds):
308309

309310
if span:
310311
span.add_event("Commit Done")
312+
311313
self.committed = response.commit_timestamp
312314
if return_commit_stats:
313315
self.commit_stats = response.commit_stats
@@ -449,7 +451,7 @@ def execute_update(
449451
response = self._execute_request(
450452
method,
451453
request,
452-
"CloudSpanner.execute_update",
454+
"CloudSpanner.ReadWriteTransaction",
453455
self._session,
454456
trace_attributes,
455457
observability_options=observability_options,
@@ -466,7 +468,7 @@ def execute_update(
466468
response = self._execute_request(
467469
method,
468470
request,
469-
"CloudSpanner.execute_update",
471+
"CloudSpanner.ReadWriteTransaction",
470472
self._session,
471473
trace_attributes,
472474
observability_options=observability_options,

0 commit comments

Comments
 (0)