Skip to content

Commit

Permalink
[CI Visibility] Catch UploadRepositoryChanges exceptions (#6331)
Browse files Browse the repository at this point in the history
## Summary of changes

This PR adds some missing try/catch for the UploadRepositoryChanges
calls.

## Reason for change

This method is being used in the `dd-trace` runner, currently if the
method fails (backend error) then `dd-trace` will throw an exception.

## Implementation details

We create a function method to wrap the call with a try/catch block so
we don't throw and fail the customer CI.

## Test coverage

## Other details
<!-- Fixes #{issue} -->

<!-- ⚠️ Note: where possible, please obtain 2 approvals prior to
merging. Unless CODEOWNERS specifies otherwise, for external teams it is
typically best to have one review from a team member, and one review
from apm-dotnet. Trivial changes do not require 2 reviews. -->
  • Loading branch information
tonyredondo authored Nov 21, 2024
1 parent 3a7d042 commit 3b655e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 13 additions & 1 deletion tracer/src/Datadog.Trace.Tools.Runner/CiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,19 @@ public static async Task<InitResults> InitializeCiCommandsAsync(
if (ciVisibilitySettings.GitUploadEnabled != false || ciVisibilitySettings.IntelligentTestRunnerEnabled)
{
// If we are in git upload only then we can defer the await until the child command exits.
uploadRepositoryChangesTask = Task.Run(() => lazyItrClient.Value.UploadRepositoryChangesAsync());
async Task UploadRepositoryChangesAsync()
{
try
{
await lazyItrClient.Value.UploadRepositoryChangesAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
Log.Error(ex, "RunCiCommand: Error uploading repository git metadata.");
}
}

uploadRepositoryChangesTask = Task.Run(UploadRepositoryChangesAsync);

// Once the repository has been uploaded we switch off the git upload in children processes
profilerEnvironmentVariables[Configuration.ConfigurationKeys.CIVisibility.GitUploadEnabled] = "0";
Expand Down
16 changes: 14 additions & 2 deletions tracer/src/Datadog.Trace/Ci/CIVisibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,23 @@ private static async Task GetIntelligentTestRunnerSkippableTestsAsync()
var settings = Settings;
var lazyItrClient = new Lazy<IntelligentTestRunnerClient>(() => new(CIEnvironmentValues.Instance.WorkspacePath, settings));

Task<long>? uploadRepositoryChangesTask = null;
Task? uploadRepositoryChangesTask = null;
if (settings.GitUploadEnabled != false)
{
// Upload the git metadata
uploadRepositoryChangesTask = Task.Run(() => lazyItrClient.Value.UploadRepositoryChangesAsync());
async Task UploadRepositoryChangesAsync()
{
try
{
await lazyItrClient.Value.UploadRepositoryChangesAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
Log.Error(ex, "CIVisibility: Error uploading repository git metadata.");
}
}

uploadRepositoryChangesTask = Task.Run(UploadRepositoryChangesAsync);
}

// If any DD_CIVISIBILITY_CODE_COVERAGE_ENABLED or DD_CIVISIBILITY_TESTSSKIPPING_ENABLED has not been set
Expand Down

0 comments on commit 3b655e1

Please sign in to comment.