Skip to content

Commit 88d0d58

Browse files
committed
fix
1 parent 6200581 commit 88d0d58

File tree

2 files changed

+102
-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

+102
-7
lines changed

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

Lines changed: 101 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,103 @@ 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(String oldAttributeKey, @Nullable Object oldAttributeValue) {
445+
Object result = null;
446+
if (DbIncubatingAttributes.DB_SYSTEM.getKey().equals(oldAttributeKey) && oldAttributeValue instanceof String) {
447+
String stringValue = (String) oldAttributeValue;
448+
switch (stringValue) {
449+
case DbIncubatingAttributes.DbSystemIncubatingValues.MSSQL:
450+
result = DbAttributes.DbSystemNameValues.MICROSOFT_SQL_SERVER;
451+
break;
452+
case DbIncubatingAttributes.DbSystemIncubatingValues.DB2:
453+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.IBM_DB2;
454+
break;
455+
case DbIncubatingAttributes.DbSystemIncubatingValues.ORACLE:
456+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.ORACLE_DB;
457+
break;
458+
case DbIncubatingAttributes.DbSystemIncubatingValues.HANADB:
459+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.SAP_HANA;
460+
break;
461+
case DbIncubatingAttributes.DbSystemIncubatingValues.MAXDB:
462+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.SAP_MAXDB;
463+
break;
464+
case DbIncubatingAttributes.DbSystemIncubatingValues.CACHE:
465+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.INTERSYSTEMS_CACHE;
466+
break;
467+
case DbIncubatingAttributes.DbSystemIncubatingValues.ADABAS:
468+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.SOFTWAREAG_ADABAS;
469+
break;
470+
case DbIncubatingAttributes.DbSystemIncubatingValues.INGRES:
471+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.ACTIAN_INGRES;
472+
break;
473+
case DbIncubatingAttributes.DbSystemIncubatingValues.NETEZZA:
474+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.IBM_NETEZZA;
475+
break;
476+
case DbIncubatingAttributes.DbSystemIncubatingValues.INFORMIX:
477+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.IBM_INFORMIX;
478+
break;
479+
case DbIncubatingAttributes.DbSystemIncubatingValues.SPANNER:
480+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.GCP_SPANNER;
481+
break;
482+
case DbIncubatingAttributes.DbSystemIncubatingValues.COSMOSDB:
483+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.AZURE_COSMOSDB;
484+
break;
485+
case DbIncubatingAttributes.DbSystemIncubatingValues.DYNAMODB:
486+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.AWS_DYNAMODB;
487+
break;
488+
case DbIncubatingAttributes.DbSystemIncubatingValues.REDSHIFT:
489+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.AWS_REDSHIFT;
490+
break;
491+
case DbIncubatingAttributes.DbSystemIncubatingValues.H2:
492+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.H2DATABASE;
493+
break;
494+
case DbIncubatingAttributes.DbSystemIncubatingValues.FIREBIRD:
495+
result = DbIncubatingAttributes.DbSystemNameIncubatingValues.FIREBIRDSQL;
496+
break;
497+
default:
498+
// do nothing
499+
}
500+
}
501+
502+
if (result == null) {
503+
return oldAttributeValue;
504+
}
505+
506+
configurationLogger.warn(
507+
"\"{}\" attribute value \"{}\" has been deprecated and replaced with \"{}\" since 3.8.0 GA.",
508+
oldAttributeKey,
509+
oldAttributeValue,
510+
result);
416511
return result;
417512
}
418513

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)