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

Azure functions: Unit tests #2726

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -2152,11 +2152,18 @@ public string AzureFunctionResourceId
return string.Empty;
}

return $"/subscriptions/{subscriptionId}/resourceGroups/{websiteResourceGroup}/providers/Microsoft.Web/sites/{AzureFunctionServiceName}";
return $"/subscriptions/{subscriptionId}/resourceGroups/{websiteResourceGroup}/providers/Microsoft.Web/sites/{(string.IsNullOrEmpty(AzureFunctionServiceName) ? "unknown" : AzureFunctionServiceName)}";
}
}

public string AzureFunctionResourceIdWithFunctionName(string functionName) => $"{AzureFunctionResourceId}/functions/{functionName}";
public string AzureFunctionResourceIdWithFunctionName(string functionName)
{
if (string.IsNullOrEmpty(AzureFunctionResourceId) || string.IsNullOrEmpty(functionName))
{
return string.Empty;
}

return $"{AzureFunctionResourceId}/functions/{functionName}"; }

public string AzureFunctionResourceGroupName
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ExtensionsLoader
/// </summary>
private static string[] _autoReflectedAssemblies;

[NrExcludeFromCodeCoverage]
public static void Initialize(string installPathExtensionsDirectory)
{
_installPathExtensionsDirectory = installPathExtensionsDirectory;
Expand Down
875 changes: 465 additions & 410 deletions src/Agent/NewRelic/Profiler/ConfigurationTest/ConfigurationTest.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Agent/NewRelic/Profiler/Logging/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace NewRelic {

// Console logging at debug or trace level incurs a very large
// performance hit. Clamp the log level to INFO in that case.
// TODO: In Azure function mode, TRACE level debugging causes a crash that we haven't identified yet, so limit to INFO or higher for now
// In Azure function mode, TRACE level debugging causes a crash, so limit to INFO or higher for now
return (_level < Level::LEVEL_INFO) ? Level::LEVEL_INFO : _level;
}

Expand Down
21 changes: 21 additions & 0 deletions src/Agent/NewRelic/Profiler/LoggingTest/LoggerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ namespace NewRelic {
Assert::AreEqual(Level::LEVEL_INFO, priorLevel);
}

TEST_METHOD(logger_azure_function_limited_to_info_level)
{
ResetStdLog();
StdLog.SetAzureFunctionMode(true);

LogError(L"error message here");
LogWarn(L"warning message here");
LogInfo(L"info message here");
LogDebug(L"debug message here");
LogTrace(L"trace message here");

AssertMessageCount(3); // debug and trace shouldn't be logged
auto messages = GetMessages();
// verify there are no debug or trace messages
for (auto message : messages)
{
Assert::IsFalse(Strings::Contains(message, L"debug"));
Assert::IsFalse(Strings::Contains(message, L"trace"));
}
}

TEST_METHOD(logger_test_stream_logger)
{
ResetStdLog();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ public void RootSpanEventHasTransactionsUserAndAgentAttributes([Values(true,fals

_attribDefs.GetCustomAttributeForTransaction("trxCustomAttrib").TrySetValue(allAttribValues, "trxCustomAttribValue");
_attribDefs.GetLambdaAttribute("lambdaAttributeKey").TrySetValue(allAttribValues, "lambdaAttributeValue");
_attribDefs.GetFaasAttribute("faasAttributeKey").TrySetValue(allAttribValues, "faasAttributeValue");
_attribDefs.OriginalUrl.TrySetValue(allAttribValues, "http://www.test.com");

// ACT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,4 +537,36 @@ public void AddLambdaAttribute_DoesNotSetAttribute_WhenKeyIsBad(string key)
// Assert
Assert.That(_transaction.TransactionMetadata.UserAndRequestAttributes.Count, Is.EqualTo(0));
}

[Test]
public void AddFaasAttribute_SetAttributeInTransactionMetadata()
{
// Arrange
var key = "TestAttribute";
var value = "TestValue";

// Act
_transaction.AddFaasAttribute(key, value);

// Assert
var allAttributeValuesDic = _transaction.TransactionMetadata.UserAndRequestAttributes.GetAllAttributeValuesDic();

var attributeValue = allAttributeValuesDic[key];
Assert.That(attributeValue, Is.EqualTo(value));
}

[TestCase(" ")]
[TestCase("")]
[TestCase(null)]
public void AddFaasAttribute_DoesNotSetAttribute_WhenKeyIsBad(string key)
{
// Arrange
var value = "TestValue";

// Act
_transaction.AddFaasAttribute(key, value);

// Assert
Assert.That(_transaction.TransactionMetadata.UserAndRequestAttributes.Count, Is.EqualTo(0));
}
}
Loading