Skip to content

Commit

Permalink
Link to traces
Browse files Browse the repository at this point in the history
Link to AWS traces in PR comments, where available.
  • Loading branch information
martincostello committed Jan 24, 2024
1 parent 5e5cd98 commit ec94ae3
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions test/LondonTravel.Skill.EndToEndTests/CloudWatchLogsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ regionName is not null &&
case "Init Duration":
entry.InitDuration = parts[1];
break;

case "XRAY TraceId":
entry.TraceId = parts[1];
break;
}
}
}
Expand Down Expand Up @@ -166,6 +170,7 @@ regionName is not null &&
private static async Task TryPostLogsToPullRequestAsync(IEnumerable<LogEvent> events)
{
string? apiUrl = Environment.GetEnvironmentVariable("GITHUB_API_URL");
string? awsRegion = Environment.GetEnvironmentVariable("AWS_REGION");
string? repository = Environment.GetEnvironmentVariable("GITHUB_REPOSITORY");
string? token = Environment.GetEnvironmentVariable("GITHUB_TOKEN");
string? issue = Environment.GetEnvironmentVariable("PULL_NUMBER");
Expand All @@ -180,8 +185,8 @@ private static async Task TryPostLogsToPullRequestAsync(IEnumerable<LogEvent> ev
}

var comment = new StringBuilder()
.AppendLine("| **Payload** | **Duration** | **Billed Duration** | **Memory Size** | **Max Memory Used** | **Init Duration** |")
.AppendLine("|:------------|-------------:|--------------------:|----------------:|--------------------:|------------------:|");
.AppendLine("| **Payload** | **Duration** | **Billed Duration** | **Memory Size** | **Max Memory Used** | **Init Duration** | **Trace** |")
.AppendLine("|:------------|-------------:|--------------------:|----------------:|--------------------:|------------------:|:----------|");

foreach (var entry in events)
{
Expand All @@ -192,6 +197,7 @@ private static async Task TryPostLogsToPullRequestAsync(IEnumerable<LogEvent> ev
.Append(CultureInfo.InvariantCulture, $" | {entry.MemorySize}")
.Append(CultureInfo.InvariantCulture, $" | {entry.MaxMemoryUsed}")
.Append(CultureInfo.InvariantCulture, $" | {entry.InitDuration ?? "-"}")
.Append(CultureInfo.InvariantCulture, $" | {TraceUrl(entry.TraceId, awsRegion)}")
.AppendLine(" |");
}

Expand All @@ -213,6 +219,16 @@ private static async Task TryPostLogsToPullRequestAsync(IEnumerable<LogEvent> ev
new { body = comment.ToString() });

response.EnsureSuccessStatusCode();

static string TraceUrl(string? traceId, string? region)
{
if (string.IsNullOrEmpty(traceId))
{
return "-";
}

return $"[:link:](https://{region}.console.aws.amazon.com/cloudwatch/home?region={region}#xray:traces/{traceId})";
}
}

private sealed class LogEvent(string name)
Expand All @@ -231,6 +247,8 @@ private sealed class LogEvent(string name)

public string MaxMemoryUsed { get; set; } = default!;

public string InitDuration { get; set; } = default!;
public string? InitDuration { get; set; }

public string? TraceId { get; set; }
}
}

0 comments on commit ec94ae3

Please sign in to comment.