Skip to content

Commit

Permalink
[CI Visibility] Specify if the user is setting the DD_SERVICE (#6348)
Browse files Browse the repository at this point in the history
## Summary of changes

This PR sets a tag to let the ci visibility backend know if the
DD_SERVICE value was provided by the user or auto-generated.

## Reason for change

This required by the backend.

## Test coverage

- Updated snapshots.
- Fixed tests

## 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 and veerbia committed Dec 16, 2024
1 parent d6e8ba1 commit 694ab16
Show file tree
Hide file tree
Showing 27 changed files with 3,078 additions and 1,523 deletions.
11 changes: 11 additions & 0 deletions tracer/src/Datadog.Trace/Ci/CIVisibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Datadog.Trace.Agent.Transports;
using Datadog.Trace.Ci.CiEnvironment;
using Datadog.Trace.Ci.Configuration;
using Datadog.Trace.Ci.Tags;
using Datadog.Trace.Configuration;
using Datadog.Trace.HttpOverStreams;
using Datadog.Trace.Logging;
Expand Down Expand Up @@ -134,6 +135,11 @@ public static void Initialize()
{
// Extract repository name from the git url and use it as a default service name.
tracerSettings.ServiceNameInternal = GetServiceNameFromRepository(CIEnvironmentValues.Instance.Repository);
tracerSettings.GlobalTagsInternal[CommonTags.UserProvidedTestServiceTag] = "false";
}
else
{
tracerSettings.GlobalTagsInternal[CommonTags.UserProvidedTestServiceTag] = "true";
}

// Normalize the service name
Expand Down Expand Up @@ -203,6 +209,11 @@ internal static void InitializeFromRunner(CIVisibilitySettings settings, IDiscov
{
// Extract repository name from the git url and use it as a default service name.
tracerSettings.ServiceNameInternal = GetServiceNameFromRepository(CIEnvironmentValues.Instance.Repository);
tracerSettings.GlobalTagsInternal[CommonTags.UserProvidedTestServiceTag] = "false";
}
else
{
tracerSettings.GlobalTagsInternal[CommonTags.UserProvidedTestServiceTag] = "true";
}

// Normalize the service name
Expand Down
5 changes: 5 additions & 0 deletions tracer/src/Datadog.Trace/Ci/Tags/CommonTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,9 @@ internal static class CommonTags
/// GIT PR Base branch name
/// </summary>
public const string GitPrBaseBranch = "git.pull_request.base_branch";

/// <summary>
/// Defines if the service is a user provided test service
/// </summary>
public const string UserProvidedTestServiceTag = "_dd.test.is_user_provided_service";
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ await Verifier.Verify(
targetTest.Meta.Remove(EarlyFlakeDetectionTags.TestIsNew);
targetTest.Meta.Remove(EarlyFlakeDetectionTags.TestIsRetry);

// Remove user provided service tag
targetTest.Meta.Remove(CommonTags.UserProvidedTestServiceTag);

// check the name
Assert.Equal("mstestv2.test", targetTest.Name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public async Task SubmitTraces(string packageVersion)
targetSpan.Tags.Remove(EarlyFlakeDetectionTags.TestIsNew);
targetSpan.Tags.Remove(EarlyFlakeDetectionTags.TestIsRetry);

// Remove user provided service tag
targetSpan.Tags.Remove(CommonTags.UserProvidedTestServiceTag);

// check the name
Assert.Equal("mstestv2.test", targetSpan.Name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ public async Task SubmitTraces(string packageVersion, string evpVersionToRemove,
targetTest.Meta.Remove(EarlyFlakeDetectionTags.TestIsNew);
targetTest.Meta.Remove(EarlyFlakeDetectionTags.TestIsRetry);

// Remove user provided service tag
targetTest.Meta.Remove(CommonTags.UserProvidedTestServiceTag);

// check the name
Assert.Equal("nunit.test", targetTest.Name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public async Task SubmitTraces(string packageVersion)
targetSpan.Tags.Remove(EarlyFlakeDetectionTags.TestIsNew);
targetSpan.Tags.Remove(EarlyFlakeDetectionTags.TestIsRetry);

// Remove user provided service tag
targetSpan.Tags.Remove(CommonTags.UserProvidedTestServiceTag);

// check the name
targetSpan.Name.Should().Be("nunit.test");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ public virtual async Task SubmitTraces(string packageVersion, string evpVersionT
targetTest.Meta.Remove(EarlyFlakeDetectionTags.TestIsNew);
targetTest.Meta.Remove(EarlyFlakeDetectionTags.TestIsRetry);

// Remove user provided service tag
targetTest.Meta.Remove(CommonTags.UserProvidedTestServiceTag);

// check the name
Assert.Equal("xunit.test", targetTest.Name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public virtual async Task SubmitTraces(string packageVersion)
targetSpan.Tags.Remove(EarlyFlakeDetectionTags.TestIsNew);
targetSpan.Tags.Remove(EarlyFlakeDetectionTags.TestIsRetry);

// Remove user provided service tag
targetSpan.Tags.Remove(CommonTags.UserProvidedTestServiceTag);

// check the name
Assert.Equal("xunit.test", targetSpan.Name);

Expand Down
Loading

0 comments on commit 694ab16

Please sign in to comment.