ElasticApmModule Auto Instrumentation does not check if Agent.IsConfigured

APM Agent language and version: Elastic.Apm 1.12.1

Hi.

I've been following the guide to setup Apm on .NET Framework 4.8: ASP.NET | APM .NET Agent Reference [1.12] | Elastic

I'm using the auto instrumentation by adding the ElasticApmModule in the web.config but also have some filters configured on Application_Start.

I've added the following to ensure that the Agent is initialised before trying to configure a filter so that it is initialised with the FullFramework components:

if (!Agent.IsConfigured) {
    var agentComponents = ElasticApmModule.CreateAgentComponents();
    Agent.Setup(agentComponents);
}

What I've noticed is that when the ElasticApmModule initialises, it calls a method named SafeAgentSetup which then calls the following code without an Agent.IsConfigured check:

var agentComponents = CreateAgentComponents(dbgInstanceName);
if (!agentComponents.ConfigurationReader.Enabled)
    return;

Agent.Setup(agentComponents);

This seems to cause the "The singleton APM agent has already been instantiated and can no longer be configured. Reusing existing instance" error to be logged and also means that the AgentComponents are initialised twice. So with the GCMetricsProvider enabled, this is seemingly causing multiple TraceEventSessions to be spawned.

Firstly, am I configuring this correctly? If so, should the SafeAgentSetup be performing an IsConfigured check itself?

Cheers
Lee

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.