From 380614546ea0939a2577bd58e6564f5043689a80 Mon Sep 17 00:00:00 2001 From: Hannah Ramadan <76922290+hannahramadan@users.noreply.github.com> Date: Mon, 18 Nov 2024 15:57:47 -0800 Subject: [PATCH] View Component instrumentation: use `source_location` or `identifier` (#2956) * Use `source_location` or `identifier` --- CHANGELOG.md | 6 +++++- .../instrumentation/view_component/instrumentation.rb | 6 +++++- test/multiverse/suites/view_component/Envfile | 9 +++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c4106e87f..b178b6b794 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## dev -Version introduces instrumentation for the aws-sdk-lambda gem, allows users to opt-in to adding labels to logs, and fixes a bug with explain plans on Rails 7.2+. +Version introduces instrumentation for the aws-sdk-lambda gem, allows users to opt-in to adding labels to logs, updates View Component instrumentation, and fixes a bug with explain plans on Rails 7.2+. - **Feature: Instrumentation for aws-sdk-lambda** @@ -12,6 +12,10 @@ Version introduces instrumentation for the aws-sdk-lambda gem, allows user The Ruby agent now allows you to opt-in to adding your custom tags (labels) to agent-forwarded logs. With custom tags on logs, platform engineers can easily filter, search, and correlate log data for faster and more efficient troubleshooting, improved performance, and optimized resource utilization. [PR#2925](https://github.com/newrelic/newrelic-ruby-agent/pull/2925) +- **Feature: Update View Component instrumentation+** + + The `.identifier` method will be formally exposed as part of the View Component public API. The agent will now use this method for building metric names when available, ensuring ongoing compatibility with all View Component versions. [PR#2956](https://github.com/newrelic/newrelic-ruby-agent/pull/2956) + - **Bugfix: Record explain plan traces on Rails 7.2+** Rails 7.2 removed adapter-specific connection methods (ex. `ActiveRecord::Base.postgresql_connection`) and replaced them with `ActiveRecord::Base.with_connection`. Our explain plan feature relies on making a connection to the database to create an explain plan trace. Due to a bug in our tests, we missed this regression. Now, the agent uses the new method to fetch explain plans on Rails 7.2+. Thank you, [@gsar](https://github.com/gsar) and [@gstark](https://github.com/gstark) for bringing this to our attention! [Issue#2922](https://github.com/newrelic/newrelic-ruby-agent/issues/2922) [PR#2940](https://github.com/newrelic/newrelic-ruby-agent/pull/2940) diff --git a/lib/new_relic/agent/instrumentation/view_component/instrumentation.rb b/lib/new_relic/agent/instrumentation/view_component/instrumentation.rb index b565f81e10..4c149f1186 100644 --- a/lib/new_relic/agent/instrumentation/view_component/instrumentation.rb +++ b/lib/new_relic/agent/instrumentation/view_component/instrumentation.rb @@ -21,7 +21,11 @@ def render_in_with_tracing(*args) end def metric_name - "View/#{metric_path(self.class.source_location)}/#{self.class.name}" + # ViewComponent determines a component's identifier differently depending on the version + # https://github.com/ViewComponent/view_component/pull/2153 + component_identifier = defined?(self.class.source_location) ? self.class.source_location : self.class.identifier + + "View/#{metric_path(component_identifier)}/#{self.class.name}" rescue => e NewRelic::Agent.logger.error('Error identifying View Component metric name', e) diff --git a/test/multiverse/suites/view_component/Envfile b/test/multiverse/suites/view_component/Envfile index 10100d9ee3..30e8de1a82 100644 --- a/test/multiverse/suites/view_component/Envfile +++ b/test/multiverse/suites/view_component/Envfile @@ -6,15 +6,16 @@ instrumentation_methods :chain, :prepend VIEW_COMPONENT_VERSIONS = [ [nil, 2.7], + ['3.15.0', 2.7], # 3.15.0 should remain tested due to API differences before and after this version ['2.53.0', 2.4] ] def gem_list(view_component_version = nil) <<~RB - gem 'rails' - gem 'view_component'#{view_component_version} - gem 'rack-test' - gem 'loofah', '~> 2.20.0' if RUBY_VERSION >= '2.4.0' && RUBY_VERSION < '2.5.0' + gem 'rails' + gem 'view_component'#{view_component_version} + gem 'rack-test' + gem 'loofah', '~> 2.20.0' if RUBY_VERSION >= '2.4.0' && RUBY_VERSION < '2.5.0' RB end