Set up SqlClient instrumentation
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes. The Elastic APM .NET agent enables you to trace the execution of operations in your .NET applications, sending performance metrics and errors to the Elastic APM server. Availability This functionality is generally available and ready for production usage. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless Observability
Generally available
Stack
Generally available
APM Agent .NET
Generally available
| 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());
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.