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!
Hi @mustela,
I noticed "Available?: false" in your output, meaning the method Patchable.available? returned false: https://github.com/DataDog/dd-trace-rb/blob/7125d114fb9e357423b253cce2061a5d52886f2b/lib/ddtrace/contrib/patchable.rb#L17-L19
Which, for the Rails integration, means that Integration.version was nil: https://github.com/DataDog/dd-trace-rb/blob/7125d114fb9e357423b253cce2061a5d52886f2b/lib/ddtrace/contrib/rails/integration.rb#L18-L20
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?
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
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.
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
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)>
looks like it broke from https://github.com/DataDog/dd-trace-rb/releases/tag/v0.33.0
looks like it broke from https://github.com/DataDog/dd-trace-rb/releases/tag/v0.33.0
Specifically this PR https://github.com/DataDog/dd-trace-rb/pull/944 which enforces a require 'rails' in the the Gemfile, to return available? = true
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:
defined?(::Rails::VERSION) && ::Rails::VERSION::MAJOR.to_i >= 3Gem.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.
@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 sounds great thanks for the fix we will give a try post new release
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
Hey @mustela, @bheemreddy181, @vramaiah! We've just released 0.36.0, which ships a fix to allow for more leaning Rails detection (https://github.com/DataDog/dd-trace-rb/pull/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.
Cool thanks :-) will keep you posted.