Skip to content

Commit 98f6f6d

Browse files
committed
Add db.query.summary and db.operation.name for Text commands
Set db.query.summary as the low-cardinality activity name on all spans. For Text commands, extract the first SQL verb (SELECT, INSERT, etc.) and use it as db.operation.name and in the activity name.
1 parent f68747f commit 98f6f6d

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/FirebirdSql.Data.FirebirdClient/Trace/FbActivitySource.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ internal static Activity CommandStart(FbCommand command)
3737
break;
3838

3939
case CommandType.Text:
40-
activityName = dbName;
40+
dbOperationName = ExtractSqlVerb(command.CommandText);
41+
activityName = dbOperationName ?? dbName;
4142
break;
4243

4344
default:
@@ -65,6 +66,8 @@ internal static Activity CommandStart(FbCommand command)
6566
activity.SetTag("db.operation.name", dbOperationName);
6667
}
6768

69+
activity.SetTag("db.query.summary", activityName);
70+
6871
if (command.CommandType == CommandType.StoredProcedure)
6972
{
7073
activity.SetTag("db.stored_procedure.name", command.CommandText);
@@ -119,5 +122,16 @@ internal static void CommandException(Activity activity, Exception exception)
119122
activity.SetStatus(ActivityStatusCode.Error, errorDescription);
120123
activity.Dispose();
121124
}
125+
126+
static string ExtractSqlVerb(string sql)
127+
{
128+
if (string.IsNullOrEmpty(sql))
129+
return null;
130+
var span = sql.AsSpan().TrimStart();
131+
var spaceIndex = span.IndexOfAny(' ', '\t', '\n', '\r');
132+
if (spaceIndex <= 0)
133+
return span.Length > 0 ? span.ToString().ToUpperInvariant() : null;
134+
return span.Slice(0, spaceIndex).ToString().ToUpperInvariant();
135+
}
122136
}
123137
}

0 commit comments

Comments
 (0)