Set up the Agentedit

The .NET Agent ships as a set of NuGet packages via nuget.org. You can add the Agent to your .NET application by referencing one of these packages.

Packagesedit

The following packages are available:

Elastic.Apm.NetCoreAll
This is a meta package that references every other Elastic APM .NET agent package. If you plan to monitor a typical ASP.NET Core application that depends on the Microsoft.AspNetCore.All package and uses Entity Framework Core then you should reference this package. In order to avoid adding unnecessary dependencies in applications that aren’t depending on the Microsoft.AspNetCore.All package we also offer some other packages - those are all referenced by the Elastic.Apm.NetCoreAll package.
Elastic.Apm
This is the core of the agent, which we didn’t name “Core”, because someone already took that name :) This package also contains the Public API and it is a .NET Standard 2.0 package. We also ship every tracing component that traces classes that are part of .NET Standard 2.0 in this package, which includes the monitoring part for HttpClient. Every other Elastic APM package references this package.
Elastic.Apm.AspNetCore
This package contains ASP.NET Core monitoring related code. The main difference between this package and the Elastic.Apm.NetCoreAll package is that this package does not reference the Elastic.Apm.EntityFrameworkCore package, so if you have an ASP.NET Core application that does not use EF Core and you want to avoid adding additional unused references, you should use this package.
Elastic.Apm.EntityFrameworkCore
This package contains EF Core monitoring related code.
Elastic.Apm.AspNetFullFramework
This package contains ASP.NET (Full .NET Framework) monitoring related code.

Quick startedit

ASP.NET Coreedit

For ASP.NET Core, once you referenced the Elastic.Apm.NetCoreAll package, you can enable auto instrumentation by calling UseAllElasticApm() extension method:

public class Startup
{
  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
    app.UseAllElasticApm(Configuration);
    //…rest of the method
  }
  //…rest of the class
}

With this you enable every agent component including ASP.NET Core tracing, monitoring of outgoing HTTP request, Entity Framework Core database tracing, etc.

In case you only reference the Elastic.Apm.AspNetCore package, you won’t find the UseAllElasticApm. Instead you need to use the UseElasticApm() method from the Elastic.Apm.AspNetCore namespace. This method turns on ASP.NET Core tracing, and gives you the opportunity to manually turn on other components. By default it will only trace ASP.NET Core requests - No HTTP request tracing, database call tracing or any other tracing component will be turned on.

In case you only want to use the Public API, you don’t need to do any initialization, you can simply start using the API and the agent will send the data to the APM Server.

ASP.NETedit

For ASP.NET (Full .NET Framework), once you’ve referenced the Elastic.Apm.AspNetFullFramework package, you can enable auto instrumentation by including the ElasticApmModule IIS Module in your application’s web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <modules>
            <add name="ElasticApmModule" type="Elastic.Apm.AspNetFullFramework.ElasticApmModule" />
        </modules>
    </system.webServer>
</configuration>

By default the agent creates transactions for all HTTP requests, including the ones for static content: .html pages, images, etc. If you would like to create transactions only for HTTP requests with dynamic content, such as .aspx pages, you can add managedHandler preCondition (official documentation) as shown in the following example:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <modules>
            <add name="ElasticApmModule" type="Elastic.Apm.AspNetFullFramework.ElasticApmModule" preCondition="managedHandler" />
        </modules>
    </system.webServer>
</configuration>

You can also configure the agent using web.config as described at Configuration on ASP.NET.