Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to patch Datadog::Contrib::Rails::Integration (Available?: false, Loaded? true, Compatibl e? false, Patchable? false) #993

Closed
mustela opened this issue Apr 3, 2020 · 13 comments · Fixed by #1054
Assignees
Labels
bug Involves a bug community Was opened by a community member integrations Involves tracing integrations
Milestone

Comments

@mustela
Copy link

mustela commented Apr 3, 2020

Hey guys, I can no longer see stats of my service and Im seeing a warning in the logs

W, [2020-04-03T15:46:09.808488 #101]  WARN -- ddtrace: [ddtrace] Unable to patch
 Datadog::Contrib::Rails::Integration (Available?: false, Loaded? true, Compatib
le? false, Patchable? false)

Im using:

ddtrace 0.34.1
rails 5.2.4

Is there any way I can manually test if the integration is working as expected?

Thanks!

@marcotc
Copy link
Member

marcotc commented Apr 3, 2020

Hi @mustela,

I noticed "Available?: false" in your output, meaning the method Patchable.available? returned false:

def available?
!version.nil?
end

Which, for the Rails integration, means that Integration.version was nil:

def self.version
Gem.loaded_specs['rails'] && Gem.loaded_specs['rails'].version
end

This leads me to believe that Rails was not required before ddtrace is configured.
The versions Rails you are using is compatible with the tracer version, so there's no concern there.

Would you mind sharing how you configure ddtrace: what's the path for the file that calls Datadog.configure in your project, and what's the content of that file?

@marcotc marcotc added bug Involves a bug community Was opened by a community member integrations Involves tracing integrations labels Apr 3, 2020
@marcotc marcotc self-assigned this Apr 3, 2020
@mustela
Copy link
Author

mustela commented Apr 3, 2020

Sure, this is the content

require "rake"

Datadog.configure do |c|
  c.tracer enabled: false unless Rails.env.production? || Rails.env.staging? || Rails.env.lab?
  c.analytics_enabled = true
  c.tracer tags: { "env" => Rails.env }
  c.use :rails, service_name: "pusher"
  c.use :rake
end

And the path is config/initializers/datadog.rb

@delner
Copy link
Contributor

delner commented Apr 9, 2020

How are you loading the application? Not sure how Gem.loaded_specs['rails'] && Gem.loaded_specs['rails'].version returns nil, yet defined?(::Rails) doesn't. Almost like you defined a Rails constant without actually loading the Rails gem? Perhaps running this from a Rakefile? You may also need to use bundle exec otherwise the Rails gem may not be available.

Without a code sample to replicate this one, its going to be hard to say how this happened, and you might have to dig a bit deeper on your end. For what its worth, I'm not seeing this when doing the same in a default Rails 5 application and running rails s.

@mustela
Copy link
Author

mustela commented Apr 21, 2020

Hey guys, thanks for your help and sorry for my delay!

So, yes, the issue was that I was not using the rails gem, but including only the parts that I needed like

gem 'actioncable'
gem 'actionmailer'
gem 'actionpack'
gem 'activejob'

So that was the issue, putting back the gem fixed the problem.

Thanks

@mustela mustela closed this as completed Apr 21, 2020
@bheemreddy181-zz
Copy link

bheemreddy181-zz commented May 22, 2020

why do we need a rails gem explicitly on the new version of ddtrace why not on the older version ? @delner

Local, with ddtrace - 0.32.0
[1] pry(main)> Datadog.registry[:rails].patcher.patched?
true
[2] pry(main)>
Local, with ddtrace - 0.35.2 and without gem
[1] pry(main)> Datadog.registry[:rails].patcher.patched?
false
[2] pry(main)>
Local, with ddtrace - 0.35.2 and with rails gem in Gemfile
[1] pry(main)> Datadog.registry[:rails].patcher.patched?
true
[2] pry(main)>

@bheemreddy181-zz
Copy link

looks like it broke from https://github.com/DataDog/dd-trace-rb/releases/tag/v0.33.0

@vishakseshadri
Copy link

looks like it broke from https://github.com/DataDog/dd-trace-rb/releases/tag/v0.33.0

Specifically this PR #944 which enforces a require 'rails' in the the Gemfile, to return available? = true

@marcotc
Copy link
Member

marcotc commented May 22, 2020

Hi @bheemreddy181 and @vramaiah, thank you for the update!

I've tried to reproduce the issue and get the same output you provided, but I'm not able to. Here's what I tried:

require 'bundler/inline'

ddtrace_version = ARGV[0]
rails_gem = ARGV[1] == "true"

gemfile do
  source 'https://rubygems.org'
  if rails_gem
    gem 'rails', '5.2.0'
  else
    gem 'actioncable', '5.2.0'
    gem 'actionmailer', '5.2.0'
    gem 'actionpack', '5.2.0'
    gem 'actionview', '5.2.0'
    gem 'activejob', '5.2.0'
    gem 'activemodel', '5.2.0'
    gem 'activerecord', '5.2.0'
    gem 'activestorage', '5.2.0'
    gem 'activesupport', '5.2.0'
  end

  gem 'ddtrace', ddtrace_version
end

Datadog.configure do |c|
  c.use :rails
end

puts "Datadog.registry[:rails].patcher.patched? = #{Datadog.registry[:rails].patcher.patched?}"
$ ruby  -v
ruby 2.4.10p364 (2020-03-31 revision 67879)

$ ruby issue993.rb 0.32.0 false
W, [2020-05-22T15:50:21.944546 #86969]  WARN -- ddtrace: [ddtrace] Unable to patch Datadog::Contrib::Rails::Integration
Datadog.registry[:rails].patcher.patched? = false

$ ruby issue993.rb 0.32.0 true
Datadog.registry[:rails].patcher.patched? = true

$ ruby issue993.rb 0.35.2 false
W, [2020-05-22T15:50:37.254230 #98427]  WARN -- ddtrace: [ddtrace] Unable to patch Datadog::Contrib::Rails::Integration (Available?: false, Loaded? false, Compatible? false, Patchable? false)
Datadog.registry[:rails].patcher.patched? = false

$ ruby issue993.rb 0.35.2 true
Datadog.registry[:rails].patcher.patched? = true

I also checked again the suspected culprit file, https://github.com/DataDog/dd-trace-rb/pull/944/files#diff-1081fc5d9e2a72bd75729272da38a396, and we did make changes to the way we check for the presence of Rails, but the outcomes are still the same when I tested:

  • Before: defined?(::Rails::VERSION) && ::Rails::VERSION::MAJOR.to_i >= 3
  • After: Gem.loaded_specs['rails'].version >= Gem::Version.new('3.0')

Both will return false unless the meta-gem rails is loaded:

pry> require 'action_cable'
=> true
pry> require 'action_mailer'
=> true
pry> require 'action_pack'
=> false
pry> require 'action_view'
=> true
pry> require 'active_job'
=> true
pry> require 'active_model'
=> true
pry> require 'active_record'
=> true
pry> require 'active_storage'
=> true
pry> require 'active_support'
=> false
pry> require 'active_support'
=> false

pry> ::Rails # old check
NameError: uninitialized constant Rails

pry> Gem.loaded_specs['rails'] # new check
=> nil

I'm likely missing something in my efforts to reproduce it, please let me know if there's any other information from you application that I'm not capturing in my test setup.

@delner
Copy link
Contributor

delner commented May 26, 2020

@mustela @bheemreddy181 @vramaiah I think #1054 should address this issue if your apps are not using gem 'rails' but are using railties. Can you try this out and confirm it fixes the issue?

@delner delner reopened this May 26, 2020
@bheemreddy181-zz
Copy link

@delner sounds great thanks for the fix we will give a try post new release

@delner delner linked a pull request May 26, 2020 that will close this issue
@bheemreddy181-zz
Copy link

We tested this version of gem in our local , we could see all these changes working as expected

Loading development environment (Rails 5.2.4.3)
[1] pry(main)> Datadog.registry[:rails].patcher.patched?
true
[2] pry(main)> Datadog::Contrib::Rails::Integration.compatible?
true
[3] pry(main)> Datadog::Contrib::Rails::Integration.version
#<Gem::Version "5.2.4.3">
[4] pry(main)> Datadog::Contrib::Rails::Integration.available?
true
[5] pry(main)> Datadog::Contrib::Rails::Integration.patchable?
true

with the below source

source 'http://gems.datadoghq.com/prerelease' do
  gem 'ddtrace', '0.35.2.fix.rails.patching.with.railties.66858'
end

@marcotc marcotc added this to the 0.36.0 milestone May 27, 2020
@marcotc
Copy link
Member

marcotc commented May 27, 2020

Hey @mustela, @bheemreddy181, @vramaiah! We've just released 0.36.0, which ships a fix to allow for more leaning Rails detection (#1054): we now only need to find railties installed, the rails meta gem is not required.

Let us know if the issue persists after this release.

@bheemreddy181-zz
Copy link

Cool thanks :-) will keep you posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug community Was opened by a community member integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants