@@ -492,50 +492,53 @@ def traced_execution(
492492        with  self ._db_api_integration ._tracer .start_as_current_span (
493493            name , kind = SpanKind .CLIENT 
494494        ) as  span :
495-             if  args  and  self ._commenter_enabled :
496-                 try :
497-                     args_list  =  list (args )
498- 
499-                     # lazy capture of mysql-connector client version using cursor 
500-                     if  (
501-                         self ._db_api_integration .database_system  ==  "mysql" 
502-                         and  self ._db_api_integration .connect_module .__name__ 
503-                         ==  "mysql.connector" 
504-                         and  not  self ._db_api_integration .commenter_data [
505-                             "mysql_client_version" 
506-                         ]
507-                     ):
508-                         self ._db_api_integration .commenter_data [
509-                             "mysql_client_version" 
510-                         ] =  cursor ._cnx ._cmysql .get_client_info ()
511- 
512-                     commenter_data  =  dict (
513-                         self ._db_api_integration .commenter_data 
514-                     )
515-                     if  self ._commenter_options .get (
516-                         "opentelemetry_values" , True 
517-                     ):
518-                         commenter_data .update (** _get_opentelemetry_values ())
519- 
520-                     # Filter down to just the requested attributes. 
521-                     commenter_data  =  {
522-                         k : v 
523-                         for  k , v  in  commenter_data .items ()
524-                         if  self ._commenter_options .get (k , True )
525-                     }
526-                     statement  =  _add_sql_comment (
527-                         args_list [0 ], ** commenter_data 
528-                     )
529- 
530-                     args_list [0 ] =  statement 
531-                     args  =  tuple (args_list )
532- 
533-                 except  Exception  as  exc :  # pylint: disable=broad-except 
534-                     _logger .exception (
535-                         "Exception while generating sql comment: %s" , exc 
536-                     )
537- 
538-             self ._populate_span (span , cursor , * args )
495+             if  span .is_recording ():
496+                 if  args  and  self ._commenter_enabled :
497+                     try :
498+                         args_list  =  list (args )
499+ 
500+                         # lazy capture of mysql-connector client version using cursor 
501+                         if  (
502+                             self ._db_api_integration .database_system  ==  "mysql" 
503+                             and  self ._db_api_integration .connect_module .__name__ 
504+                             ==  "mysql.connector" 
505+                             and  not  self ._db_api_integration .commenter_data [
506+                                 "mysql_client_version" 
507+                             ]
508+                         ):
509+                             self ._db_api_integration .commenter_data [
510+                                 "mysql_client_version" 
511+                             ] =  cursor ._cnx ._cmysql .get_client_info ()
512+ 
513+                         commenter_data  =  dict (
514+                             self ._db_api_integration .commenter_data 
515+                         )
516+                         if  self ._commenter_options .get (
517+                             "opentelemetry_values" , True 
518+                         ):
519+                             commenter_data .update (
520+                                 ** _get_opentelemetry_values ()
521+                             )
522+ 
523+                         # Filter down to just the requested attributes. 
524+                         commenter_data  =  {
525+                             k : v 
526+                             for  k , v  in  commenter_data .items ()
527+                             if  self ._commenter_options .get (k , True )
528+                         }
529+                         statement  =  _add_sql_comment (
530+                             args_list [0 ], ** commenter_data 
531+                         )
532+ 
533+                         args_list [0 ] =  statement 
534+                         args  =  tuple (args_list )
535+ 
536+                     except  Exception  as  exc :  # pylint: disable=broad-except 
537+                         _logger .exception (
538+                             "Exception while generating sql comment: %s" , exc 
539+                         )
540+ 
541+                 self ._populate_span (span , cursor , * args )
539542
540543            return  query_method (* args , ** kwargs )
541544
0 commit comments