-
Notifications
You must be signed in to change notification settings - Fork 369
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
AWS patcher loads wrong Client constant #938
Comments
Could you be more specific about how this error was produced? Do you have a snippet of code that will reproduce it? Currently on |
It's possible the error may stem from the AWS patcher code, which attempts to load def patch
require 'ddtrace/contrib/aws/parsed_context'
require 'ddtrace/contrib/aws/instrumentation'
require 'ddtrace/contrib/aws/services'
add_plugin(Seahorse::Client::Base, *loaded_constants)
end
def add_plugin(*targets)
targets.each { |klass| klass.add_plugin(Instrumentation) }
end
def loaded_constants
SERVICES.each_with_object([]) do |service, constants|
next if ::Aws.autoload?(service)
constants << ::Aws.const_get(service).const_get(:Client) rescue next
end
end If I'm reading this error correctly, it sounds like one of the Can you share:
Maybe with that we can try to replicate this; might require a bugfix to our patcher if so. |
Hi @delner From our Gemfile.lock: ddtrace: Also when we renamed our Client class to something else temporarily, the error did not appear. |
@delner any updates on this? Thank you very much |
Currently trying to reproduce this, will update afterwards. If you have sample code that reproduces the issue that'd be most welcome. |
Hi @delner After doing some digging Client is being added to the list of
vs S3
All the other targets are properly nested except Support Client.
|
From what I can tell with the latest
Looks like everything is loading properly to me, no errors. What version of |
Hi @delner The problem was not with the AWS SDK but rather the way ddtrace adds AWS Services. By iterating through a list of services and running My app has a class called Client as well as a folder in /lib called /support. Rails autoloads /support as a module called Support. When Might it be better to get the intersection of the ddtrace SERVICES list and |
I'm not sure how this is happening. module Aws
module Support
class Client
end
end
end
module Support
class Client
end
end
[].tap do |loaded_constants|
loaded_constants << ::Aws.const_get(:Support).const_get(:Client)
end
# => [Aws::Support::Client] Maybe Rails auto-loading is involved, but I also ran this in a Rails 5.2.2 application after adding |
Just to be clear, client.rb is a model (app/models/client.rb) and has nothing to do with the support folder. Also if you have the
Here is the code I used to generate the above: https://github.com/illdelph/dd-test |
@illdelph Okay, I loaded up that repo and I can see the error now. I'm going to crack open the patcher with this example and see what I can make of this and how to fix it. Will get back to you; thanks! |
It looks like This is an unusual circumstance because you did not load the full I think this should be relatively easy to fix; I'll make the constant resolution a little more restrictive so it doesn't search ancestors. EDIT: It's even more unexpected than originally thought because calling
Meaning when we disable the ancestor search, it still doesn't work as expected. When I try to replicate this in class Bar
end
module Foo
# class Bar
# end
end
::Foo.const_get('Bar', false)
# => NameError (uninitialized constant Foo::Bar)
::Foo.const_get('Bar', false)
# => NameError (uninitialized constant Foo::Bar) So there's something weird going on with Rails autoloading I'd suspect. Either way, we should be able to work around this. |
In new Rails 6 loader "zeitwerk", it says (https://github.com/fxn/zeitwerk#motivation):
|
@frsantos Good to know; thanks! Given this is a Rails 5 app, I'm not sure if |
@illdelph and @letiesperon: This should be addressed by #945, please feel free to give it a try and let me know if it works for you. |
@delner I tried out the PR and it looks like the error is gone 👍 |
Should be addressed when the next release rolls; thank you for the report and sample code to reproduce! |
So, I had a class called
Client
in my app.Now I added the gem
gem 'ddtrace', '~> 0.28.0'
and I get this error:Unable to apply AWS integration: undefined method add_plugin for Client (call 'Client.connection' to establish a connection):Class
Because it seems that this adds its own class called Client right? Which is overriden by my own Client class.
Why didn't you namespace it to be sth more specific like
Datadog::Client
? I mean,Client
is a pretty common name.The text was updated successfully, but these errors were encountered: