Loading

Set up SqlClient instrumentation

Package Supported versions
System.Data.SqlClient ≥4.0.0 <5.0.0
Microsoft.Data.SqlClient ≥1.0.0 <6.0.0

For the full compatibility matrix including supported installation methods, refer to Data access technologies.

This page assumes the core agent is already set up. If not, see Set up the APM .NET Agent first.

Add the Elastic.Apm.SqlClient NuGet package to your project:

dotnet add package Elastic.Apm.SqlClient
		

Pass SqlClientDiagnosticSubscriber to the AddElasticApm method in case of ASP.NET Core:

using Elastic.Apm.SqlClient;

app.Services.AddElasticApm(new SqlClientDiagnosticSubscriber());
		

or passing SqlClientDiagnosticSubscriber to the Subscribe method and make sure that the code is called only once, otherwise the same database call could be captured multiple times:

using Elastic.Apm;
using Elastic.Apm.SqlClient;

Agent.Subscribe(new SqlClientDiagnosticSubscriber());
		
Note

System.Data.SqlClient tracing is available for both .NET and .NET Framework applications, however, support of .NET Framework has one limitation: command text cannot be captured.

Microsoft.Data.SqlClient tracing is available only for .NET at the moment.

As an alternative to using the Elastic.Apm.SqlClient package to instrument database calls, see Profiler Auto instrumentation.