Skip to content

Commit

Permalink
Update View Component metric building (#2907)
Browse files Browse the repository at this point in the history
* Use default `View/component` metric name for unidentified View Components
  • Loading branch information
hannahramadan authored Oct 11, 2024
1 parent c96ac53 commit 52bb44e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## dev

Version <dev> resolves a bug in rdkafka instrumentation when using the karafka-rdkafka gem.
Version <dev> updates View Componment instrumentation to use a default metric name when one is unavaliable and resolves a bug in rdkafka instrumentation when using the karafka-rdkafka gem.

- **Feature: Use default `View/component` metric name for unidentified View Components**

Previously, when a View Component metric name could not be identified, the agent would set the name as `nil`. Now, the agent defaults to using `View/component` as the metric name when one can not be identified. [PR#2907](https://github.com/newrelic/newrelic-ruby-agent/pull/2907)

- **Bugfix: Instrumentation errors when using the karafka-rdkafka gem**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ def render_in_with_tracing(*args)
NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)

begin
segment = NewRelic::Agent::Tracer.start_segment(
name: metric_name(
self.class.respond_to?(:identifier) ? self.class.identifier : nil,
self.class.name
)
)
segment = NewRelic::Agent::Tracer.start_segment(name: metric_name)
yield
rescue => e
NewRelic::Agent.notice_error(e)
Expand All @@ -25,8 +20,12 @@ def render_in_with_tracing(*args)
end
end

def metric_name(identifier, component)
"View/#{metric_path(identifier)}/#{component}"
def metric_name
"View/#{metric_path(self.class.source_location)}/#{self.class.name}"
rescue => e
NewRelic::Agent.logger.error('Error identifying View Component metric name', e)

'View/component'
end

def metric_path(identifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ def test_error_raised
end
end

# Test metric name being built when the controller class doesn't respond to :identifier
# https://github.com/newrelic/newrelic-ruby-agent/pull/2870
def test_the_metric_name_omits_the_identifier_when_absent
def test_the_metric_name_records_default_name_on_error
in_transaction do |txn|
FAKE_CLASS.render_in_with_tracing { 11 * 38 }
actual_name = txn.segments.last.name

assert_equal 'View/component/DummyViewComponentInstrumentationClass', actual_name
assert_equal 'View/component', actual_name
end
end
end

0 comments on commit 52bb44e

Please sign in to comment.