module ScoutApm::Instruments::ActiveRecordQueryingInstruments

Entry-point of instruments.

Instrumentation starts in ActiveRecord::Relation#exec_queries (Rails >= 3.2.0) or ActiveRecord::FinderMethods#find_with_assocations (previous Rails versions).

ActiveRecord::Querying#find_by_sql is instrumented in all Rails versions even though it is also invoked by exec_queries/#find_by_associations because it can be invoked directly from user code (e.g., Post.find_by_sql(“SELECT * FROM posts”)). The layer started by exec_queries/#find_by_assocations is marked to ignore children, so it will not cause duplicate layers in the former case.

These methods are early in the chain of calls invoked when executing an ActiveRecord query, before the cache is consulted. If the query is later determined to be a cache miss, ‘#log` will be invoked, which we also instrument, and more details will be filled in (name, sql).

Caveats:

* We don't have a name for the query yet.
* The query hasn't hit the cache yet. In the case of a cache hit, we
  won't hit #log, so won't get a name, leaving the misleading default.
* One call here can result in several calls to #log, especially in the
  case where Rails needs to load the schema details for the table being
  queried.