@@ -492,49 +492,54 @@ def traced_execution(
492
492
with self ._db_api_integration ._tracer .start_as_current_span (
493
493
name , kind = SpanKind .CLIENT
494
494
) as span :
495
- self ._populate_span (span , cursor , * args )
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 (** _get_opentelemetry_values ())
520
-
521
- # Filter down to just the requested attributes.
522
- commenter_data = {
523
- k : v
524
- for k , v in commenter_data .items ()
525
- if self ._commenter_options .get (k , True )
526
- }
527
- statement = _add_sql_comment (
528
- args_list [0 ], ** commenter_data
529
- )
530
-
531
- args_list [0 ] = statement
532
- args = tuple (args_list )
533
-
534
- except Exception as exc : # pylint: disable=broad-except
535
- _logger .exception (
536
- "Exception while generating sql comment: %s" , exc
537
- )
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 )
542
+
538
543
return query_method (* args , ** kwargs )
539
544
540
545
0 commit comments