Skip to content

Commit

Permalink
Update View Component metric naming
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahramadan committed Oct 10, 2024
1 parent ffea529 commit 0f18bb4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
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 @@ -60,12 +60,12 @@ def test_error_raised

# 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 0f18bb4

Please sign in to comment.