diff --git a/lib/datadog/ci.rb b/lib/datadog/ci.rb index 4912cda8..9893cc88 100644 --- a/lib/datadog/ci.rb +++ b/lib/datadog/ci.rb @@ -10,10 +10,18 @@ module Datadog # @public_api module CI class << self + # Trace a test run + # @public_api def trace_test(test_name, service_name: nil, operation_name: "test", tags: {}, &block) recorder.trace_test(test_name, service_name: service_name, operation_name: operation_name, tags: tags, &block) end + # Start a test run trace. + # @public_api + def start_test(test_name, service_name: nil, operation_name: "test", tags: {}) + recorder.trace_test(test_name, service_name: service_name, operation_name: operation_name, tags: tags) + end + def trace(span_type, span_name, tags: {}, &block) recorder.trace(span_type, span_name, tags: tags, &block) end diff --git a/lib/datadog/ci/contrib/cucumber/formatter.rb b/lib/datadog/ci/contrib/cucumber/formatter.rb index 01d0b5ba..634de76b 100644 --- a/lib/datadog/ci/contrib/cucumber/formatter.rb +++ b/lib/datadog/ci/contrib/cucumber/formatter.rb @@ -28,7 +28,7 @@ def bind_events(config) end def on_test_case_started(event) - @current_feature_span = CI.trace_test( + @current_feature_span = CI.start_test( event.test_case.name, tags: { CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK, diff --git a/lib/datadog/ci/contrib/minitest/hooks.rb b/lib/datadog/ci/contrib/minitest/hooks.rb index 0ec5be15..a49ef648 100644 --- a/lib/datadog/ci/contrib/minitest/hooks.rb +++ b/lib/datadog/ci/contrib/minitest/hooks.rb @@ -19,7 +19,7 @@ def before_setup path, = method(name).source_location test_suite = Pathname.new(path.to_s).relative_path_from(Pathname.pwd).to_s - test_span = CI.trace_test( + test_span = CI.start_test( test_name, tags: { CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK, diff --git a/sig/datadog/ci.rbs b/sig/datadog/ci.rbs index 18f8f592..560eea99 100644 --- a/sig/datadog/ci.rbs +++ b/sig/datadog/ci.rbs @@ -2,6 +2,8 @@ module Datadog module CI def self.trace_test: (String span_name, ?service_name: String?, ?operation_name: String, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped + def self.start_test: (String span_name, ?service_name: String?, ?operation_name: String, ?tags: Hash[untyped, untyped]) -> Datadog::CI::Span + def self.trace: (String span_type, String span_name, ?tags: Hash[untyped, untyped]) ?{ (Datadog::CI::Span span) -> untyped } -> untyped def self.components: () -> Datadog::CI::Configuration::Components diff --git a/spec/datadog/ci_spec.rb b/spec/datadog/ci_spec.rb index cf944c99..c298f55e 100644 --- a/spec/datadog/ci_spec.rb +++ b/spec/datadog/ci_spec.rb @@ -24,6 +24,30 @@ it { is_expected.to be(ci_test) } end + describe "#start_test" do + subject(:start_test) { described_class.start_test(test_name, **options) } + + let(:test_name) { "test name" } + let(:options) do + { + service_name: "my-serivce", + operation_name: "rspec.example", + tags: {"foo" => "bar"} + } + end + + let(:recorder) { instance_double(Datadog::CI::Recorder) } + let(:ci_test) { instance_double(Datadog::CI::Span) } + + before do + allow(Datadog::CI).to receive(:recorder).and_return(recorder) + + allow(recorder).to receive(:trace_test).with(test_name, **options).and_return(ci_test) + end + + it { is_expected.to be(ci_test) } + end + describe "::trace" do subject(:trace) { described_class.trace(span_type, span_name, **options, &block) }