Skip to content

Commit 3806145

Browse files
View Component instrumentation: use source_location or identifier (#2956)
* Use `source_location` or `identifier`
1 parent ad4bf8d commit 3806145

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## dev
44

5-
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+.
5+
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+.
66

77
- **Feature: Instrumentation for aws-sdk-lambda**
88

@@ -12,6 +12,10 @@ Version <dev> introduces instrumentation for the aws-sdk-lambda gem, allows user
1212

1313
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)
1414

15+
- **Feature: Update View Component instrumentation+**
16+
17+
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)
18+
1519
- **Bugfix: Record explain plan traces on Rails 7.2+**
1620

1721
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)

lib/new_relic/agent/instrumentation/view_component/instrumentation.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def render_in_with_tracing(*args)
2121
end
2222

2323
def metric_name
24-
"View/#{metric_path(self.class.source_location)}/#{self.class.name}"
24+
# ViewComponent determines a component's identifier differently depending on the version
25+
# https://github.com/ViewComponent/view_component/pull/2153
26+
component_identifier = defined?(self.class.source_location) ? self.class.source_location : self.class.identifier
27+
28+
"View/#{metric_path(component_identifier)}/#{self.class.name}"
2529
rescue => e
2630
NewRelic::Agent.logger.error('Error identifying View Component metric name', e)
2731

test/multiverse/suites/view_component/Envfile

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ instrumentation_methods :chain, :prepend
66

77
VIEW_COMPONENT_VERSIONS = [
88
[nil, 2.7],
9+
['3.15.0', 2.7], # 3.15.0 should remain tested due to API differences before and after this version
910
['2.53.0', 2.4]
1011
]
1112

1213
def gem_list(view_component_version = nil)
1314
<<~RB
14-
gem 'rails'
15-
gem 'view_component'#{view_component_version}
16-
gem 'rack-test'
17-
gem 'loofah', '~> 2.20.0' if RUBY_VERSION >= '2.4.0' && RUBY_VERSION < '2.5.0'
15+
gem 'rails'
16+
gem 'view_component'#{view_component_version}
17+
gem 'rack-test'
18+
gem 'loofah', '~> 2.20.0' if RUBY_VERSION >= '2.4.0' && RUBY_VERSION < '2.5.0'
1819
RB
1920
end
2021

0 commit comments

Comments
 (0)