ASP.NETedit

Quick startedit

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, Elastic.Apm.AspNetFullFramework" />
        </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, Elastic.Apm.AspNetFullFramework" preCondition="managedHandler" />
        </modules>
    </system.webServer>
</configuration>

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

The ElasticApmModule instantiates the APM agent on first initialization. There are some scenarios however where you might want to control agent instantiatiation, such as configuring filters in application start. The ElasticApmModule exposes a CreateAgentComponents() method that returns agent components configured to work with ASP.NET Full Framework, that can then be used to instantiate the agent.

For example, one might wish to add transaction filters to the agent in application start

public class MvcApplication : HttpApplication
{
    protected void Application_Start()
    {
        // other application startup e.g. RouteConfig, etc.

        // set up agent with components
        var agentComponents = ElasticApmModule.CreateAgentComponents();
        Agent.Setup(agentComponents);

        // add transaction filter
        Agent.AddFilter((ITransaction t) =>
        {
            t.SetLabel("foo", "bar");
            return t;
        });
    }
}

Now, the ElasticApmModule will use the already instantiated APM agent instance upon initialization.