1414import com .azure .monitor .opentelemetry .autoconfigure .implementation .models .ContextTagKeys ;
1515import com .azure .monitor .opentelemetry .autoconfigure .implementation .models .TelemetryItem ;
1616import com .azure .monitor .opentelemetry .autoconfigure .implementation .semconv .ClientAttributes ;
17+ import com .azure .monitor .opentelemetry .autoconfigure .implementation .semconv .DbAttributes ;
1718import com .azure .monitor .opentelemetry .autoconfigure .implementation .semconv .incubating .EnduserIncubatingAttributes ;
1819import com .azure .monitor .opentelemetry .autoconfigure .implementation .semconv .ExceptionAttributes ;
1920import com .azure .monitor .opentelemetry .autoconfigure .implementation .semconv .HttpAttributes ;
@@ -61,12 +62,14 @@ public final class SpanDataMapper {
6162 // visible for testing
6263 public static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors" ;
6364
64- private static final Set <String > SQL_DB_SYSTEMS = new HashSet <>(asList (DbIncubatingAttributes .DbSystemValues .DB2 ,
65- DbIncubatingAttributes .DbSystemValues .DERBY , DbIncubatingAttributes .DbSystemValues .MARIADB ,
66- DbIncubatingAttributes .DbSystemValues .MSSQL , DbIncubatingAttributes .DbSystemValues .MYSQL ,
67- DbIncubatingAttributes .DbSystemValues .ORACLE , DbIncubatingAttributes .DbSystemValues .POSTGRESQL ,
68- DbIncubatingAttributes .DbSystemValues .SQLITE , DbIncubatingAttributes .DbSystemValues .OTHER_SQL ,
69- DbIncubatingAttributes .DbSystemValues .HSQLDB , DbIncubatingAttributes .DbSystemValues .H2 ));
65+ // the deprecated incubating constants for mariadb, mysql, postgresql had the same values as the stable ones
66+ private static final Set <String > SQL_DB_SYSTEMS
67+ = new HashSet <>(asList (DbAttributes .DbSystemNameValues .MARIADB , DbAttributes .DbSystemNameValues .MYSQL ,
68+ DbAttributes .DbSystemNameValues .POSTGRESQL , DbAttributes .DbSystemNameValues .MICROSOFT_SQL_SERVER ,
69+ DbIncubatingAttributes .DbSystemValues .DB2 , DbIncubatingAttributes .DbSystemValues .DERBY ,
70+ DbIncubatingAttributes .DbSystemValues .MSSQL , DbIncubatingAttributes .DbSystemValues .ORACLE ,
71+ DbIncubatingAttributes .DbSystemValues .SQLITE , DbIncubatingAttributes .DbSystemValues .OTHER_SQL ,
72+ DbIncubatingAttributes .DbSystemValues .HSQLDB , DbIncubatingAttributes .DbSystemValues .H2 ));
7073
7174 // this is needed until Azure SDK moves to latest OTel semantic conventions
7275 private static final String COSMOS = "Cosmos" ;
@@ -227,7 +230,8 @@ private static void applySemanticConventions(RemoteDependencyTelemetryBuilder te
227230 applyRpcClientSpan (telemetryBuilder , rpcSystem , attributes );
228231 return ;
229232 }
230- String dbSystem = attributes .get (DbIncubatingAttributes .DB_SYSTEM );
233+ String dbSystem
234+ = getStableOrOldAttribute (attributes , DbAttributes .DB_SYSTEM_NAME , DbIncubatingAttributes .DB_SYSTEM );
231235 if (dbSystem == null ) {
232236 // special case needed until Azure SDK moves to latest OTel semantic conventions
233237 dbSystem = attributes .get (AiSemanticAttributes .AZURE_SDK_DB_TYPE );
@@ -402,15 +406,17 @@ private static String getTarget(String host, @Nullable Long port, int defaultPor
402406
403407 private static void applyDatabaseClientSpan (RemoteDependencyTelemetryBuilder telemetryBuilder , String dbSystem ,
404408 Attributes attributes ) {
405- String dbStatement = attributes .get (DbIncubatingAttributes .DB_STATEMENT );
409+ String dbStatement
410+ = getStableOrOldAttribute (attributes , DbAttributes .DB_QUERY_TEXT , DbIncubatingAttributes .DB_STATEMENT );
406411 if (dbStatement == null ) {
407- dbStatement = attributes .get (DbIncubatingAttributes .DB_OPERATION );
412+ dbStatement = getStableOrOldAttribute (attributes , DbAttributes .DB_OPERATION_NAME ,
413+ DbIncubatingAttributes .DB_OPERATION );
408414 }
409415 String type ;
410416 if (SQL_DB_SYSTEMS .contains (dbSystem )) {
411- if (dbSystem .equals (DbIncubatingAttributes .DbSystemValues .MYSQL )) {
417+ if (dbSystem .equals (DbAttributes .DbSystemValues .MYSQL )) { // deprecated incubating constant had the same value
412418 type = "mysql" ; // this has special icon in portal
413- } else if (dbSystem .equals (DbIncubatingAttributes .DbSystemValues .POSTGRESQL )) {
419+ } else if (dbSystem .equals (DbAttributes .DbSystemValues .POSTGRESQL )) { // deprecated incubating constant had the same value
414420 type = "postgresql" ; // this has special icon in portal
415421 } else {
416422 type = "SQL" ;
@@ -437,7 +443,7 @@ private static void applyDatabaseClientSpan(RemoteDependencyTelemetryBuilder tel
437443 dbName = attributes .get (AiSemanticAttributes .AZURE_SDK_DB_INSTANCE );
438444 } else {
439445 target = getTargetOrDefault (attributes , getDefaultPortForDbSystem (dbSystem ), dbSystem );
440- dbName = attributes . get ( DbIncubatingAttributes .DB_NAME );
446+ dbName = getStableOrOldAttribute ( attributes , DbAttributes . DB_NAMESPACE , DbIncubatingAttributes .DB_NAME );
441447 }
442448 target = nullAwareConcat (target , dbName , " | " );
443449 if (target == null ) {
@@ -472,10 +478,11 @@ private static int getDefaultPortForDbSystem(String dbSystem) {
472478 case DbIncubatingAttributes .DbSystemValues .REDIS :
473479 return 6379 ;
474480
475- case DbIncubatingAttributes . DbSystemValues .MARIADB :
476- case DbIncubatingAttributes . DbSystemValues .MYSQL :
481+ case DbAttributes . DbSystemNameValues .MARIADB : // deprecated incubating constant had the same value
482+ case DbAttributes . DbSystemNameValues .MYSQL : // deprecated incubating constant had the same value
477483 return 3306 ;
478484
485+ case DbAttributes .DbSystemNameValues .MICROSOFT_SQL_SERVER :
479486 case DbIncubatingAttributes .DbSystemValues .MSSQL :
480487 return 1433 ;
481488
@@ -491,7 +498,7 @@ private static int getDefaultPortForDbSystem(String dbSystem) {
491498 case DbIncubatingAttributes .DbSystemValues .DERBY :
492499 return 1527 ;
493500
494- case DbIncubatingAttributes . DbSystemValues .POSTGRESQL :
501+ case DbAttributes . DbSystemNameValues .POSTGRESQL : // deprecated incubating constant had the same value
495502 return 5432 ;
496503
497504 default :
0 commit comments