diff --git a/lib/new_relic/agent/vm/mri_vm.rb b/lib/new_relic/agent/vm/mri_vm.rb index ddb071e8b9..5f128db86c 100644 --- a/lib/new_relic/agent/vm/mri_vm.rb +++ b/lib/new_relic/agent/vm/mri_vm.rb @@ -49,7 +49,19 @@ def gather_ruby_vm_stats(snap) end if supports?(:constant_cache_invalidations) - snap.constant_cache_invalidations = RubyVM.stat[:global_constant_state] + snap.constant_cache_invalidations = gather_constant_cache_invalidations + end + end + + def gather_constant_cache_invalidations + # Ruby >= 3.2 uses :constant_cache + # see: https://github.com/ruby/ruby/pull/5433 and https://bugs.ruby-lang.org/issues/18589 + # TODO: now that 3.2+ provides more granual cache invalidation data, should we report it instead of summing? + if RUBY_VERSION >= '3.2.0' + RubyVM.stat[:constant_cache].values.sum + # Ruby < 3.2 uses :global_constant_state + else + RubyVM.stat[:global_constant_state] end end