question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AppSettings ElasticApm:Enabled is not fully honored in ASP.NET Classic

See original GitHub issue

Without 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:closed
  • Created a year ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
PortSeventySixcommented, Dec 14, 2022

elastic-apm-issue.zip Hi @z1c0,

.NET 4.8 & Nuget

Thanks

1reaction
jzeloscommented, Dec 13, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

NET Agent version 1.x
Since these are currently not displayed in the APM UI, while technically breaking, ... #1961 AppSettings ElasticApm:Enabled is not fully honored in ASP.NET ......
Read more >
ASP.NET Core web service does not load appsettings.json ...
WebHostBuilder doesn't load appsettings.json by default, you need to manually call AddJsonFile . For example: return new WebHostBuilder() .
Read more >
Configuring ASP.NET Core In AWS - Cold-Brewed DevOps
I knew there was an appsettings.json file, but I treated it merely as a JSON-formatted version of classic ASP.NET's Web.config file.
Read more >
A Better Way to Inject AppSettings in Asp.NET Core
When I started using ASP.NET Core, I found the appSettings.json file quite fascinating. The idea of defining configuration settings and being able to...
Read more >
ASP.NET appSettings Element
NET checks the client's username before it performs this synchronization step. If this key value is true, ASP.NET performs no check.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found