Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
initial changes
  • Loading branch information
Matthew Sainsbury committed Oct 7, 2025
commit 6a77f8de1575bf5f68e4555a1f93ecb41af0d43c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public RemoteDependencyData(int version, Activity activity, ref ActivityTagsProc
SetHttpDependencyPropertiesAndDependencyName(activity, ref activityTagsProcessor.MappedTags, isNewSchemaVersion, out dependencyName);
break;
case OperationType.Db:
SetDbDependencyProperties(ref activityTagsProcessor.MappedTags);
SetDbDependencyProperties(ref activityTagsProcessor.MappedTags, isNewSchemaVersion);
break;
case OperationType.Messaging:
SetMessagingDependencyProperties(activity, ref activityTagsProcessor.MappedTags);
Expand Down Expand Up @@ -86,11 +86,23 @@ private void SetHttpDependencyPropertiesAndDependencyName(Activity activity, ref
ResultCode = resultCode?.Truncate(SchemaConstants.RemoteDependencyData_ResultCode_MaxLength) ?? "0";
}

private void SetDbDependencyProperties(ref AzMonList dbTagObjects)
private void SetDbDependencyProperties(ref AzMonList dbTagObjects, bool isNewSchemaVersion)
{
var dbAttributeTagObjects = AzMonList.GetTagValues(ref dbTagObjects, SemanticConventions.AttributeDbStatement, SemanticConventions.AttributeDbSystem);
string statementAttributeKey;
string statementSystemKey;
if (isNewSchemaVersion)
{
statementAttributeKey = SemanticConventions.AttributeDbQueryText;
statementSystemKey = SemanticConventions.AttributeDbSystemName;
}
else
{
statementAttributeKey = SemanticConventions.AttributeDbStatement;
statementSystemKey = SemanticConventions.AttributeDbSystem;
}
var dbAttributeTagObjects = AzMonList.GetTagValues(ref dbTagObjects, statementAttributeKey, statementSystemKey);
Data = dbAttributeTagObjects[0]?.ToString().Truncate(SchemaConstants.RemoteDependencyData_Data_MaxLength);
var (DbName, DbTarget) = dbTagObjects.GetDbDependencyTargetAndName();
var (DbName, DbTarget) = dbTagObjects.GetDbDependencyTargetAndName(isNewSchemaVersion);
Target = DbTarget?.Truncate(SchemaConstants.RemoteDependencyData_Target_MaxLength);
Type = AzMonListExtensions.s_dbSystems.Contains(dbAttributeTagObjects[1]?.ToString()) ? "SQL" : dbAttributeTagObjects[1]?.ToString().Truncate(SchemaConstants.RemoteDependencyData_Type_MaxLength);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public void CategorizeTags(Activity activity)
case SemanticConventions.AttributeDbSystem:
activityType = OperationType.Db;
break;
case SemanticConventions.AttributeDbSystemName:
activityType = OperationType.Db | OperationType.V2;
break;
case SemanticConventions.AttributeMessagingSystem:
activityType = OperationType.Messaging;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,20 @@ internal static string GetDefaultDbPort(string? dbSystem)
///<summary>
/// Gets Database dependency target and name from activity tag objects.
///</summary>
internal static (string? DbName, string? DbTarget) GetDbDependencyTargetAndName(this AzMonList tagObjects)
internal static (string? DbName, string? DbTarget) GetDbDependencyTargetAndName(this AzMonList tagObjects, bool isNewSchemaVersion)
{
var peerServiceAndDbSystem = AzMonList.GetTagValues(ref tagObjects, SemanticConventions.AttributePeerService, SemanticConventions.AttributeDbSystem);

string statementDbNameKey;
string statementDbSystemKey;
if (isNewSchemaVersion) {
statementDbNameKey = SemanticConventions.AttributeDbNamespace;
statementDbSystemKey = SemanticConventions.AttributeDbSystemName;
} else {
statementDbNameKey = SemanticConventions.AttributeDbName;
statementDbSystemKey = SemanticConventions.AttributeDbSystem;
}

var peerServiceAndDbSystem = AzMonList.GetTagValues(ref tagObjects, SemanticConventions.AttributePeerService, statementDbSystemKey);
string? target = peerServiceAndDbSystem[0]?.ToString();
var defaultPort = GetDefaultDbPort(peerServiceAndDbSystem[1]?.ToString());

Expand All @@ -340,7 +351,7 @@ internal static (string? DbName, string? DbTarget) GetDbDependencyTargetAndName(
target = tagObjects.GetTargetUsingServerAttributes(defaultPort) ?? tagObjects.GetTargetUsingNetPeerAttributes(defaultPort);
}

var dbName = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeDbName)?.ToString();
var dbName = AzMonList.GetTagValue(ref tagObjects, statementDbNameKey)?.ToString();
bool isTargetEmpty = string.IsNullOrWhiteSpace(target);
bool isDbNameEmpty = string.IsNullOrWhiteSpace(dbName);
if (!isTargetEmpty && !isDbNameEmpty)
Expand All @@ -353,7 +364,7 @@ internal static (string? DbName, string? DbTarget) GetDbDependencyTargetAndName(
}
else if (isTargetEmpty && isDbNameEmpty)
{
target = AzMonList.GetTagValue(ref tagObjects, SemanticConventions.AttributeDbSystem)?.ToString();
target = AzMonList.GetTagValue(ref tagObjects, statementDbSystemKey)?.ToString();
}

return (DbName: dbName, DbTarget: target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,16 @@ internal static class SemanticConventions
// Messaging v1.21.0 https://github.com/open-telemetry/opentelemetry-specification/blob/v1.21.0/specification/trace/semantic_conventions/messaging.md
public const string AttributeMessagingDestinationName = "messaging.destination.name";
public const string AttributeNetworkProtocolName = "network.protocol.name";

// Database v1.36.0 https://github.com/open-telemetry/semantic-conventions/tree/v1.36.0/docs/database
public const string AttributeDbCollectionName = "db.collection.name";
public const string AttributeDbOperationName = "db.operation.name";
public const string AttributeDbSystemName = "db.system.name";
public const string AttributeDbNamespace = "db.namespace";
public const string AttributeDbResponseStatusCode = "db.response.status_code";
public const string AttributeDbOperationBatchSize = "db.operation.batch.size";
public const string AttributeDbQuerySummary = "db.query.summary";
public const string AttributeDbQueryText = "db.query.text";
public const string AttributeDbStoredProcedureName = "db.stored_procedure.name";
}
}