Skip to content

Commit a18ff2f

Browse files
committed
fix
1 parent 6200581 commit a18ff2f

File tree

2 files changed

+104
-7
lines changed
  • agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration
  • smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest

2 files changed

+104
-7
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java

Lines changed: 103 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
import com.microsoft.applicationinsights.agent.internal.diagnostics.DiagnosticsHelper;
2323
import io.opentelemetry.api.common.AttributeKey;
2424
import io.opentelemetry.semconv.ClientAttributes;
25+
import io.opentelemetry.semconv.DbAttributes;
2526
import io.opentelemetry.semconv.HttpAttributes;
2627
import io.opentelemetry.semconv.NetworkAttributes;
2728
import io.opentelemetry.semconv.ServerAttributes;
2829
import io.opentelemetry.semconv.UrlAttributes;
30+
import io.opentelemetry.semconv.incubating.DbIncubatingAttributes;
2931
import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes;
3032
import io.opentelemetry.semconv.incubating.NetIncubatingAttributes;
3133
import java.io.IOException;
@@ -329,12 +331,16 @@ private static void supportTelemetryProcessorsOldSemConv(Configuration config) {
329331
for (Configuration.ProcessorConfig processor : config.preview.processors) {
330332
if (processor.include != null && processor.type == Configuration.ProcessorType.ATTRIBUTE) {
331333
for (Configuration.ProcessorAttribute attribute : processor.include.attributes) {
334+
String oldKey = attribute.key;
332335
attribute.key = mapAttributeKey(attribute.key);
336+
attribute.value = mapAttributeValue(oldKey, attribute.value);
333337
}
334338
}
335339
if (processor.exclude != null && processor.type == Configuration.ProcessorType.ATTRIBUTE) {
336340
for (Configuration.ProcessorAttribute attribute : processor.exclude.attributes) {
341+
String oldKey = attribute.key;
337342
attribute.key = mapAttributeKey(attribute.key);
343+
attribute.value = mapAttributeValue(oldKey, attribute.value);
338344
}
339345
}
340346
for (Configuration.ProcessorAction action : processor.actions) {
@@ -405,14 +411,105 @@ private static String mapAttributeKey(String oldAttributeKey) {
405411
result = ServerAttributes.SERVER_PORT.getKey();
406412
}
407413

414+
// Database span attributes
415+
if (oldAttributeKey.equals("db.system")) {
416+
result = DbAttributes.DB_SYSTEM_NAME.getKey();
417+
} else if (oldAttributeKey.equals(DbIncubatingAttributes.DB_STATEMENT.getKey())) {
418+
result = DbAttributes.DB_QUERY_TEXT.getKey();
419+
} else if (oldAttributeKey.equals(DbIncubatingAttributes.DB_OPERATION.getKey())) {
420+
result = DbAttributes.DB_OPERATION_NAME.getKey();
421+
} else if (oldAttributeKey.equals(DbIncubatingAttributes.DB_SQL_TABLE.getKey())
422+
|| oldAttributeKey.equals(DbIncubatingAttributes.DB_CASSANDRA_TABLE.getKey())
423+
|| oldAttributeKey.equals(DbIncubatingAttributes.DB_MONGODB_COLLECTION.getKey())
424+
|| oldAttributeKey.equals(DbIncubatingAttributes.DB_COSMOSDB_CONTAINER.getKey())) {
425+
result = DbAttributes.DB_COLLECTION_NAME.getKey();
426+
}
427+
408428
if (result == null) {
409-
result = oldAttributeKey;
410-
} else {
411-
configurationLogger.warn(
412-
"\"{}\" has been deprecated and replaced with \"{}\" since 3.5.0 GA.",
413-
oldAttributeKey,
414-
result);
429+
return oldAttributeKey;
415430
}
431+
432+
// Database attributes were stabilized in 3.8.0, HTTP attributes in 3.5.0
433+
String version = oldAttributeKey.startsWith("db.") ? "3.8.0 GA" : "3.5.0 GA";
434+
configurationLogger.warn(
435+
"\"{}\" has been deprecated and replaced with \"{}\" since {}.",
436+
oldAttributeKey,
437+
result,
438+
version);
439+
return result;
440+
}
441+
442+
@SuppressWarnings("deprecation") // support deprecated semconv for backwards compatibility
443+
@Nullable
444+
private static Object mapAttributeValue(
445+
String oldAttributeKey, @Nullable Object oldAttributeValue) {
446+
Object result = null;
447+
if (DbIncubatingAttributes.DB_SYSTEM.getKey().equals(oldAttributeKey)
448+
&& oldAttributeValue instanceof String) {
449+
String stringValue = (String) oldAttributeValue;
450+
switch (stringValue) {
451+
case DbIncubatingAttributes.DbSystemIncubatingValues.MSSQL:
452+
result = DbAttributes.DbSystemNameValues.MICROSOFT_SQL_SERVER;
453+
break;
454+
case DbIncubatingAttributes.DbSystemIncubatingValues.DB2:
455+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.IBM_DB2;
456+
break;
457+
case DbIncubatingAttributes.DbSystemIncubatingValues.ORACLE:
458+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.ORACLE_DB;
459+
break;
460+
case DbIncubatingAttributes.DbSystemIncubatingValues.HANADB:
461+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.SAP_HANA;
462+
break;
463+
case DbIncubatingAttributes.DbSystemIncubatingValues.MAXDB:
464+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.SAP_MAXDB;
465+
break;
466+
case DbIncubatingAttributes.DbSystemIncubatingValues.CACHE:
467+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.INTERSYSTEMS_CACHE;
468+
break;
469+
case DbIncubatingAttributes.DbSystemIncubatingValues.ADABAS:
470+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.SOFTWAREAG_ADABAS;
471+
break;
472+
case DbIncubatingAttributes.DbSystemIncubatingValues.INGRES:
473+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.ACTIAN_INGRES;
474+
break;
475+
case DbIncubatingAttributes.DbSystemIncubatingValues.NETEZZA:
476+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.IBM_NETEZZA;
477+
break;
478+
case DbIncubatingAttributes.DbSystemIncubatingValues.INFORMIX:
479+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.IBM_INFORMIX;
480+
break;
481+
case DbIncubatingAttributes.DbSystemIncubatingValues.SPANNER:
482+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.GCP_SPANNER;
483+
break;
484+
case DbIncubatingAttributes.DbSystemIncubatingValues.COSMOSDB:
485+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.AZURE_COSMOSDB;
486+
break;
487+
case DbIncubatingAttributes.DbSystemIncubatingValues.DYNAMODB:
488+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.AWS_DYNAMODB;
489+
break;
490+
case DbIncubatingAttributes.DbSystemIncubatingValues.REDSHIFT:
491+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.AWS_REDSHIFT;
492+
break;
493+
case DbIncubatingAttributes.DbSystemIncubatingValues.H2:
494+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.H2DATABASE;
495+
break;
496+
case DbIncubatingAttributes.DbSystemIncubatingValues.FIREBIRD:
497+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.FIREBIRDSQL;
498+
break;
499+
default:
500+
// do nothing
501+
}
502+
}
503+
504+
if (result == null) {
505+
return oldAttributeValue;
506+
}
507+
508+
configurationLogger.warn(
509+
"\"{}\" attribute value \"{}\" has been deprecated and replaced with \"{}\" since 3.8.0 GA.",
510+
oldAttributeKey,
511+
oldAttributeValue,
512+
result);
416513
return result;
417514
}
418515

smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ void hsqldbBatchPreparedStatement() throws Exception {
121121
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
122122
assertThat(telemetry.rd.getSuccess()).isTrue();
123123

124-
assertThat(telemetry.rdd1.getName()).isEqualTo("INSERT testdb.abc");
124+
assertThat(telemetry.rdd1.getName()).isEqualTo("BATCH INSERT testdb.abc");
125125
assertThat(telemetry.rdd1.getData()).isEqualTo("insert into abc (xyz) values (?)");
126126
assertThat(telemetry.rdd1.getType()).isEqualTo("SQL");
127127
assertThat(telemetry.rdd1.getTarget()).isEqualTo("hsqldb | testdb");

0 commit comments

Comments
 (0)