Skip to content

Commit face038

Browse files
committed
chore: update readme with very new changes in sqlclient instrumentation
1 parent 228aeaa commit face038

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,12 @@ These metrics help you understand polling patterns, database performance, messag
119119

120120
Since the SQL Server backplane performs frequent polling operations, you may want to filter out successful, fast queries to reduce trace noise.
121121

122-
The following example assumes using package `OpenTelemetry.Instrumentation.SqlClient` for SqlClient instrumentation. There are currently [4 different packages for SqlClient instrumentation](https://github.com/dotnet/aspire/issues/2427#issuecomment-3259572206), so your method of collecting or filtering the command details may vary if you're using Aspire's instrumentation or Azure Monitor's instrumentation. Be sure to update the CommandText filter if you customize the schema name:
122+
The following example assumes using package `OpenTelemetry.Instrumentation.SqlClient >= 1.12.0-beta.3` for SqlClient instrumentation. There are currently [4 different packages for SqlClient instrumentation](https://github.com/dotnet/aspire/issues/2427#issuecomment-3259572206), so your method of collecting or filtering the command details may vary if you're using Aspire's instrumentation or Azure Monitor's instrumentation. Be sure to update the CommandText filter if you customize the schema name:
123123

124124
``` cs
125125
builder.Services.AddOpenTelemetry()
126126
.WithTracing(tracing => tracing
127-
.AddSqlClientInstrumentation(options =>
128-
{
129-
options.Enrich = (activity, _, cmd) => activity.SetCustomProperty("sqlCommand", cmd);
130-
})
127+
.AddSqlClientInstrumentation()
131128
.AddSource("IntelliTect.AspNetCore.SignalR.SqlServer")
132129
.AddProcessor<SignalRTelemetryNoiseFilter>()
133130
);
@@ -138,8 +135,8 @@ internal sealed class SignalRTelemetryNoiseFilter : BaseProcessor<Activity>
138135
{
139136
if (activity.Status != ActivityStatusCode.Error &&
140137
activity.Duration.TotalMilliseconds < 100 &&
141-
activity.GetCustomProperty("sqlCommand") is DbCommand command &&
142-
command.CommandText.StartsWith("SELECT [PayloadId], [Payload], [InsertedOn] FROM [SignalR]") == true)
138+
(activity.GetTagItem("db.query.text") ?? activity.GetTagItem("db.statement")) is string command &&
139+
command.StartsWith("SELECT [PayloadId], [Payload], [InsertedOn] FROM [SignalR]"))
143140
{
144141
// Sample out successful and fast SignalR queries
145142
activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;

demo/DemoServer/DemoServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
1313
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
1414
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
15-
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.12.0-beta.1" />
15+
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.12.0-beta.3" />
1616
</ItemGroup>
1717

1818
<ItemGroup>

demo/DemoServer/Program.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@
4141
.AddSource("IntelliTect.AspNetCore.SignalR.SqlServer")
4242
.AddProcessor<SignalRMessagesNoiseFilterProcessor>()
4343
.AddAspNetCoreInstrumentation()
44-
.AddSqlClientInstrumentation(tracing =>
45-
{
46-
tracing.Enrich = (activity, _, cmd) => activity.SetCustomProperty("sqlCommand", cmd);
47-
})
44+
.AddSqlClientInstrumentation()
4845
);
4946

5047

@@ -109,8 +106,8 @@ public override void OnEnd(Activity activity)
109106
{
110107
if (activity.Status != ActivityStatusCode.Error &&
111108
activity.Duration.TotalMilliseconds < 100 &&
112-
activity.GetCustomProperty("sqlCommand") is DbCommand command &&
113-
command.CommandText.StartsWith("SELECT [PayloadId], [Payload], [InsertedOn] FROM [SignalR") == true)
109+
(activity.GetTagItem("db.query.text") ?? activity.GetTagItem("db.statement")) is string command &&
110+
command.StartsWith("SELECT [PayloadId], [Payload], [InsertedOn] FROM [SignalR"))
114111
{
115112
// Sample out successful and fast SignalR queries
116113
activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;

0 commit comments

Comments
 (0)