diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java index 52d645dbda9..e1bf5828e6f 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java @@ -91,6 +91,10 @@ public final class AiSemanticAttributes { AttributeKey.stringKey("message_bus.destination"); public static final AttributeKey AZURE_SDK_ENQUEUED_TIME = AttributeKey.longKey("x-opt-enqueued-time"); + public static final AttributeKey AZURE_SDK_DB_TYPE = AttributeKey.stringKey("db.type"); + public static final AttributeKey AZURE_SDK_DB_INSTANCE = + AttributeKey.stringKey("db.instance"); + public static final AttributeKey AZURE_SDK_DB_URL = AttributeKey.stringKey("db.url"); public static final AttributeKey KAFKA_RECORD_QUEUE_TIME_MS = AttributeKey.longKey("kafka.record.queue_time_ms"); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index f2abc4ecc8e..3abc1c99fd9 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -56,6 +56,9 @@ public final class SpanDataMapper { SemanticAttributes.DbSystemValues.HSQLDB, SemanticAttributes.DbSystemValues.H2)); + // this is needed until Azure SDK moves to latest OTel semantic conventions + private static final String COSMOS = "Cosmos"; + private static final Mappings MAPPINGS; // TODO (trask) add to generated ContextTagKeys class @@ -164,6 +167,8 @@ private TelemetryItem exportRemoteDependency(SpanData span, boolean inProc, long telemetryBuilder.setSuccess(getSuccess(span)); if (inProc) { + // TODO (trask) need to handle Cosmos INTERNAL spans + // see https://github.com/microsoft/ApplicationInsights-Java/pull/2906/files#r1104981386 telemetryBuilder.setType("InProc"); } else { applySemanticConventions(telemetryBuilder, span); @@ -220,6 +225,10 @@ private static void applySemanticConventions( return; } String dbSystem = attributes.get(SemanticAttributes.DB_SYSTEM); + if (dbSystem == null) { + // special case needed until Azure SDK moves to latest OTel semantic conventions + dbSystem = attributes.get(AiSemanticAttributes.AZURE_SDK_DB_TYPE); + } if (dbSystem != null) { applyDatabaseClientSpan(telemetryBuilder, dbSystem, attributes); return; @@ -386,16 +395,31 @@ private static void applyDatabaseClientSpan( } else { type = "SQL"; } + } else if (dbSystem.equals(COSMOS)) { + // this has special icon in portal (documentdb was the old name for cosmos) + type = "Microsoft.DocumentDb"; } else { type = dbSystem; } telemetryBuilder.setType(type); telemetryBuilder.setData(dbStatement); - String target = - nullAwareConcat( - getTargetOrDefault(attributes, getDefaultPortForDbSystem(dbSystem), dbSystem), - attributes.get(SemanticAttributes.DB_NAME), - " | "); + + String target; + String dbName; + if (dbSystem.equals(COSMOS)) { + // special case needed until Azure SDK moves to latest OTel semantic conventions + String dbUrl = attributes.get(AiSemanticAttributes.AZURE_SDK_DB_URL); + if (dbUrl != null) { + target = UrlParser.getTarget(dbUrl); + } else { + target = null; + } + dbName = attributes.get(AiSemanticAttributes.AZURE_SDK_DB_INSTANCE); + } else { + target = getTargetOrDefault(attributes, getDefaultPortForDbSystem(dbSystem), dbSystem); + dbName = attributes.get(SemanticAttributes.DB_NAME); + } + target = nullAwareConcat(target, dbName, " | "); if (target == null) { target = dbSystem; }