SqlClient
Serverless ObservabilityStackAPM Agent .NET
You can enable auto instrumentation forSystem.Data.SqlClient orMicrosoft.Data.SqlClient by referencingElastic.Apm.SqlClient package and passingSqlClientDiagnosticSubscriber to theAddElasticApm method in case of ASP.NET Core as it shown in example:
// Enable tracing of outgoing db requestsapp.Services.AddElasticApm(new SqlClientDiagnosticSubscriber());or passingSqlClientDiagnosticSubscriber to theSubscribe 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 requestsAgent.Subscribe(new SqlClientDiagnosticSubscriber());Auto instrumentation forSystem.Data.SqlClient is available for both .NET and .NET Framework applications, however, support of .NET Framework has one limitation: command text cannot be captured.
Auto instrumentation forMicrosoft.Data.SqlClient is available only for .NET at the moment.
As an alternative to using theElastic.Apm.SqlClient package to instrument database calls, seeProfiler Auto instrumentation.