Skip to content

Commit

Permalink
Add App Name and Source + NR and App configs to Environment (#653)
Browse files Browse the repository at this point in the history
* Added ApplicationNamesSource to IConfiguration and included it in Environment payload.

* Added comment.

* Including names as well.

* Added NR Config and potential App Config file paths to Environment data.

* Spacing fix.

* Broke EnvironmentTests into framework and core versions, and added config path testing to it.

* Added 'initial' to new properties for clarity.

* CHANGELOG

* Reverting changelog change to merge.

* Changelog update.
  • Loading branch information
tehbio authored Jul 21, 2021
1 parent 45c05e0 commit 3049693
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 140 deletions.
1 change: 1 addition & 0 deletions src/Agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### New Features
* Feature [#580](https://github.com/newrelic/newrelic-dotnet-agent/issues/580): Send initial app name and source in environment data. ([#653](https://github.com/newrelic/newrelic-dotnet-agent/pull/653))
* Adds support for capturing stack traces for each instrumented method in a Transaction Trace.
* This feature is disabled by default.
* You can enable the capture of stack traces by setting either maxStackTrace to any value greater than 1. This value will only be used to determine if stack traces are captured or not despite the name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private static IConfiguration Configuration
}
}

public static string AppSettingsFilePath => _appSettingsFilePaths;

private static IConfigurationRoot InitializeConfiguration()
{
// Get application base directory, where appsettings*.json will be if they exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,59 +216,78 @@ public virtual string AgentLicenseKey
private IEnumerable<string> _applicationNames;
public virtual IEnumerable<string> ApplicationNames { get { return _applicationNames ?? (_applicationNames = GetApplicationNames()); } }

private string _applicationNamesSource;
public virtual string ApplicationNamesSource => _applicationNamesSource;

private IEnumerable<string> GetApplicationNames()
{
var runtimeAppNames = _runTimeConfiguration.ApplicationNames.ToList();
if (runtimeAppNames.Any())
{
Log.Info("Application name from SetApplicationName API.");
_applicationNamesSource = "API";

return runtimeAppNames;
}

var appName = _configurationManagerStatic.GetAppSetting("NewRelic.AppName");
if (appName != null)
{
Log.Info("Application name from web.config or app.config.");
_applicationNamesSource = "Application Config";

return appName.Split(StringSeparators.Comma);
}

appName = _environment.GetEnvironmentVariable("IISEXPRESS_SITENAME");
if (appName != null)
{
Log.Info("Application name from IISEXPRESS_SITENAME Environment Variable.");
_applicationNamesSource = "Environment Variable (IISEXPRESS_SITENAME)";

return appName.Split(StringSeparators.Comma);
}

appName = _environment.GetEnvironmentVariable("NEW_RELIC_APP_NAME");
if (appName != null)
{
Log.Info("Application name from NEW_RELIC_APP_NAME Environment Variable.");
_applicationNamesSource = "Environment Variable (NEW_RELIC_APP_NAME)";

return appName.Split(StringSeparators.Comma);
}

appName = _environment.GetEnvironmentVariable("RoleName");
if (appName != null)
{
Log.Info("Application name from RoleName Environment Variable.");
_applicationNamesSource = "Environment Variable (RoleName)";

return appName.Split(StringSeparators.Comma);
}

if (_localConfiguration.application.name.Count > 0)
{
Log.Info("Application name from newrelic.config.");
_applicationNamesSource = "NewRelic Config";

return _localConfiguration.application.name;
}

appName = GetAppPoolId();
if (!string.IsNullOrWhiteSpace(appName))
{
Log.Info("Application name from Application Pool name.");
_applicationNamesSource = "Application Pool";

return appName.Split(StringSeparators.Comma);
}

if (_httpRuntimeStatic.AppDomainAppVirtualPath == null)
{
Log.Info("Application name from process name.");
_applicationNamesSource = "Process Name";

return new List<string> { _processStatic.GetCurrentProcess().ProcessName };
}

Expand Down Expand Up @@ -1778,7 +1797,8 @@ public IDictionary<string, double> WebTransactionsApdex

#endregion Metric naming

public string NewRelicConfigFilePath { get { return _localConfiguration.ConfigurationFileName; } }
public string NewRelicConfigFilePath => _localConfiguration.ConfigurationFileName;
public string AppSettingsConfigFilePath => _configurationManagerStatic.AppSettingsFilePath;

#region Utilization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace NewRelic.Agent.Core.Configuration
{
public interface IConfigurationManagerStatic
{
string AppSettingsFilePath { get; }
string GetAppSetting(string key);
}

Expand All @@ -26,6 +27,8 @@ public ConfigurationManagerStaticMock(Func<string, string> getAppSetting = null)
_getAppSetting = getAppSetting ?? (variable => null);
}

public string AppSettingsFilePath => throw new NotImplementedException();

public string GetAppSetting(string variable)
{
return _getAppSetting(variable);
Expand All @@ -38,6 +41,21 @@ public class ConfigurationManagerStatic : IConfigurationManagerStatic
{
private bool localConfigChecksDisabled;

public string AppSettingsFilePath
{
get
{
try
{
if (!localConfigChecksDisabled)
return AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
}
catch { }

return null;
}
}

public string GetAppSetting(string key)
{
if (localConfigChecksDisabled || key == null) return null;
Expand All @@ -59,6 +77,8 @@ public class ConfigurationManagerStatic : IConfigurationManagerStatic
{
private bool localConfigChecksDisabled;

public string AppSettingsFilePath => AppSettingsConfigResolveWhenUsed.AppSettingsFilePath;

public string GetAppSetting(string key)
{
if (localConfigChecksDisabled || key == null) return null;
Expand Down
Loading

0 comments on commit 3049693

Please sign in to comment.