|
22 | 22 | import com.microsoft.applicationinsights.agent.internal.diagnostics.DiagnosticsHelper; |
23 | 23 | import io.opentelemetry.api.common.AttributeKey; |
24 | 24 | import io.opentelemetry.semconv.ClientAttributes; |
| 25 | +import io.opentelemetry.semconv.DbAttributes; |
25 | 26 | import io.opentelemetry.semconv.HttpAttributes; |
26 | 27 | import io.opentelemetry.semconv.NetworkAttributes; |
27 | 28 | import io.opentelemetry.semconv.ServerAttributes; |
28 | 29 | import io.opentelemetry.semconv.UrlAttributes; |
| 30 | +import io.opentelemetry.semconv.incubating.DbIncubatingAttributes; |
29 | 31 | import io.opentelemetry.semconv.incubating.HttpIncubatingAttributes; |
30 | 32 | import io.opentelemetry.semconv.incubating.NetIncubatingAttributes; |
31 | 33 | import java.io.IOException; |
@@ -329,12 +331,16 @@ private static void supportTelemetryProcessorsOldSemConv(Configuration config) { |
329 | 331 | for (Configuration.ProcessorConfig processor : config.preview.processors) { |
330 | 332 | if (processor.include != null && processor.type == Configuration.ProcessorType.ATTRIBUTE) { |
331 | 333 | for (Configuration.ProcessorAttribute attribute : processor.include.attributes) { |
| 334 | + String oldKey = attribute.key; |
332 | 335 | attribute.key = mapAttributeKey(attribute.key); |
| 336 | + attribute.value = mapAttributeValue(oldKey, attribute.value); |
333 | 337 | } |
334 | 338 | } |
335 | 339 | if (processor.exclude != null && processor.type == Configuration.ProcessorType.ATTRIBUTE) { |
336 | 340 | for (Configuration.ProcessorAttribute attribute : processor.exclude.attributes) { |
| 341 | + String oldKey = attribute.key; |
337 | 342 | attribute.key = mapAttributeKey(attribute.key); |
| 343 | + attribute.value = mapAttributeValue(oldKey, attribute.value); |
338 | 344 | } |
339 | 345 | } |
340 | 346 | for (Configuration.ProcessorAction action : processor.actions) { |
@@ -405,14 +411,105 @@ private static String mapAttributeKey(String oldAttributeKey) { |
405 | 411 | result = ServerAttributes.SERVER_PORT.getKey(); |
406 | 412 | } |
407 | 413 |
|
| 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 | + |
408 | 428 | 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; |
415 | 430 | } |
| 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); |
416 | 513 | return result; |
417 | 514 | } |
418 | 515 |
|
|
0 commit comments