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

Support to break out viewcomponent #169

Open
drnic opened this issue Jan 14, 2021 · 7 comments
Open

Support to break out viewcomponent #169

drnic opened this issue Jan 14, 2021 · 7 comments

Comments

@drnic
Copy link

drnic commented Jan 14, 2021

I'm rendering pages, partials, and actioncable responses with https://viewcomponent.org/ Currently the work done inside the .rb component and its .html.erb template is not shown in skylight. Could we add VC support please?

Update

I've had some success sending the rendering time for each component by adding the following two lines to each component class:

  include Skylight::Helpers
  instrument_method :render_in

image

@wagenet
Copy link
Contributor

wagenet commented Jan 19, 2021

@drnic thanks for bringing this to our attention. I meant to look into it some last week but ran out of time. I hope to prioritize it this week.

@wagenet
Copy link
Contributor

wagenet commented Jan 19, 2021

FWIW, I think the solution you found works well though we should definitely make it first class!

@wagenet
Copy link
Contributor

wagenet commented Jan 19, 2021

@drnic at the most fundamental level, this already appears to work. Do you have some sample code that you recommend?

@p8
Copy link

p8 commented Feb 2, 2022

@wagenet I tried implementing this by adding an ApplicationComponent:

class ApplicationComponent < ViewComponent::Base
  include Skylight::Helpers
  instrument_method :render_in
end

Then I don't need to add it to all my components and I can just inherit from this ApplicationComponent:

class AgreementComponent < ApplicationComponent
  attr_reader :agreement
  def initialize(agreement:)
    @agreement = agreement
  end

end

But in Skylight I'm only seeing the instrumentation of the superclass:
ApplicationComponent#render_in
...instead of:
AgreementComponent#render_in

@wagenet
Copy link
Contributor

wagenet commented Jun 27, 2022

@p8 my sincere apologies for the delay in replying here! You might be able to work around this by doing:

class ApplicationComponent < ViewComponent::Base
  include Skylight::Helpers
  instrument_method :render_in
  def render_in(*)
    super
  end
end

@ConfusedVorlon
Copy link

FWIW, I think the solution you found works well though we should definitely make it first class!

Any chance of bringing this back into play?

fwiw, I tried

class InstrumentedComponent < ViewComponent::Base
  include Skylight::Helpers
  instrument_method :render_in
  def render_in(*)
    super
  end
end

(and then inheriting from that in my components)
I dont get any instrumentation at all from my components.

@zvkemp
Copy link
Contributor

zvkemp commented Dec 12, 2023

@ConfusedVorlon This branch implements the necessary normalizer to handle ViewComponent instrumentation: https://github.com/skylightio/skylight-ruby/tree/view-component. The base branch is equivalent to Skylight 6.0.1.

You can bundle this branch with

gem skylight, github: "skylightio/skylight-ruby", branch: "view-component"

Please note this has not been merged into our main branch yet, as it has been only narrowly tested, so please test it out yourself before deciding to use it in production (that said, the normalizer logic itself is heavily tested, so the risks should be minimal). I used view_component 3.8.0 on a rails 7.1 app, YMMV with other versions.

This also requires the following two lines in your application.rb:

    config.view_component.instrumentation_enabled = true
    config.view_component.use_deprecated_instrumentation_name = false

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

No branches or pull requests

5 participants