Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update View Component metric building #2907

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
kaylareopelle marked this conversation as resolved.
Show resolved Hide resolved
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
Loading