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

ViewComponent instrumentation #2367

Merged
merged 10 commits into from Jan 8, 2024
Merged

ViewComponent instrumentation #2367

merged 10 commits into from Jan 8, 2024

Conversation

hannahramadan
Copy link
Contributor

@hannahramadan hannahramadan commented Dec 14, 2023

Add New Relic instrumentation for ViewComponent.

Closes #2205

.rubocop_todo.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great overall. 🖼️ 🎉

I know you're still working on things, but don't forget to add a CHANGELOG entry!

I have a few other comments below 🙂

@hannahramadan hannahramadan marked this pull request as ready for review January 5, 2024 20:11
def test_metric_recorded
get('/view_components')

assert_metrics_recorded('View/view_component/view_component_instrumentation_test.rb/ExampleComponent')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metric name looked odd to me with the .rb file path, but it does match the convention we've long had in place for View/ based metrics:

'View/model/index.html.erb/Rendering'
'View/model/_list.html.erb/Partial'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree! I don't love the look and thought it was a bit weird, but matches 🤷‍♀️ It is also how ViewComponent itself has chosen to do their instrumentation (self.class.identifier is the full path including .rb)

fallwith
fallwith previously approved these changes Jan 5, 2024
module ViewComponent
INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name)

def render_in_with_tracing(*args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused, i'm probably missing something obvious (sorry!).
But this method doesn't seem to take a block or yield or anything, so i'm curious what the segment thats being created is measuring?

begin
segment = NewRelic::Agent::Tracer.start_segment(
name: metric_name(self.class.identifier, self.class.name)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I would expect a yield after this line, which would call super/render_in_without_tracing from the do blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch @tannalynn. This wasn't yielding and preventing views from showing up 😱 Added the yield, tested, and we get both the NR metric and app view now.

Hannah Ramadan and others added 9 commits January 8, 2024 06:39
Inline disable rubocop

Cleanup tests

Appease rubocop
Co-authored-by: Kayla Reopelle (she/her) <87386821+kaylareopelle@users.noreply.github.com>

Code feedback

Add mistakenly deleted file

Move file

Test update

Test updates

Use newer vc version
version change

Only test latest version
tannalynn
tannalynn previously approved these changes Jan 8, 2024
@tannalynn tannalynn merged commit 38199be into dev Jan 8, 2024
26 checks passed
Copy link

github-actions bot commented Jan 8, 2024

SimpleCov Report

Coverage Threshold
Line 93.69% 93%
Branch 71.77% 71%

)
yield
rescue => e
::NewRelic::Agent.logger.debug('Error capturing ViewComponent segment', e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late to the party, but... is suppressing errors here the intended behavior?

ViewComponent/view_component#1981

@hannahramadan hannahramadan deleted the view_component branch April 12, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for getting render timing information with view_component
5 participants