My application is running in test environment. I see that it throws apm logs, but it does not work in production environment. I think the reason is from the configuration in appsettings.json by default, briefly as follows:
var environmentName = Environment.GetEnvironmentVariable('ASPNETCORE_ENVIRONMENT');
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
.AddJsonFile('appsettings.json', false)
.AddJsonFile($'appsettings.{environmentName}.json', true)
.AddEnvironmentVariables();
UseElasticApm(new HttpDiagnosticsSubscriber());
I have 2 different configuration files according to the environment information in which the configuration is active. However, APM seems to be searching for the appsettings.json file by default.
When I check the logs, I see errors like the following.
Elastic.Apm[0] {CentralConfigFetcher} Exception was thrown while fetching configuration from APM Server and parsing it. ETag: <null>'. URL: http://localhost:8200/config/v1/agents?
Elastic.Apm[0] {PayloadSenderV2} Failed sending events. Following events were not transferred successfully to the server (http://localhost:8200/):
By the way, the application is a console application.
This log only means that the agent wasn't able to fetch configs from APM server - maybe central config is just disabled:
Elastic.Apm[0] {CentralConfigFetcher} Exception was thrown while fetching configuration from APM Server and parsing it. ETag: <null>'. URL:
So that's fine.
This second one (below) is a real problem and it means the agent wasn't able to send the data to the APM Server - further parts of the log should have more info:
Elastic.Apm[0] {PayloadSenderV2} Failed sending events. Following events were not transferred successfully to the server (http://localhost:8200/):
Now to the appsettings.json and IConfiguration part: I assume you use the Elastic.Apm.Extensions.Hosting package, right?
In that case the agent will just use the IConfiguration that you configure on the IServiceProvider - you have this var builder = new ConfigurationBuilder(), but then nothing happens with the builder you create - is that the full code?
Now the error has changed, it says that it sent successfully, but it is trying to send metrics to APM running in the test environment.
Elastic.Apm[0] {PayloadSenderV2} Failed sending events. Following events were not transferred successfully to the server (http://xxx.xx.x.xx:8200/)
So my application is now trying to send it to a real ip and not localhost: 8200, so I see that the config file is working, but it configures according to the information in the fixed appsettings.json file, not the environment information.
Ok, I see. The code itself looks ok to me, the agent should pick up the ConfigurationBuilder you configure in ConfigureServices.
You say
but it configures according to the information in the fixed appsettings.json file, not the environment information.
What's exactly the goal here? Where do you want to read the values from? You configure the 2 .json files, plus the environment variable. Where do you expect the value coming from? And could you show me the content of those files or show me the environment variable? One thing to keep in mind here (and I admit this can be confusing) is that if you set environment variables in this case, then you'll need to follow the IConfiguration format - so e.g. for configuring the server url, you need to set the environment variable ElasticApm:ServerUrl in this case (and not ELASTIC_APM_SERVER_URL).
Another small nit: you have this at the end of the code snippet: services.AddSingleton<ITracer, Tracer>(); - if that's the Elastic.Apm.ITracerer then you can remove it, the .UseElasticApm adds it for you.
I am installing my application in the production environment. The environment information is writing to the screen as "Production". All other external applications (Solr, MassTransit etc.) configure according to the information in appsettings.Production.json, but APM tries to go to the address in appsettings.json.
In the production environment, when I look at the APM logs, I see this.
Elastic.Apm[0] {PayloadSenderV2} Failed sending events. Following events were not transferred successfully to the server (http://xxx.xx.x.xx:8200/):
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.