Skip to content

Commit

Permalink
Fix/improve CloudWatch logging
Browse files Browse the repository at this point in the history
- Fix broken filtering.
- Log the request IDs.
- Log the wait.
- Log how many log events found.
  • Loading branch information
martincostello committed Dec 1, 2023
1 parent 3314b76 commit e02a329
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions test/LondonTravel.Skill.EndToEndTests/CloudWatchLogsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@ public async Task DisposeAsync()
regionName is not null &&
credentials is not null)
{
await Task.Delay(TimeSpan.FromSeconds(10));
var builder = new StringBuilder()
.AppendLine()
.AppendLine()
.AppendLine(CultureInfo.InvariantCulture, $"AWS Request ID(s) (Count = {RequestIds.Count}):")
.AppendLine();

foreach (var requestId in RequestIds)
{
builder.AppendLine(CultureInfo.InvariantCulture, $" - {requestId}");
}

diagnosticMessageSink.OnMessage(new DiagnosticMessage(builder.ToString()));

var delay = TimeSpan.FromSeconds(10);

diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Waiting {delay.Seconds} seconds for CloudWatch logs..."));
await Task.Delay(delay);

string logGroupName = $"/aws/lambda/{functionName}";
var region = RegionEndpoint.GetBySystemName(regionName);
Expand Down Expand Up @@ -63,14 +79,16 @@ regionName is not null &&
foreach (var @event in reports)
{
string[] split = @event.Message.Split('\t', StringSplitOptions.RemoveEmptyEntries);
string requestId = split[0][ReportPrefix.Length..];
string requestIdLine = split[0][ReportPrefix.Length..];
string requestId = requestIdLine.Split(' ')[1];

var builder = new StringBuilder()
builder
.Clear()
.AppendLine()
.AppendLine()
.AppendFormat(CultureInfo.InvariantCulture, $"Timestamp: {@event.Timestamp:u}")
.AppendLine()
.AppendLine(requestId);
.AppendLine(requestIdLine);

foreach (string value in split.Skip(1))
{
Expand All @@ -89,6 +107,8 @@ regionName is not null &&
.OrderBy((p) => p.Timestamp)
.ToList();

diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Found {events.Count} CloudWatch log events."));

foreach (var (_, _, message) in events)
{
diagnosticMessageSink.OnMessage(new DiagnosticMessage(message));
Expand Down

0 comments on commit e02a329

Please sign in to comment.