aws / aws-xray-dotnet-agent

The official AWS X-Ray Auto Instrumentation Agent for .Net.
Apache License 2.0
23 stars 15 forks source link

Unable to override settings depending in the environment #29

Open TMiNus opened 3 years ago

TMiNus commented 3 years ago

Due to this piece of code

 IConfiguration configuration = null;
 try
 {
      // Get the json file
     configuration = new ConfigurationBuilder()
                             .SetBasePath(Directory.GetCurrentDirectory())
                             .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                             .Build();
 }
 catch (Exception e)
 {
     _logger.Error(e, "Can't fetch configuration from appsettings.json file.");
 }

The configuration settings below are not properly applied in localhost

appsettings.json ```json "XRay": { "DisableXRayTracing": "false", "UseRuntimeErrors": "true", "CollectSqlQueries": "false", "DaemonAddress": "127.0.0.1:2000", "ServiceName": "defaultService", "TraceHttpRequests": "true", "TraceAWSRequests": "true", "TraceSqlRequests": "true", "TraceEFRequests": "true" } ```
appsettings.Localhost.json ```json "XRay": { "DisableXRayTracing": "true", "UseRuntimeErrors": "true", "CollectSqlQueries": "false", "DaemonAddress": "127.0.0.1:3000", "ServiceName": "defaultService", "TraceHttpRequests": "false", "TraceAWSRequests": "false", "TraceSqlRequests": "false", "TraceEFRequests": "false" } ```

I wonder what is the rationale behind loading appsettings.json directly instead of receiving IConfiguration in the Register method

lupengamzn commented 3 years ago

Hey @TMiNus ,

Thanks for bringing this up and we'll be adding the support for parsing custom appsettings.json configuration files.

You may append AddJsonFile("appsettings.Localhost.json", optional: true, reloadOnChange: true) to the ConfigurationBuilder as a workaround if you would like to override the settings from appsettings.Localhost.json.

TMiNus commented 3 years ago

Hey @lupengamzn,

Thanks for answering. I am looking forward to the changes.

For the time being I have added an option to inject IConfiguration into that class, I haven't encountered issues so far with that workaround.