newrelic-ruby-agent icon indicating copy to clipboard operation
newrelic-ruby-agent copied to clipboard

Optimisation to shrink the agent's footprint: don't require disabled or absent gem based instrumentation code

Open fallwith opened this issue 1 year ago • 1 comments

Most every gem instrumentation's detection code has some top-level lines like so:

require_relative 'widget/instrumentation'
require_relative 'widget/chain'
require_relative 'widget/prepend'

These lines are evaluated by Ruby and cause all of instrumentation logic for the gem to be loaded into the Ruby VM even if the gem does not exist in the customer's tech stack and even if the customer's configuration has explicitly disabled the instrumentation. Essentially some Ruby methods will sit defined but orphaned in the customer's Ruby VM instance.

We can shrink the relevant footprint by moving these require_relative lines either into the existing executes do block within each instrumentation file, or within their own dedicated executes do block. By having the lines live within a block, they will only being executed by Ruby conditionally, based on the instrumentation's depends_on block(s).

We did this recently with the rdkafka gem instrumentation and we should consider doing the same for all gems.

fallwith avatar Sep 10 '24 17:09 fallwith

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