Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include SQL query parameter values in Application Insights telemetry

For ASP.NET Core (and likely other platforms), Application Insights by default tracks all queries to Azure SQL Database (and likely other platforms) as dependency operations. For each query, it records the query string, something like this:

SELECT [b].[Foo] FROM [Bar] AS [b] WHERE [b].[Id] = @id

However, it doesn't record the value of @id. How do I make it record the values of the query parameters?

like image 912
Edward Brey Avatar asked Mar 01 '26 23:03

Edward Brey


1 Answers

This is tracked as a feature request on GitHub: https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/193

We already implemented this type of extensibility for http calls where you now have access to the original http request object to extract additional details.

With the current version of SDK the best option is to set those parameters somewhere on current thread and access from telemetry initializer or track this operation manually by wrapping all SQL calls.

Hope this helps

like image 146
Sergey Kanzhelev Avatar answered Mar 04 '26 17:03

Sergey Kanzhelev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!