SqlClient
editSqlClient
editQuick start
editYou can enable auto instrumentation for System.Data.SqlClient
or Microsoft.Data.SqlClient
by referencing Elastic.Apm.SqlClient
package
and passing SqlClientDiagnosticSubscriber
to the AddElasticApm
method in case of ASP.NET Core as it shown in example:
// Enable tracing of outgoing db requests 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:
// Enable tracing of outgoing db requests Agent.Subscribe(new SqlClientDiagnosticSubscriber());
Auto instrumentation for System.Data.SqlClient
is available for both .NET Core and .NET Framework applications, however, support of .NET Framework has one limitation:
command text cannot be captured.
Auto instrumentation for Microsoft.Data.SqlClient
is available only for .NET Core at the moment.
As an alternative to using the Elastic.Apm.SqlClient
package to instrument database calls, see Profiler Auto instrumentation.