ActiveRecord profiling with Sinatra

Hi,

I'm trying to use the Ruby APM agent. We have a Sinatra based app that uses ActiveRecord. Currently APM doesn't show the database calls, just the top level Rack calls. Is there an easy way to turn this on? It looks like from the code that it's only enabled for Rails, before I spend more time digging into the code to figure out if it's possible has anyone else done this?

Cheers,
James.

Hi James!

I haven't tried or heard of this exact combination with the agent before but it should be doable.
The "problem" is that ActiveRecord instrumentation works via ActiveSupport::Notifications and the agent isn't subscribing to those when not loaded via Rails.

But! It should work if you just instantiate your own ElasticAPM::Subscriber, ie somewhere after starting the agent, do ElasticAPM::Subscriber.new(ElasticAPM.agent).register!.

I take it ActiveRecord already depends on ActiveSuppport but if I'm wrong, you might have to do a require 'activesupport' somewhere too.

Here's the class definition for reference: https://github.com/elastic/apm-agent-ruby/blob/v3.3.0/lib/elastic_apm/subscriber.rb

Let me know how and if it works!

Thanks for the help.

That idea results in an error as it looks like the Normalizer needs to be registered first.
normalizers.rb line 25 throws a nil error.
I'm having a look to see if I can figure out where/how that needs to happen.

Cheers,
James

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.