Skip to content

Commit

Permalink
Better mapping of cosmos telemetry (#2906)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Feb 22, 2023
1 parent 4341890 commit 8d34a55
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ public final class AiSemanticAttributes {
AttributeKey.stringKey("message_bus.destination");
public static final AttributeKey<Long> AZURE_SDK_ENQUEUED_TIME =
AttributeKey.longKey("x-opt-enqueued-time");
public static final AttributeKey<String> AZURE_SDK_DB_TYPE = AttributeKey.stringKey("db.type");
public static final AttributeKey<String> AZURE_SDK_DB_INSTANCE =
AttributeKey.stringKey("db.instance");
public static final AttributeKey<String> AZURE_SDK_DB_URL = AttributeKey.stringKey("db.url");

public static final AttributeKey<Long> KAFKA_RECORD_QUEUE_TIME_MS =
AttributeKey.longKey("kafka.record.queue_time_ms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 8d34a55

Please sign in to comment.