Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better mapping of cosmos telemetry #2906

Merged
merged 5 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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