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 all commits
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
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)
hannahramadan marked this conversation as resolved.
Show resolved Hide resolved

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