newrelic / newrelic-ruby-agent

New Relic RPM Ruby Agent
https://docs.newrelic.com/docs/apm/agents/ruby-agent/getting-started/introduction-new-relic-ruby/
Apache License 2.0
1.2k stars 598 forks source link

Investigate Apartment compatibility with New Relic #2426

Open hannahramadan opened 7 months ago

hannahramadan commented 7 months ago

Description

The Apartment gem helps Rails applications achieve database multitenancy. There is a known incompatiability with New Relic and Apartment when the config setting active_record_log = true is present. This config unsubscribes from ActiveRecord notifications, which Ruby agent instrumentation relies on. We are unable to provide insights into ActiveRecord calls when that config setting is enabled, which it isn't by default.

    config.after_initialize do
      # NOTE: Load the custom log subscriber if enabled
      if Apartment.active_record_log
        ActiveSupport::Notifications.notifier.listeners_for('sql.active_record').each do |listener|
          next unless listener.instance_variable_get('@delegate').is_a?(ActiveRecord::LogSubscriber)

          ActiveSupport::Notifications.unsubscribe listener
        end

        Apartment::LogSubscriber.attach_to :active_record
      end
    end

Customers can disable this configuration value and recieve New Relic insights into their database calls.

Acceptance Criteria

We should understand why this configuration setting needs to disable ActiveRecord notifications, and from there decide if we add our findings to a troubleshooting guide that instructs turning off this config setting for New Relic to report database calls, or programatically work around this issue in the agent.

Post-completion

The GTSE team created a KCS article describing the fix of removing the config. Whatever we decided to do with this ticket, we should update teh GTSE team so they can edit that article if needed.

workato-integration[bot] commented 7 months ago

https://new-relic.atlassian.net/browse/NR-221591