Apm agent can't read the configuration from appsettings.Release.json

Kibana version: 8.3.3

Elasticsearch version:8.3.3

APM Server version:8.3.3

APM Agent language and version:dotnet core 1.25.3

Fresh install or upgraded from other version? Fresh install

The APM dotnet core agent doesn't read configuration from the appsettings.Release.json

appsettings.Release.json:
	{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Elastic.Apm": "Debug",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
      
    }
  },
  "ElasticApm": {
    "ServerUrl": "http://10.10.10.10:8600",
    "SecretToken": "xxxxxxxx",
    "ServiceName": "ServiceCatalog", 
    "Environment": "ServiceCatalog_prod"
    }
	}

and I am passing the configuration in the Startup.cs to app.UseAllElasticApm method as below :

using Elastic.Apm.NetCoreAll;

namespace ServiceCatalog
{
    public class Startup
    {
        public IConfiguration Configuration { get; }
        
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseAllElasticApm(Configuration);

        }
    }
}

you can find the log below :

2024-02-13 15: 01: 10.573 [Information] Application Started.
2024-02-13 15: 01: 10.613 [Information] Application running on environment Release
2024-02-13 15: 01: 10.613 [Information] Application version 1.2.8
2024-02-13 15: 01: 10.613 [Information] ServiceCatalog Seeded
2024-02-13 15: 01: 10.684 [Information] {"AbstractConfigurationReader (ApmConfiguration)"} The agent was started without a service name. The service name will be automatically discovered.
2024-02-13 15: 01: 10.691 [Information] {"AbstractConfigurationReader (ApmConfiguration)"} The agent was started without a service name. The automatically discovered service name is "ServiceCatalog_API"
2024-02-13 15: 01: 10.691 [Information] {"AbstractConfigurationReader (ApmConfiguration)"} The agent was started without a service version. The service version will be automatically discovered.
2024-02-13 15: 01: 10.691 [Information] {"AbstractConfigurationReader (ApmConfiguration)"} The agent was started without a service version. The automatically discovered service version is "1.0.0"
2024-02-13 15: 01: 10.703 [Information] {"ConfigurationStore"} ********************************************************************************
2024-02-13 15: 01: 10.703 [Information] {"ConfigurationStore"} Elastic APM .NET Agent, version: "1.25.3+730e0f64e647bc32250d011e06ac9f080b75b487"
2024-02-13 15: 01: 10.703 [Information] {"ConfigurationStore"} Process ID: 2959194
2024-02-13 15: 01: 10.707 [Information] {"ConfigurationStore"} Process Name: "dotnet"
2024-02-13 15: 01: 10.707 [Information] {"ConfigurationStore"} Command line arguments: '"/var/www/servicecatalog_APM/ServiceCatalog.API.dll, --urls, http://0.0.0.0:8050"'
2024-02-13 15: 01: 10.708 [Information] {"ConfigurationStore"} Operating System: "Linux 5.15.0-76-generic #83~20.04.1-Ubuntu SMP Wed Jun 21 20:23:31 UTC 2023"
2024-02-13 15: 01: 10.708 [Information] {"ConfigurationStore"} CPU architecture: X64
2024-02-13 15: 01: 10.708 [Information] {"ConfigurationStore"} Host: "Service-Catalog"
2024-02-13 15: 01: 10.710 [Information] {"ConfigurationStore"} Time zone: "(UTC+02:00) Eastern European Standard Time"
2024-02-13 15: 01: 10.711 [Information] {"ConfigurationStore"} Runtime: ".NET Core 3.1.32"
2024-02-13 15: 01: 10.714 [Information] {"ConfigurationStore"} ********************************************************************************
2024-02-13 15: 01: 10.714 [Information] {"ConfigurationStore"} Agent Configuration (via '"ApmConfiguration (config provider: ConfigurationKeyValueProvider environment provider: EnvironmentKeyValueProvider)"'):
2024-02-13 15: 01: 10.728 [Information] {"ConfigurationStore"} "      Default"->"log_level": '"Error"' ("GetDefaultValueForLogging")
2024-02-13 15: 01: 10.728 [Information] {"ConfigurationStore"} "      Default"->"server_url": '"http://127.0.0.1:8200/"' ("GetDefaultValueForLogging")
2024-02-13 15: 01: 10.728 [Information] {"ConfigurationStore"} "      Default"->"service_name": '"ServiceCatalog_API"' ("GetDefaultValueForLogging")
2024-02-13 15: 01: 10.728 [Information] {"ConfigurationStore"} "      Default"->"service_version": '"1.0.0"' ("GetDefaultValueForLogging")
2024-02-13 15: 01: 10.728 [Information] {"ConfigurationStore"} ********************************************************************************
2024-02-13 15: 01: 10.730 [Information] {"Service"} Detected agent activation method: "nuget"
2024-02-13 15: 01: 10.744 [Information] {"SystemInfoHelper"} Could not parse container ID from '/proc/self/cgroup' line: "11:devices:/system.slice/sc.service"
2024-02-13 15: 01: 10.744 [Information] {"SystemInfoHelper"} Could not parse container ID from '/proc/self/cgroup' line: "10:memory:/system.slice/sc.service"
2024-02-13 15: 01: 10.744 [Information] {"SystemInfoHelper"} Could not parse container ID from '/proc/self/cgroup' line: "5:pids:/system.slice/sc.service"
2024-02-13 15: 01: 10.744 [Information] {"SystemInfoHelper"} Could not parse container ID from '/proc/self/cgroup' line: "1:name=systemd:/system.slice/sc.service"
2024-02-13 15: 01: 10.744 [Information] {"SystemInfoHelper"} Could not parse container ID from '/proc/self/cgroup' line: "0::/system.slice/sc.service"
2024-02-13 15: 01: 10.744 [Information] {"SystemInfoHelper"} Failed parsing container id - the agent will not report container id. Likely the application is not running within a container
2024-02-13 15: 01: 10.761 [Information] CreateHttpClientHandler - Setting ServerCertificateCustomValidationCallback
2024-02-13 15: 01: 10.762 [Information] CreateHttpClientHandler - SslProtocols: Tls12
2024-02-13 15: 01: 10.786 [Information] CreateHttpClientHandler - Setting ServerCertificateCustomValidationCallback
2024-02-13 15: 01: 10.787 [Information] CreateHttpClientHandler - SslProtocols: Tls12
2024-02-13 15: 01: 10.817 [Information] {"MetricsCollector"} Collecting metrics in 30000 milliseconds interval
2024-02-13 15: 01: 13.895 [Warning] {"PayloadSenderV2"} Failed reading APM server info
System.Net.Http.HttpRequestException: Connection refused
 ---> System.Net.Sockets.SocketException (111): Connection refused
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at Elastic.Apm.ServerInfo.ApmServerInfoProvider.FillApmServerInfo(IApmServerInfo apmServerInfo, IApmLogger logger, IConfiguration configuration, HttpClient httpClient, Action`2 callbackOnFinish)

Hi, @bassem_abdalftah.

We don't control the loading and binding of the configuration values and can only access those provided via the IConfiguration instance passed into UseAllElasticApm. The Microsoft extension libraries (Microsoft.Extensions.Configuration, etc.) handle the loading of the values from the various configuration sources.

It doesn't look like this release-specific file is being loaded/used. Are you 100% certain that the app is running under the Release environment? At this point, I'd recommend double-checking your application environment and configuration first.

For example, if you add another key to the appsettings.Release.json file and attempt to access it from IConfiguration in your code, does it resolve the value from the appsettings.Release.json file? I suspect it won't.

Hello Steve

after I investigate more in my configuration, I found a typo from my side was causing the error sorry and thanks for your time :smiley: