Skip to content

Commit

Permalink
set _dd.test.is_user_provided_service for all spans if user has confi…
Browse files Browse the repository at this point in the history
…gured test_service
  • Loading branch information
anmarchenko committed Dec 16, 2024
1 parent 7d4a076 commit a2c6aeb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/datadog/ci/test_visibility/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_relative "../ext/environment"
require_relative "../ext/test"

require_relative "../utils/configuration"
require_relative "../utils/test_run"

require_relative "../span"
Expand Down Expand Up @@ -207,6 +208,10 @@ def set_initial_tags(ci_span, tags)
ci_span.set_tags(@environment_tags)

ci_span.set_metric(Ext::Test::METRIC_CPU_COUNT, Utils::TestRun.virtual_cpu_count)
ci_span.set_tag(
Ext::Test::TAG_USER_PROVIDED_TEST_SERVICE,
Utils::Configuration.service_name_provided_by_user?.to_s
)
end

# PROPAGATING CONTEXT FROM TOP-LEVEL TO THE LOWER LEVELS
Expand Down
21 changes: 18 additions & 3 deletions spec/datadog/ci/contrib/minitest/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ def test_foo

expect(span.service).to eq("datadog-ci-rb")
end

it "sets user_provided_service tag to false" do
klass = Class.new(Minitest::Test) do
def test_foo
end
end

klass.new(:test_foo).run

expect(span).to have_test_tag(:user_provided_test_service, "false")
end
end

context "with service name configured and code coverage enabled" do
include_context "CI mode activated" do
let(:service_name) { "ltest" }
let(:integration_name) { :minitest }
let(:integration_options) { {service_name: "ltest"} }

Expand Down Expand Up @@ -88,11 +100,14 @@ def test_foo
:source_file,
"spec/datadog/ci/contrib/minitest/instrumentation_spec.rb"
)
expect(span).to have_test_tag(:source_start, "61")
expect(span).to have_test_tag(:source_start, "73")
expect(span).to have_test_tag(
:codeowners,
"[\"@DataDog/ruby-guild\", \"@DataDog/ci-app-libraries\"]"
)

# test service is provided by user in the configuration
expect(span).to have_test_tag(:user_provided_test_service, "true")
end

it "creates spans for several tests" do
Expand Down Expand Up @@ -455,7 +470,7 @@ def test_pass_other

expect(test_session_span).to have_pass_status

# test_session metric has auto_injected false
# test_session telemetry metric has auto_injected false
test_session_started_metric = telemetry_metric(:inc, "test_session")
expect(test_session_started_metric.tags["auto_injected"]).to eq("false")
end
Expand Down Expand Up @@ -492,7 +507,7 @@ def test_pass_other
:source_file,
"spec/datadog/ci/contrib/minitest/instrumentation_spec.rb"
)
expect(first_test_suite_span).to have_test_tag(:source_start, "419")
expect(first_test_suite_span).to have_test_tag(:source_start, "434")
expect(first_test_suite_span).to have_test_tag(
:codeowners,
"[\"@DataDog/ruby-guild\", \"@DataDog/ci-app-libraries\"]"
Expand Down
5 changes: 5 additions & 0 deletions spec/support/contexts/ci_mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
RSpec.shared_context "CI mode activated" do
include CoverageHelpers

let(:service_name) { nil }
let(:test_command) { "command" }
let(:logical_test_session_name) { nil }
let(:integration_name) { :no_instrument }
Expand Down Expand Up @@ -109,6 +110,10 @@
allow_any_instance_of(Datadog::CI::TestRetries::UniqueTestsClient).to receive(:fetch_unique_tests).and_return(unique_tests_set)

Datadog.configure do |c|
if service_name
c.service = service_name
end

# library switch
c.ci.enabled = ci_enabled

Expand Down

0 comments on commit a2c6aeb

Please sign in to comment.