@@ -500,47 +500,48 @@ async def inner(*args: P.args, **kwargs: P.kwargs):
500
500
while True :
501
501
try :
502
502
async with pool .connection () as conn :
503
- assert isinstance (conn , LatchAsyncConnection )
503
+ with tracer .start_as_current_span ("connection acquired" ):
504
+ assert isinstance (conn , LatchAsyncConnection )
504
505
505
- backoff = CABackoff (
506
- db_config .tx_retries .delay_quant ,
507
- db_config .tx_retries .max_wait_time ,
508
- )
509
- while True :
510
- try :
511
- res = await f (conn , * args , ** kwargs )
512
- # Commit here so we can retry if it fails
513
- # Otherwise the context manager will commit and fail
514
- await conn .commit ()
515
- return res
516
- except (
517
- # Class 40 - Transaction Rollback
518
- SerializationFailure ,
519
- DeadlockDetected ,
520
- ) as e :
521
- # Retry with the same connection
522
- delay = backoff .retry ()
523
-
524
- if delay is None :
525
- raise e
526
-
527
- s .add_event (
528
- "transaction retry" ,
529
- {
530
- "db.retry.count" : retries ,
531
- "db.retry.accum_retry_time" : str (
532
- backoff .acc_wait_time
506
+ backoff = CABackoff (
507
+ db_config .tx_retries .delay_quant ,
508
+ db_config .tx_retries .max_wait_time ,
509
+ )
510
+ while True :
511
+ try :
512
+ res = await f (conn , * args , ** kwargs )
513
+ # Commit here so we can retry if it fails
514
+ # Otherwise the context manager will commit and fail
515
+ await conn .commit ()
516
+ return res
517
+ except (
518
+ # Class 40 - Transaction Rollback
519
+ SerializationFailure ,
520
+ DeadlockDetected ,
521
+ ) as e :
522
+ # Retry with the same connection
523
+ delay = backoff .retry ()
524
+
525
+ if delay is None :
526
+ raise e
527
+
528
+ s .add_event (
529
+ "transaction retry" ,
530
+ {
531
+ "db.retry.count" : retries ,
532
+ "db.retry.accum_retry_time" : str (
533
+ backoff .acc_wait_time
534
+ ),
535
+ "db.retry.delay" : str (delay ),
536
+ }
537
+ | dict_to_attrs (
538
+ pg_error_to_dict (e , short = True ),
539
+ "db.retry.reason" ,
533
540
),
534
- "db.retry.delay" : str (delay ),
535
- }
536
- | dict_to_attrs (
537
- pg_error_to_dict (e , short = True ),
538
- "db.retry.reason" ,
539
- ),
540
- )
541
+ )
541
542
542
- await conn .rollback ()
543
- await asyncio .sleep (delay )
543
+ await conn .rollback ()
544
+ await asyncio .sleep (delay )
544
545
except (SerializationFailure , DeadlockDetected ):
545
546
# todo(maximsmol): should be unnecessary if the list below is precise enough
546
547
raise
0 commit comments