Type to search.

Set up Entity Framework 6 instrumentation

Serverless Observability

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    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.

APM Agent .NET

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

  • Generally available

    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.

Package Supported versions
EntityFramework ≥6.2 ≤6.5.2

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.EntityFramework6 NuGet package to your project:

Shell
dotnet add package Elastic.Apm.EntityFramework6

Include the Ef6Interceptor interceptor in your application’s web.config:

Xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <entityFramework>
        <interceptors>
            <interceptor type="Elastic.Apm.EntityFramework6.Ef6Interceptor, Elastic.Apm.EntityFramework6" />
        </interceptors>
    </entityFramework>
</configuration>

As an alternative to registering the interceptor via the configuration, you can register it in the application code:

C#
using System.Data.Entity;

DbInterception.Add(new Elastic.Apm.EntityFramework6.Ef6Interceptor());

For example, in an ASP.NET application, you can place the above call in the Application_Start method.

Instrumentation works with EntityFramework ≥6.2 ≤6.5.2 NuGet packages.

Note

Be careful not to execute DbInterception.Add for the same interceptor type more than once, as this will register multiple instances, causing multiple database spans to be captured for every SQL command.