diff --git a/Rakefile b/Rakefile index 0a7caa65..f2633a77 100644 --- a/Rakefile +++ b/Rakefile @@ -44,13 +44,13 @@ TEST_METADATA = { "" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby" }, "cucumber" => { - "cucumber-3" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby", - "cucumber-4" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby", - "cucumber-5" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby", - "cucumber-6" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby", - "cucumber-7" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby", - "cucumber-8" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby", - "cucumber-9" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby" + "cucumber-3" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby", + "cucumber-4" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby", + "cucumber-5" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby", + "cucumber-6" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby", + "cucumber-7" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby", + "cucumber-8" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby", + "cucumber-9" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby" }, "rspec" => { "rspec-3" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby" @@ -80,7 +80,7 @@ TEST_METADATA = { "knapsack_pro-7-rspec-3" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ❌ jruby" }, "selenium" => { - "selenium-4-capybara-3" => "❌ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby" + "selenium-4-capybara-3" => "❌ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ❌ 3.4 / ✅ jruby" }, "timecop" => { "timecop-0" => "✅ 2.7 / ✅ 3.0 / ✅ 3.1 / ✅ 3.2 / ✅ 3.3 / ✅ 3.4 / ✅ jruby" diff --git a/lib/datadog/ci/contrib/cucumber/patcher.rb b/lib/datadog/ci/contrib/cucumber/patcher.rb index 0459ba18..af130550 100644 --- a/lib/datadog/ci/contrib/cucumber/patcher.rb +++ b/lib/datadog/ci/contrib/cucumber/patcher.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "datadog/tracing/contrib/patcher" +require_relative "../patcher" require_relative "instrumentation" @@ -10,7 +10,7 @@ module Contrib module Cucumber # Patches 'cucumber' gem. module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher module_function diff --git a/lib/datadog/ci/contrib/minitest/patcher.rb b/lib/datadog/ci/contrib/minitest/patcher.rb index bc7a3309..de98d603 100644 --- a/lib/datadog/ci/contrib/minitest/patcher.rb +++ b/lib/datadog/ci/contrib/minitest/patcher.rb @@ -11,7 +11,7 @@ module Contrib module Minitest # Patcher enables patching of 'minitest' module. module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher module_function diff --git a/lib/datadog/ci/contrib/patcher.rb b/lib/datadog/ci/contrib/patcher.rb new file mode 100644 index 00000000..74e0fce0 --- /dev/null +++ b/lib/datadog/ci/contrib/patcher.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require "datadog/core/utils/only_once" +require "datadog/core/telemetry/logger" + +module Datadog + module CI + module Contrib + # Common behavior for patcher modules. + module Patcher + def self.included(base) + base.singleton_class.prepend(CommonMethods) + end + + # Prepended instance methods for all patchers + module CommonMethods + attr_accessor \ + :patch_error_result, + :patch_successful + + def patch_name + (self.class != Class && self.class != Module) ? self.class.name : name + end + + def patched? + patch_only_once.ran? + end + + def patch + return unless defined?(super) + + patch_only_once.run do + super.tap do + @patch_successful = true + end + rescue => e + on_patch_error(e) + end + end + + # Processes patching errors. This default implementation logs the error and reports relevant metrics. + # @param e [Exception] + def on_patch_error(e) + Datadog.logger.error("Failed to apply #{patch_name} patch. Cause: #{e} Location: #{Array(e.backtrace).first}") + Datadog::Core::Telemetry::Logger.report(e, description: "Failed to apply #{patch_name} patch") + + @patch_error_result = { + type: e.class.name, + message: e.message, + line: Array(e.backtrace).first + } + end + + private + + def patch_only_once + # NOTE: This is not thread-safe + @patch_only_once ||= Datadog::Core::Utils::OnlyOnce.new + end + end + end + end + end +end diff --git a/lib/datadog/ci/contrib/rspec/patcher.rb b/lib/datadog/ci/contrib/rspec/patcher.rb index 65799a4b..145ed035 100644 --- a/lib/datadog/ci/contrib/rspec/patcher.rb +++ b/lib/datadog/ci/contrib/rspec/patcher.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "datadog/tracing/contrib/patcher" +require_relative "../patcher" require_relative "example" require_relative "example_group" @@ -12,7 +12,7 @@ module Contrib module RSpec # Patcher enables patching of 'rspec' module. module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher module_function diff --git a/lib/datadog/ci/contrib/selenium/capybara_driver.rb b/lib/datadog/ci/contrib/selenium/capybara_driver.rb index 6e77cbc8..5dd671ce 100644 --- a/lib/datadog/ci/contrib/selenium/capybara_driver.rb +++ b/lib/datadog/ci/contrib/selenium/capybara_driver.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "datadog/tracing/contrib/patcher" +require_relative "../patcher" require_relative "ext" require_relative "rum" diff --git a/lib/datadog/ci/contrib/selenium/driver.rb b/lib/datadog/ci/contrib/selenium/driver.rb index 3c6bea4a..75a2757c 100644 --- a/lib/datadog/ci/contrib/selenium/driver.rb +++ b/lib/datadog/ci/contrib/selenium/driver.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "datadog/tracing/contrib/patcher" +require_relative "../patcher" require_relative "ext" require_relative "rum" diff --git a/lib/datadog/ci/contrib/selenium/navigation.rb b/lib/datadog/ci/contrib/selenium/navigation.rb index b44f2234..04151798 100644 --- a/lib/datadog/ci/contrib/selenium/navigation.rb +++ b/lib/datadog/ci/contrib/selenium/navigation.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "datadog/tracing/contrib/patcher" +require_relative "../patcher" require_relative "ext" require_relative "../../ext/test" diff --git a/lib/datadog/ci/contrib/selenium/patcher.rb b/lib/datadog/ci/contrib/selenium/patcher.rb index 6471b047..b4640c9c 100644 --- a/lib/datadog/ci/contrib/selenium/patcher.rb +++ b/lib/datadog/ci/contrib/selenium/patcher.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "datadog/tracing/contrib/patcher" +require_relative "../patcher" require_relative "capybara_driver" require_relative "driver" @@ -12,7 +12,7 @@ module Contrib module Selenium # Patcher enables patching of 'Selenium::WebDriver' module. module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher module_function diff --git a/lib/datadog/ci/contrib/selenium/rum.rb b/lib/datadog/ci/contrib/selenium/rum.rb index 3a2b8330..f5fb25d4 100644 --- a/lib/datadog/ci/contrib/selenium/rum.rb +++ b/lib/datadog/ci/contrib/selenium/rum.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "datadog/tracing/contrib/patcher" - require_relative "ext" require_relative "../../ext/test" require_relative "../../utils/parsing" diff --git a/lib/datadog/ci/contrib/simplecov/patcher.rb b/lib/datadog/ci/contrib/simplecov/patcher.rb index 1e11e01e..f200d894 100644 --- a/lib/datadog/ci/contrib/simplecov/patcher.rb +++ b/lib/datadog/ci/contrib/simplecov/patcher.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "datadog/tracing/contrib/patcher" +require_relative "../patcher" require_relative "result_extractor" @@ -10,7 +10,7 @@ module Contrib module Simplecov # Patcher enables patching of 'SimpleCov' module. module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher module_function diff --git a/sig/datadog/ci/contrib/cucumber/patcher.rbs b/sig/datadog/ci/contrib/cucumber/patcher.rbs index 8769cd17..ed30da67 100644 --- a/sig/datadog/ci/contrib/cucumber/patcher.rbs +++ b/sig/datadog/ci/contrib/cucumber/patcher.rbs @@ -3,7 +3,7 @@ module Datadog module Contrib module Cucumber module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher def self?.target_version: () -> untyped diff --git a/sig/datadog/ci/contrib/minitest/patcher.rbs b/sig/datadog/ci/contrib/minitest/patcher.rbs index 49b53f30..ab494098 100644 --- a/sig/datadog/ci/contrib/minitest/patcher.rbs +++ b/sig/datadog/ci/contrib/minitest/patcher.rbs @@ -3,7 +3,7 @@ module Datadog module Contrib module Minitest module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher def self?.target_version: () -> untyped diff --git a/sig/datadog/ci/contrib/patcher.rbs b/sig/datadog/ci/contrib/patcher.rbs new file mode 100644 index 00000000..f63fd48c --- /dev/null +++ b/sig/datadog/ci/contrib/patcher.rbs @@ -0,0 +1,33 @@ +module Datadog + module CI + module Contrib + module Patcher + def self.included: (untyped base) -> untyped + + module CommonMethods + attr_accessor patch_error_result: untyped + + attr_accessor patch_successful: untyped + + def patch_name: () -> String? + + def name: () -> String + + def patched?: () -> bool + + def patch: () -> void + + def on_patch_error: (untyped e) -> untyped + + def default_tags: () -> untyped + + private + + def patch_only_once: () -> untyped + + @patch_only_once: Datadog::Core::Utils::OnlyOnce + end + end + end + end +end diff --git a/sig/datadog/ci/contrib/rspec/patcher.rbs b/sig/datadog/ci/contrib/rspec/patcher.rbs index bb3ff7c6..d3e26b75 100644 --- a/sig/datadog/ci/contrib/rspec/patcher.rbs +++ b/sig/datadog/ci/contrib/rspec/patcher.rbs @@ -3,7 +3,7 @@ module Datadog module Contrib module RSpec module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher def self?.target_version: () -> String diff --git a/sig/datadog/ci/contrib/selenium/patcher.rbs b/sig/datadog/ci/contrib/selenium/patcher.rbs index 885aaa45..83295b0b 100644 --- a/sig/datadog/ci/contrib/selenium/patcher.rbs +++ b/sig/datadog/ci/contrib/selenium/patcher.rbs @@ -3,7 +3,7 @@ module Datadog module Contrib module Selenium module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher def self?.target_version: () -> untyped diff --git a/sig/datadog/ci/contrib/simplecov/patcher.rbs b/sig/datadog/ci/contrib/simplecov/patcher.rbs index 30263ca5..65cb472f 100644 --- a/sig/datadog/ci/contrib/simplecov/patcher.rbs +++ b/sig/datadog/ci/contrib/simplecov/patcher.rbs @@ -3,7 +3,7 @@ module Datadog module Contrib module Simplecov module Patcher - include Datadog::Tracing::Contrib::Patcher + include Datadog::CI::Contrib::Patcher def self?.target_version: () -> untyped diff --git a/spec/datadog/ci/git/search_commits_spec.rb b/spec/datadog/ci/git/search_commits_spec.rb index ea664353..721b7fc3 100644 --- a/spec/datadog/ci/git/search_commits_spec.rb +++ b/spec/datadog/ci/git/search_commits_spec.rb @@ -107,7 +107,7 @@ expect { subject } .to raise_error( Datadog::CI::Git::SearchCommits::ApiError, - "Invalid commit type response {\"id\"=>\"c7f893648f656339f62fb7b4d8a6ecdf7d063835\", \"type\"=>\"invalid\"}" + /Invalid commit type response/ ) end end @@ -169,7 +169,7 @@ expect { subject } .to raise_error( Datadog::CI::Git::SearchCommits::ApiError, - "Invalid commit type response {\"id\"=>\"c7f893648f656339f62fb7b4d8a6ecdf7d063835\"}" + /Invalid commit type response/ ) end end diff --git a/spec/datadog/ci/test_optimisation/coverage/transport_spec.rb b/spec/datadog/ci/test_optimisation/coverage/transport_spec.rb index 7007720d..a0c9dd44 100644 --- a/spec/datadog/ci/test_optimisation/coverage/transport_spec.rb +++ b/spec/datadog/ci/test_optimisation/coverage/transport_spec.rb @@ -131,9 +131,7 @@ subject expect(Datadog.logger).to have_received(:warn).with( - "citestcov event is invalid: [test_suite_id] is nil. " \ - "Event: Coverage::Event[test_id=4, test_suite_id=, test_session_id=6, " \ - "coverage={\"file.rb\"=>true, \"file2.rb\"=>true}]" + /\[test_suite_id\] is nil/ ) end diff --git a/spec/datadog/ci/test_visibility/transport_spec.rb b/spec/datadog/ci/test_visibility/transport_spec.rb index 8d9a4640..e241ed22 100644 --- a/spec/datadog/ci/test_visibility/transport_spec.rb +++ b/spec/datadog/ci/test_visibility/transport_spec.rb @@ -196,11 +196,7 @@ it "logs warning that events were filtered out" do subject - expect(Datadog.logger).to have_received(:warn).with( - "Invalid event skipped: " \ - "Datadog::CI::TestVisibility::Serializers::Span(id:#{http_span.id},name:#{http_span.name}) " \ - "Errors: {\"start\"=>#}" - ) + expect(Datadog.logger).to have_received(:warn).with(/must be greater than or equal to 946684800000000000/) end it_behaves_like "emits telemetry metric", :inc, "events_enqueued_for_serialization", 3 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 817e5c85..77f4fdfd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -81,9 +81,8 @@ def self.load_plugins # Raise error when patching an integration fails. # This can be disabled by unstubbing +CommonMethods#on_patch_error+ - require "datadog/tracing/contrib/patcher" config.before do - allow_any_instance_of(Datadog::Tracing::Contrib::Patcher::CommonMethods).to(receive(:on_patch_error)) { |_, e| raise e } + allow_any_instance_of(Datadog::CI::Contrib::Patcher::CommonMethods).to(receive(:on_patch_error)) { |_, e| raise e } end # Ensure tracer environment is clean before running tests. diff --git a/vendor/rbs/ddtrace/0/datadog/core/telemetry/logger.rbs b/vendor/rbs/ddtrace/0/datadog/core/telemetry/logger.rbs new file mode 100644 index 00000000..b32bf487 --- /dev/null +++ b/vendor/rbs/ddtrace/0/datadog/core/telemetry/logger.rbs @@ -0,0 +1,15 @@ +module Datadog + module Core + module Telemetry + module Logger + def self.report: (Exception exception, ?level: Symbol, ?description: String?) -> void + + def self.error: (String description) -> void + + private + + def self.instance: () -> Datadog::Core::Telemetry::Component? + end + end + end +end