Skip to content

Commit

Permalink
More logging improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chynesNR committed Nov 25, 2024
1 parent 00d2251 commit f229fc1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class ArnBuilder

public ArnBuilder(string partition, string region, string accountId)
{
Partition = partition;
Region = region;
AccountId = accountId;
Partition = partition ?? "";
Region = region ?? "";
AccountId = accountId ?? "";
}

public string Build(string service, string resource) => ConstructArn(Partition, service, Region, AccountId, resource);
Expand Down Expand Up @@ -133,6 +133,15 @@ public string BuildFromPartialLambdaArn(string invocationName)
return ConstructArn(Partition, "lambda", region, accountId, $"function:{functionName}");
}

public override string ToString()
{
string partition = string.IsNullOrEmpty(Partition) ? "[Missing]" : Partition;
string region = string.IsNullOrEmpty(Region) ? "[Missing]" : Region;
string accountId = string.IsNullOrEmpty(AccountId) ? "[Missing]" : "[Present]";

return $"Partition: {partition}, Region: {region}, AccountId: {accountId}";
}

private static Regex RegionRegex = new Regex(@"^[a-z]{2}((-gov)|(-iso([a-z]?)))?-[a-z]+-\d{1}$", RegexOptions.Compiled);
private static bool LooksLikeARegion(string text) => RegionRegex.IsMatch(text);
private static bool LooksLikeAnAccountId(string text) => (text.Length == 12) && text.All(c => c >= '0' && c <= '9');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public CanWrapResponse CanWrap(InstrumentedMethodInfo methodInfo)

private ArnBuilder CreateArnBuilder(IAgent agent, dynamic requestContext)
{
string partition = "";
string systemName = "";
string accountId = "";
string partition = null;
string systemName = null;
string accountId = null;
try
{
accountId = GetAccountId(agent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static AfterWrappedMethodDelegate HandleInvokeRequest(InstrumentedMethodC
}
else if (_reportBadInvocationName)
{
agent.Logger.Debug($"Unable to parse lambda invocation named '{functionName}''");
agent.Logger.Debug($"Unable to resolve Lambda invocation named '{functionName}' [{builder.ToString()}]");
_reportBadInvocationName = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,17 @@ public void ConstructGenericArn(string partition, string service, string region,
var constructedArn = arnBuilder.Build(service, resource);
Assert.That(constructedArn, Is.EqualTo(expectedArn), "Did not get expected ARN");
}

[Test]
[TestCase("aws", "us-west-2", "123456789012", "Partition: aws, Region: us-west-2, AccountId: [Present]")]
[TestCase("aws", "", "123456789012", "Partition: aws, Region: [Missing], AccountId: [Present]")]
[TestCase("aws", "us-west-2", "", "Partition: aws, Region: us-west-2, AccountId: [Missing]")]
[TestCase("aws", "us-west-2", null, "Partition: aws, Region: us-west-2, AccountId: [Missing]")]
[TestCase("", "", "", "Partition: [Missing], Region: [Missing], AccountId: [Missing]")]
public void ArnBuilderToString(string partition, string region, string accountId, string expected)
{
var arnBuilder = new ArnBuilder(partition, region, accountId);
Assert.That(arnBuilder.ToString(), Is.EqualTo(expected), "Did not get expected string");
}
}
}

0 comments on commit f229fc1

Please sign in to comment.