Set up Entity Framework Core instrumentation
| Package | Supported versions |
|---|---|
Microsoft.EntityFrameworkCore |
≥8.0.0 ≤10.0.x |
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.EntityFrameworkCore NuGet package to your project:
dotnet add package Elastic.Apm.EntityFrameworkCore
Pass EfCoreDiagnosticsSubscriber to the AddElasticApm method in case of ASP.NET Core, as follows:
using Elastic.Apm.EntityFrameworkCore;
app.Services.AddElasticApm(new EfCoreDiagnosticsSubscriber());
or passing EfCoreDiagnosticsSubscriber to the Subscribe method
using Elastic.Apm;
using Elastic.Apm.EntityFrameworkCore;
Agent.Subscribe(new EfCoreDiagnosticsSubscriber());
Instrumentation listens for diagnostic events raised by Microsoft.EntityFrameworkCore, creating database spans for executed commands.