@@ -128,9 +128,11 @@ public static function register(): void
128128 Context::storage ()->attach ($ span ->storeInContext ($ parent ));
129129 if (self ::isSqlCommenterEnabled () && $ sqlStatement !== self ::UNDEFINED ) {
130130 $ sqlStatement = self ::appendSqlComments ($ sqlStatement , true );
131- $ span ->setAttributes ([
132- TraceAttributes::DB_QUERY_TEXT => $ sqlStatement ,
133- ]);
131+ if (self ::isSqlCommenterAttributeEnabled ()) {
132+ $ span ->setAttributes ([
133+ TraceAttributes::DB_QUERY_TEXT => $ sqlStatement ,
134+ ]);
135+ }
134136
135137 return [
136138 0 => $ sqlStatement ,
@@ -167,9 +169,11 @@ public static function register(): void
167169 Context::storage ()->attach ($ span ->storeInContext ($ parent ));
168170 if (self ::isSqlCommenterEnabled () && $ sqlStatement !== self ::UNDEFINED ) {
169171 $ sqlStatement = self ::appendSqlComments ($ sqlStatement , true );
170- $ span ->setAttributes ([
171- TraceAttributes::DB_QUERY_TEXT => $ sqlStatement ,
172- ]);
172+ if (self ::isSqlCommenterAttributeEnabled ()) {
173+ $ span ->setAttributes ([
174+ TraceAttributes::DB_QUERY_TEXT => $ sqlStatement ,
175+ ]);
176+ }
173177
174178 return [
175179 0 => $ sqlStatement ,
@@ -206,9 +210,11 @@ public static function register(): void
206210 Context::storage ()->attach ($ span ->storeInContext ($ parent ));
207211 if (self ::isSqlCommenterEnabled () && $ sqlStatement !== self ::UNDEFINED ) {
208212 $ sqlStatement = self ::appendSqlComments ($ sqlStatement , false );
209- $ span ->setAttributes ([
210- TraceAttributes::DB_QUERY_TEXT => $ sqlStatement ,
211- ]);
213+ if (self ::isSqlCommenterAttributeEnabled ()) {
214+ $ span ->setAttributes ([
215+ TraceAttributes::DB_QUERY_TEXT => $ sqlStatement ,
216+ ]);
217+ }
212218
213219 return [
214220 0 => $ sqlStatement ,
@@ -388,6 +394,15 @@ private static function isSqlCommenterEnabled(): bool
388394 return filter_var (get_cfg_var ('otel.instrumentation.pdo.sql_commenter ' ), FILTER_VALIDATE_BOOLEAN , FILTER_NULL_ON_FAILURE ) ?? false ;
389395 }
390396
397+ private static function isSqlCommenterAttributeEnabled (): bool
398+ {
399+ if (class_exists ('OpenTelemetry\SDK\Common\Configuration\Configuration ' )) {
400+ return Configuration::getBoolean ('OTEL_PHP_INSTRUMENTATION_PDO_SQL_COMMENTER_ATTRIBUTE ' , false );
401+ }
402+
403+ return filter_var (get_cfg_var ('otel.instrumentation.pdo.sql_commenter_attribute ' ), FILTER_VALIDATE_BOOLEAN , FILTER_NULL_ON_FAILURE ) ?? false ;
404+ }
405+
391406 private static function appendSqlComments (string $ query , bool $ withTraceContext ): string
392407 {
393408 $ comments = [];
0 commit comments