Skip to content
This repository was archived by the owner on Jul 5, 2020. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

## Version 2.11.0-beta1
- [Defer populating RequestTelemetry properties.](https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/1173)
- [Azure Web App for Windows Containers to use regular PerfCounter mechanism.](https://github.com/microsoft/ApplicationInsights-dotnet-server/pull/1167)
- [Support for Process CPU and Process Memory perf counters in all platforms including Linux.](https://github.com/microsoft/ApplicationInsights-dotnet-server/issues/1189)

## Version 2.10.0
- Updated Base SDK to 2.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,45 @@ public void GetCollectorReturnsXPlatformCollectorForNonWindows()
}
#endif
}

[TestMethod]
public void IsWebAppReturnsTrueOnRegularWebApp()
{
try
{
PerformanceCounterUtility.isAzureWebApp = null;
Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", "something");
Environment.SetEnvironmentVariable("WEBSITE_ISOLATION", "nothyperv");
var actual = PerformanceCounterUtility.IsWebAppRunningInAzure();
Assert.IsTrue(actual);
}
finally
{
PerformanceCounterUtility.isAzureWebApp = null;
Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", string.Empty);
Environment.SetEnvironmentVariable("WEBSITE_ISOLATION", string.Empty);
Task.Delay(1000).Wait();
}
}

[TestMethod]
public void IsWebAppReturnsFalseOnPremiumContainerWebApp()
{
try
{
PerformanceCounterUtility.isAzureWebApp = null;
Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", "something");
Environment.SetEnvironmentVariable("WEBSITE_ISOLATION", "hyperv");
var actual = PerformanceCounterUtility.IsWebAppRunningInAzure();
Assert.IsFalse(actual);
}
finally
{
PerformanceCounterUtility.isAzureWebApp = null;
Environment.SetEnvironmentVariable("WEBSITE_SITE_NAME", string.Empty);
Environment.SetEnvironmentVariable("WEBSITE_ISOLATION", string.Empty);
Task.Delay(1000).Wait();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ internal static class PerformanceCounterUtility
private const string AzureWebAppCoreSdkVersionPrefix = "azwapccore:";

private const string WebSiteEnvironmentVariable = "WEBSITE_SITE_NAME";
private const string ProcessorsCountEnvironmentVariable = "NUMBER_OF_PROCESSORS";
private const string WebSiteIsolationEnvironmentVariable = "WEBSITE_ISOLATION";
private const string WebSiteIsolationHyperV = "hyperv";

private static readonly ConcurrentDictionary<string, string> PlaceholderCache =
new ConcurrentDictionary<string, string>();
Expand Down Expand Up @@ -165,16 +166,21 @@ public static string FormatPerformanceCounter(PerformanceCounterStructure pc)
}

/// <summary>
/// Searches for the environment variable specific to Azure web applications and confirms if the current application is a web application or not.
/// Searches for the environment variable specific to Azure Web App.
/// </summary>
/// <returns>Boolean, which is true if the current application is an Azure web application.</returns>
/// <returns>Boolean, which is true if the current application is an Azure Web App.</returns>
public static bool IsWebAppRunningInAzure()
{
if (!isAzureWebApp.HasValue)
{
try
{
isAzureWebApp = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(WebSiteEnvironmentVariable));
// Presence of "WEBSITE_SITE_NAME" indicate web apps.
// "WEBSITE_ISOLATION"!="hyperv" indicate premium containers. In this case, perf counters
// can be read using regular mechanism and hence this method retuns false for
// premium containers.
isAzureWebApp = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(WebSiteEnvironmentVariable)) &&
Environment.GetEnvironmentVariable(WebSiteIsolationEnvironmentVariable) != WebSiteIsolationHyperV;
}
catch (Exception ex)
{
Expand Down