Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AppDomain.CurrentDomain.BaseDirectory to get path of appsettings*.json #375

Merged
merged 4 commits into from Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/Agent/CHANGELOG.md
Expand Up @@ -10,13 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
New Feature Description

### Fixes
Fixes Issue [#224](https://github.com/newrelic/newrelic-dotnet-agent/issues/224): leading "SET" commands will be ignored when parsing compound SQL statements. ([#370](https://github.com/newrelic/newrelic-dotnet-agent/pull/370))

Fixes Issue [#226](https://github.com/newrelic/newrelic-dotnet-agent/issues/226): the profiler ignores drive letter in `HOME_EXPANDED` when detecting running in Azure Web Apps. ([#373](https://github.com/newrelic/newrelic-dotnet-agent/pull/373))

Fix Issue [#93](https://github.com/newrelic/newrelic-dotnet-agent/issues/93): when the parent methods are blocked by their asynchronous child methods, the agent deducts the child methods' duration from the parent methods' exclusive duration.([#374](https://github.com/newrelic/newrelic-dotnet-agent/pull/374))

Fixes Issue [#9](https://github.com/newrelic/newrelic-dotnet-agent/issues/9) where the agent failed to read settings from `appsettings.{environment}.json` files. ([#372](https://github.com/newrelic/newrelic-dotnet-agent/pull/372))
* Fixes Issue [#224](https://github.com/newrelic/newrelic-dotnet-agent/issues/224): leading "SET" commands will be ignored when parsing compound SQL statements. ([#370](https://github.com/newrelic/newrelic-dotnet-agent/pull/370))
* Fixes Issue [#226](https://github.com/newrelic/newrelic-dotnet-agent/issues/226): the profiler ignores drive letter in `HOME_EXPANDED` when detecting running in Azure Web Apps. ([#373](https://github.com/newrelic/newrelic-dotnet-agent/pull/373))
* Fixes Issue [#93](https://github.com/newrelic/newrelic-dotnet-agent/issues/93): when the parent methods are blocked by their asynchronous child methods, the agent deducts the child methods' duration from the parent methods' exclusive duration.([#374](https://github.com/newrelic/newrelic-dotnet-agent/pull/374))
* Fixes Issue [#9](https://github.com/newrelic/newrelic-dotnet-agent/issues/9) where the agent failed to read settings from `appsettings.{environment}.json` files. ([#372](https://github.com/newrelic/newrelic-dotnet-agent/pull/372))
* Fixes Issue [#116](https://github.com/newrelic/newrelic-dotnet-agent/issues/116) where the agent failed to read settings from `appsettings.json` in certain hosting scenarios. ([#375](https://github.com/newrelic/newrelic-dotnet-agent/pull/375))


## [8.35] - 2020-11-09
Expand All @@ -26,8 +24,8 @@ Fixes Issue [#9](https://github.com/newrelic/newrelic-dotnet-agent/issues/9) whe
We have validated that this version of the agent is compatible with .NET 5 GA. See the [compatibility and requirements for .NET Core](https://docs.newrelic.com/docs/agents/net-agent/getting-started/net-agent-compatibility-requirements-net-core) page for more details.

### Fixes
Fixes Issue [#337](https://github.com/newrelic/newrelic-dotnet-agent/issues/337) by removing obsolete code which was causing memory growth associated with a large number of transaction names.
PR [#348](https://github.com/newrelic/newrelic-dotnet-agent/pull/348): guards against potential exceptions being thrown from the agent API when the agent is not attached.
* Fixes Issue [#337](https://github.com/newrelic/newrelic-dotnet-agent/issues/337) by removing obsolete code which was causing memory growth associated with a large number of transaction names.
* PR [#348](https://github.com/newrelic/newrelic-dotnet-agent/pull/348): guards against potential exceptions being thrown from the agent API when the agent is not attached.

## [8.34] - 2020-10-26

Expand Down
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

#if NETSTANDARD2_0
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using NewRelic.Core.Logging;
Expand All @@ -23,25 +24,37 @@ private static IConfiguration Configuration

private static IConfigurationRoot InitializeConfiguration()
{
// Get application base directory, where appsettings*.json will be if they exist
var applicationDirectory = string.Empty;
try
{
applicationDirectory = AppDomain.CurrentDomain.BaseDirectory;
}
catch (AppDomainUnloadedException)
{
// Fall back to previous behavior of agents <=8.35.0
applicationDirectory = Directory.GetCurrentDirectory();
}

var builder = new ConfigurationBuilder()
.SetBasePath(applicationDirectory)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

// Determine if there might be an environment-specific appsettings file
var env = new SystemInterfaces.Environment();
var currentDirectory = Directory.GetCurrentDirectory();
var environment = env.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code org nit: Can we move var env declaration to right before where it is used on line 38?
Similarly, Can we move the block that sets/checks var environment to right before it is used on line 48?

if (string.IsNullOrEmpty(environment))
{
environment = env.GetEnvironmentVariable("EnvironmentName");
}

var builder = new ConfigurationBuilder()
.SetBasePath(currentDirectory)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);

if (!string.IsNullOrEmpty(environment))
{
builder.AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: false);
}

var appSettingsPath = Path.Combine(currentDirectory, "appsettings.json");
var appSettingsEnvPath = Path.Combine(currentDirectory, $"appsettings.{environment}.json");
var appSettingsPath = Path.Combine(applicationDirectory, "appsettings.json");
var appSettingsEnvPath = Path.Combine(applicationDirectory, $"appsettings.{environment}.json");
_appSettingsFilePaths = !string.IsNullOrEmpty(environment) ? string.Join(", ", appSettingsPath, appSettingsEnvPath) : appSettingsPath;

return builder.Build();
Expand Down