Skip to content

Commit

Permalink
View Component instrumentation: use source_location or identifier (
Browse files Browse the repository at this point in the history
…#2956)

* Use `source_location` or `identifier`
  • Loading branch information
hannahramadan authored Nov 18, 2024
1 parent ad4bf8d commit 3806145
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## dev

Version <dev> 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 <dev> 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**

Expand All @@ -12,6 +12,10 @@ Version <dev> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions test/multiverse/suites/view_component/Envfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3806145

Please sign in to comment.