Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using APIViewWeb.Managers.Interfaces;
using APIViewWeb.Models;
using FluentAssertions;
using Microsoft.ApplicationInsights;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
Expand All @@ -27,6 +28,7 @@ public class AutoReviewControllerTests
private readonly Mock<IAutoReviewService> _mockAutoReviewService;
private readonly Mock<IConfiguration> _mockConfiguration;
private readonly List<LanguageService> _languageServices;
private readonly TelemetryClient _telemetryClient;
private readonly AutoReviewController _controller;

public AutoReviewControllerTests()
Expand All @@ -40,13 +42,15 @@ public AutoReviewControllerTests()
{
new MockLanguageService("C#", false)
};
_telemetryClient = new TelemetryClient();

_controller = new AutoReviewController(
_mockCodeFileManager.Object,
_mockApiRevisionsManager.Object,
_mockAutoReviewService.Object,
_languageServices,
_mockConfiguration.Object);
_mockConfiguration.Object,
_telemetryClient);

// Set up the HTTP context with a mock user principal
SetupControllerContext();
Expand Down
11 changes: 10 additions & 1 deletion src/dotnet/APIView/APIViewWeb/Languages/LanguageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public string RunProcess(string workingDirectory, string processName, string arg
output + Environment.NewLine +
"stderr: " + Environment.NewLine +
error + Environment.NewLine;

_telemetryClient.TrackEvent("RunProcess_Failed", new System.Collections.Generic.Dictionary<string, string>
{
{ "language", Name },
{ "processName", Path.GetFileName(processName) },
{ "exitCode", process.ExitCode.ToString() },
{ "stderrSummary", error.Length > 500 ? error.ToString().Substring(0, 500) + "..." : error.ToString() },
{ "stdoutSummary", output.Length > 500 ? output.ToString().Substring(0, 500) + "..." : output.ToString() }
});

throw new InvalidOperationException(processErrors);
}
}
Expand All @@ -98,7 +108,6 @@ public async Task<CodeFile> RunParserProcess(string originalName, string tempDir
try
{
var processErrors = RunProcess(tempDirectory, ProcessName, arguments);

_telemetryClient.TrackEvent($"Completed {Name} process run to parse " + originalName);

if (File.Exists(jsonPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using APIViewWeb.Helpers;
using APIViewWeb.LeanModels;
using APIViewWeb.Managers.Interfaces;
using Microsoft.ApplicationInsights;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -22,18 +23,21 @@ public class AutoReviewController : ControllerBase
private readonly IAutoReviewService _autoReviewService;
private readonly IEnumerable<LanguageService> _languageServices;
private readonly IConfiguration _configuration;
private readonly TelemetryClient _telemetryClient;

public AutoReviewController(ICodeFileManager codeFileManager,
IAPIRevisionsManager apiRevisionsManager,
IAutoReviewService autoReviewService,
IEnumerable<LanguageService> languageServices,
IConfiguration configuration)
IConfiguration configuration,
TelemetryClient telemetryClient)
{
_codeFileManager = codeFileManager;
_apiRevisionsManager = apiRevisionsManager;
_autoReviewService = autoReviewService;
_languageServices = languageServices;
_configuration = configuration;
_telemetryClient = telemetryClient;
}

// setReleaseTag param is set as true when request is originated from release pipeline to tag matching revision as released
Expand Down Expand Up @@ -70,6 +74,16 @@ public async Task<ActionResult> UploadAutoReview([FromForm] IFormFile file, stri
}
catch (Exception e)
{
_telemetryClient.TrackException(e, new Dictionary<string, string>
{
{ "operation", "UploadAutoReview" },
{ "fileName", file != null ? Path.GetFileName(file.FileName) : "null" },
{ "fileSize", file?.Length.ToString() ?? "0" },
{ "label", label ?? "null" },
{ "packageVersion", packageVersion ?? "null" },
{ "packageType", packageType ?? "null" }
});

return StatusCode(statusCode: StatusCodes.Status500InternalServerError, new
{
error = "Failed to create API review",
Expand All @@ -78,6 +92,7 @@ public async Task<ActionResult> UploadAutoReview([FromForm] IFormFile file, stri
});
}

_telemetryClient.TrackEvent("UploadAutoReview_NoFileProvided");
return StatusCode(statusCode: StatusCodes.Status500InternalServerError, new
{
error = "Failed to create API review. No file provided."
Expand Down Expand Up @@ -139,6 +154,19 @@ public async Task<ActionResult> CreateApiReview(
}
catch (Exception e)
{
_telemetryClient.TrackException(e, new Dictionary<string, string>
{
{ "operation", "CreateApiReview" },
{ "buildId", buildId ?? "null" },
{ "artifactName", artifactName ?? "null" },
{ "packageName", packageName ?? "null" },
{ "label", label ?? "null" },
{ "repoName", repoName ?? "null" },
{ "project", project ?? "null" },
{ "packageVersion", packageVersion ?? "null" },
{ "packageType", packageType ?? "null" }
});

return StatusCode(statusCode: StatusCodes.Status500InternalServerError, new
{
error = "Failed to create API review from DevOps artifacts",
Expand Down
Loading