@@ -251,11 +251,9 @@ def exists(self):
251
251
span ,
252
252
),
253
253
)
254
- if span :
255
- span .set_attribute ("session_found" , True )
254
+ span .set_attribute ("session_found" , True )
256
255
except NotFound :
257
- if span :
258
- span .set_attribute ("session_found" , False )
256
+ span .set_attribute ("session_found" , False )
259
257
return False
260
258
261
259
return True
@@ -317,18 +315,21 @@ def ping(self):
317
315
"""
318
316
if self ._session_id is None :
319
317
raise ValueError ("Session ID not set by back-end" )
318
+
320
319
database = self ._database
321
320
api = database .spanner_api
322
- request = ExecuteSqlRequest (session = self .name , sql = "SELECT 1" )
323
- api .execute_sql (
324
- request = request ,
325
- metadata = database .metadata_with_request_id (
326
- database ._next_nth_request ,
327
- 1 ,
328
- _metadata_with_prefix (database .name ),
329
- ),
330
- )
331
- self ._last_use_time = datetime .now ()
321
+
322
+ with trace_call ("CloudSpanner.Session.ping" , self ) as span :
323
+ request = ExecuteSqlRequest (session = self .name , sql = "SELECT 1" )
324
+ api .execute_sql (
325
+ request = request ,
326
+ metadata = database .metadata_with_request_id (
327
+ database ._next_nth_request ,
328
+ 1 ,
329
+ _metadata_with_prefix (database .name ),
330
+ span ,
331
+ ),
332
+ )
332
333
333
334
def snapshot (self , ** kw ):
334
335
"""Create a snapshot to perform a set of reads with shared staleness.
@@ -566,20 +567,18 @@ def run_in_transaction(self, func, *args, **kw):
566
567
567
568
except Aborted as exc :
568
569
previous_transaction_id = txn ._transaction_id
569
- if span :
570
- delay_seconds = _get_retry_delay (
571
- exc .errors [0 ],
572
- attempts ,
573
- default_retry_delay = default_retry_delay ,
574
- )
575
- attributes = dict (delay_seconds = delay_seconds , cause = str (exc ))
576
- attributes .update (span_attributes )
577
- add_span_event (
578
- span ,
579
- "Transaction was aborted in user operation, retrying" ,
580
- attributes ,
581
- )
582
-
570
+ delay_seconds = _get_retry_delay (
571
+ exc .errors [0 ],
572
+ attempts ,
573
+ default_retry_delay = default_retry_delay ,
574
+ )
575
+ attributes = dict (delay_seconds = delay_seconds , cause = str (exc ))
576
+ attributes .update (span_attributes )
577
+ add_span_event (
578
+ span ,
579
+ "Transaction was aborted in user operation, retrying" ,
580
+ attributes ,
581
+ )
583
582
_delay_until_retry (
584
583
exc , deadline , attempts , default_retry_delay = default_retry_delay
585
584
)
@@ -611,20 +610,18 @@ def run_in_transaction(self, func, *args, **kw):
611
610
612
611
except Aborted as exc :
613
612
previous_transaction_id = txn ._transaction_id
614
- if span :
615
- delay_seconds = _get_retry_delay (
616
- exc .errors [0 ],
617
- attempts ,
618
- default_retry_delay = default_retry_delay ,
619
- )
620
- attributes = dict (delay_seconds = delay_seconds )
621
- attributes .update (span_attributes )
622
- add_span_event (
623
- span ,
624
- "Transaction was aborted during commit, retrying" ,
625
- attributes ,
626
- )
627
-
613
+ delay_seconds = _get_retry_delay (
614
+ exc .errors [0 ],
615
+ attempts ,
616
+ default_retry_delay = default_retry_delay ,
617
+ )
618
+ attributes = dict (delay_seconds = delay_seconds )
619
+ attributes .update (span_attributes )
620
+ add_span_event (
621
+ span ,
622
+ "Transaction was aborted during commit, retrying" ,
623
+ attributes ,
624
+ )
628
625
_delay_until_retry (
629
626
exc , deadline , attempts , default_retry_delay = default_retry_delay
630
627
)
0 commit comments