Add instrumentation for Microsoft.Data.SqlClient for .Net Framework target
See original GitHub issueDuring implementation auto instrumentation for System.Data.SqlClient
it was decided to skip it for Microsoft.Data.SqlClient
due to issue which is described in a comment at https://github.com/elastic/apm-agent-dotnet/pull/704#discussion_r381478027.
Shortly, the issue is in the same event source names for System.Data.SqlClient
and Microsoft.Data.SqlClient
. It was changed in https://github.com/dotnet/SqlClient/pull/399 and the event source name for Microsoft.Data.SqlClient
can be found at https://github.com/JRahnama/SqlClient/blob/27f3bba874d55ef3d6670b945cc584e7cd2de69c/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEventSource.cs#L11. The fix is going to be released in v2.0.0-preview2 and as a result will be available in 2.0.0 GA version.
So, it means that we can add support of auto instrumentation for Microsoft.Data.SqlClient
package for .Net Framework target.
I open the issue with the following intention:
- To not forget that we have such limitation
- To understand how users are interested in a feature
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:10 (5 by maintainers)
Top GitHub Comments
Hey, @dominikskiba.
As I understand correctly, you already installed
Elastic.Apm.AspNetFullFramework
module and configured in a proper way. If so, that means you also need to downloadElastic.Apm.SqlClient
NuGet package from CI (to be honest, I didn’t do it and it would be nice to ask for more details @gregkalapos ) or wait for public release. After that, you can enable instrumentation for database calls by the following code:As for place, where you need to put it. Yeap, it can be
Init
method ofGlobal.asax.cs
file, however, I cannot guarantee that will work in your case due to it depends on a codebase. Although in general, it should work and safe to do it. If you still want to do it, you need to look intoGlobal.asax.cs
file instead ofGlobal.asax
.I hope, it will help you in your case
Support for common SqlClient providers has been implemented as part of profiler auto instrumentation in #1534. This includes capturing command text on all target frameworks that the agent supports. Profiler auto instrumentation is scheduled to be released as beta in the next release, 1.12.