# ActiveRecord profiling with Sinatra

**URL:** <https://discuss.elastic.co/t/activerecord-profiling-with-sinatra/214010>\
**Category:** APM\
**Tags:** ruby\
**Created:** [January 7, 2020, 9:21am UTC](https://discuss.elastic.co/t/activerecord-profiling-with-sinatra/214010 "2020-01-07T09:21:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesB](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jamesb/32/24343_2.png) [@JamesB](https://discuss.elastic.co/u/JamesB)\
**Post date:** [January 7, 2020, 9:21am UTC](https://discuss.elastic.co/t/activerecord-profiling-with-sinatra/214010/1 "2020-01-07T09:21:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikker/32/22118_2.png) [@mikker](https://discuss.elastic.co/u/mikker)\
**Post date:** [January 7, 2020, 9:35am UTC](https://discuss.elastic.co/t/activerecord-profiling-with-sinatra/214010/2 "2020-01-07T09:35:49Z")

</div>

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](https://github.com/elastic/apm-agent-ruby/blob/v3.3.0/lib/elastic_apm/subscriber.rb)

Let me know how and if it works!

---

<div class="post-metadata">

**Author:** ![JamesB](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jamesb/32/24343_2.png) [@JamesB](https://discuss.elastic.co/u/JamesB)\
**Post date:** [January 7, 2020, 11:43am UTC](https://discuss.elastic.co/t/activerecord-profiling-with-sinatra/214010/3 "2020-01-07T11:43:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 28, 2020, 7:43am UTC](https://discuss.elastic.co/t/activerecord-profiling-with-sinatra/214010/4 "2020-01-28T07:43:26Z")

</div>

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