instrumental_agent-ruby icon indicating copy to clipboard operation
instrumental_agent-ruby copied to clipboard

FrozenError exception raised instantiating agent in Rails 6.1.1

Open cbatson opened this issue 4 years ago • 2 comments

Using Ruby 3.0 and Rails 6.1.1:

root@3353f515ae84:/gwf/app# bundle exec rails c
/usr/local/bundle/bundler/gems/instrumental_agent-ruby-e6b27a2199d2/lib/instrumental/agent.rb:18: warning: Socket.gethostbyname is deprecated; use Addrinfo.getaddrinfo instead.
Loading development environment (Rails 6.1.1)
irb(main):001:0> require 'instrumental_agent'
=> false
irb(main):002:0> agent = Instrumental::Agent.new('foo', enabled: false)
Traceback (most recent call last):
        2: from (irb):2:in `<main>'
        1: from (irb):2:in `new'
FrozenError (can't modify frozen Array: [Metrician::Middleware::RequestTiming, Rack::ContentLength, ActionDispatch::HostAuthorization, Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::Runtime, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::ActionableExceptions, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, Rack::Head, Rack::ConditionalGet, Rack::ETag, Metrician::Middleware::ApplicationTiming])

cbatson avatar Mar 03 '21 19:03 cbatson

Can work around by disabling metrician:

irb(main):003:0> agent = Instrumental::Agent.new('foo', enabled: false, metrician: false)
=> #<Instrumental::Agent:0x00005646207d61f0 @api_key="foo", @host="collector.instrumentalapp.com", @port=80...

cbatson avatar Mar 03 '21 19:03 cbatson

We'll take a look, but off the top of my head does it work if you load the agent earlier in the rails startup process? It looks like something during initialization is freezing the middleware array, so if the agent is loaded before that happens it might work.

jason-o-matic avatar Mar 03 '21 21:03 jason-o-matic