@@ -666,20 +666,29 @@ def _set_db_data(span, cursor_or_db):
666
666
vendor = db .vendor
667
667
span .set_data (SPANDATA .DB_SYSTEM , vendor )
668
668
669
- if (
669
+ # Some custom backends override `__getattr__`, making it look like `cursor_or_db`
670
+ # actually has a `connection` and the `connection` has a `get_dsn_parameters`
671
+ # attribute, only to throw an error once you actually want to call it.
672
+ # Hence the `inspect` check whether `get_dsn_parameters` is an actual callable
673
+ # function.
674
+ is_psycopg2 = (
670
675
hasattr (cursor_or_db , "connection" )
671
676
and hasattr (cursor_or_db .connection , "get_dsn_parameters" )
672
677
and inspect .isfunction (cursor_or_db .connection .get_dsn_parameters )
673
- ):
674
- # Some custom backends override `__getattr__`, making it look like `cursor_or_db`
675
- # actually has a `connection` and the `connection` has a `get_dsn_parameters`
676
- # attribute, only to throw an error once you actually want to call it.
677
- # Hence the `inspect` check whether `get_dsn_parameters` is an actual callable
678
- # function.
678
+ )
679
+ if is_psycopg2 :
679
680
connection_params = cursor_or_db .connection .get_dsn_parameters ()
680
-
681
681
else :
682
- connection_params = db .get_connection_params ()
682
+ is_psycopg3 = (
683
+ hasattr (cursor_or_db , "connection" )
684
+ and hasattr (cursor_or_db .connection , "info" )
685
+ and hasattr (cursor_or_db .connection .info , "get_parameters" )
686
+ and inspect .isfunction (cursor_or_db .connection .info .get_parameters )
687
+ )
688
+ if is_psycopg3 :
689
+ connection_params = cursor_or_db .connection .info .get_parameters ()
690
+ else :
691
+ connection_params = db .get_connection_params ()
683
692
684
693
db_name = connection_params .get ("dbname" ) or connection_params .get ("database" )
685
694
if db_name is not None :
0 commit comments