Skip to content

Commit

Permalink
fix loaded? definitions for integrations; do not patch already patche…
Browse files Browse the repository at this point in the history
…d integrations
  • Loading branch information
anmarchenko committed Nov 20, 2024
1 parent 88a1837 commit fb26fae
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/ci/contrib/cucumber/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def version
end

def loaded?
!defined?(::Cucumber).nil? && !defined?(::Cucumber::Runtime).nil?
!defined?(::Cucumber).nil? && !defined?(::Cucumber::Runtime).nil? && !defined?(::Cucumber::Configuration).nil?
end

def compatible?
Expand Down
1 change: 1 addition & 0 deletions lib/datadog/ci/contrib/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def self.auto_instrument

script_compiled_tracepoint = TracePoint.new(:script_compiled) do
auto_instrumented_integrations.each do |integration|
next if integration.patched?
next unless integration.loaded?

Datadog.logger.debug("#{integration.class} is loaded")
Expand Down
10 changes: 6 additions & 4 deletions lib/datadog/ci/contrib/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ def patcher

# @!visibility private
def patch
# @type var patcher_klass: untyped
patcher_klass = patcher
if !patchable? || patcher_klass.nil?
if !patchable? || patcher.nil?
return {
ok: false,
available: available?,
Expand All @@ -105,10 +103,14 @@ def patch
}
end

patcher_klass.patch
patcher.patch
{ok: true}
end

def patched?
patcher&.patched?
end

# Can the patch for this integration be applied automatically?
# @return [Boolean] can the tracer activate this instrumentation without explicit user input?
def late_instrument?
Expand Down
3 changes: 2 additions & 1 deletion lib/datadog/ci/contrib/minitest/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def version
end

def loaded?
!defined?(::Minitest).nil?
!defined?(::Minitest).nil? && !defined?(::Minitest::Runnable).nil? && !defined?(::Minitest::Test).nil? &&
!defined?(::Minitest::CompositeReporter).nil?
end

def compatible?
Expand Down
4 changes: 3 additions & 1 deletion lib/datadog/ci/contrib/rspec/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def version

def loaded?
!defined?(::RSpec).nil? && !defined?(::RSpec::Core).nil? &&
!defined?(::RSpec::Core::Example).nil?
!defined?(::RSpec::Core::Example).nil? &&
!defined?(::RSpec::Core::Runner).nil? &&
!defined?(::RSpec::Core::ExampleGroup).nil?
end

def compatible?
Expand Down
4 changes: 3 additions & 1 deletion sig/datadog/ci/contrib/integration.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ module Datadog

def enabled: () -> bool

def patcher: () -> Datadog::Tracing::Contrib::Patcher?
def patcher: () -> untyped

def patched?: () -> bool?

def patch: () -> Hash[Symbol, bool]

Expand Down

0 comments on commit fb26fae

Please sign in to comment.