AppSettings ElasticApm:Enabled is not fully honored in ASP.NET Classic
See original GitHub issueWithout going in to the full details, there is a code path executed early during initialization that causes the Agent.Instance.ConfigurationReader
to be set to an instance of EnvironmentConfigurationReader
, thus bypassing the setting in Web.Config AppSettings. I believe the problem has it’s root in:
Elastic.Apm.AspNetFullFramework.ElasticApmModule.SafeAgentSetup():
AgentComponents agentComponents = CreateAgentComponents(dbgInstanceName);
if (agentComponents.ConfigurationReader.Enabled)
{
Agent.Setup(agentComponents);
}
This causes the Agent.Setup()
call to be skipped (because the Enabled
setting tested here does report ‘false’ from Web.Config), which in turn causes the later evalutation of Elastic.Apm.Agent.LazyApmAgent.Value
to call:
return new ApmAgent(Components);
with Components == null
(because of the above skip of Agent.Setup()
). This in turn calls:
internal ApmAgent(AgentComponents agentComponents)
{
Components = agentComponents ?? new AgentComponents();
}
and since agentComponents
is null
here, a new AgentComponents
is instantatiated like this:
public AgentComponents(IApmLogger logger = null, IConfigurationReader configurationReader = null, IPayloadSender payloadSender = null)
: this(logger, configurationReader, payloadSender, null, null, null, null)
{
}
where the important part is IConfigurationReader configurationReader = null
and this in turn results in:
internal AgentComponents(IApmLogger logger, IConfigurationReader configurationReader, IPayloadSender payloadSender, IMetricsCollector metricsCollector, ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer, ICentralConfigurationFetcher centralConfigurationFetcher, IApmServerInfo apmServerInfo, BreakdownMetricsProvider breakdownMetricsProvider = null)
{
try
{
IApmLogger tempLogger = logger ?? ConsoleLogger.LoggerOrDefault(configurationReader?.LogLevel);
ConfigurationReader = configurationReader ?? new EnvironmentConfigurationReader(tempLogger);
...
et voilà! We have a ConfigurationReader
of type EnvironmentConfigurationReader
not honoring the AppSettings value .
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top GitHub Comments
elastic-apm-issue.zip Hi @z1c0,
.NET 4.8 & Nuget
Thanks
Just to echo we have been debugging a fault whereby turning Enabled Off didn’t appear to work and we believe this is the root cause. Our settings are held in the Web.Config file and we don’t use Environment variables at all.
Setting ServerUrl to http://thing.com and Enabled to true - both settings are as expected Setting ServerUrl to http://thing.com and Enabled to false - Enabled is true and ServerUrl is http://localhost:8200