Skip to content

Instrumentation: include view template path in render.view_component payload#2572

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-event-emission-for-view-file
Draft

Instrumentation: include view template path in render.view_component payload#2572
Copilot wants to merge 2 commits intomainfrom
copilot/add-event-emission-for-view-file

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

The render.view_component event payload only included the component's .rb identifier, making it impossible for tools like Coverband to track which view templates are actually rendered.

Changes

  • lib/view_component/instrumentation.rb: Adds view_identifier to the event payload — the path to the rendered template file (e.g. my_component.html.erb). Uses an around_render override to capture current_template.path at the right moment: after rendering sets @current_template but before Base#render_in's ensure block restores it. view_identifier is nil for components using inline call methods (no template file).
  • test/sandbox/test/instrumentation_test.rb: Asserts view_identifier is present and correct in the event payload.
  • docs/guide/instrumentation.md: Updated example payload to reflect new field.

Updated payload

ActiveSupport::Notifications.subscribe("render.view_component") do |event|
  event.payload
  # => {
  #   name: "MyComponent",
  #   identifier: "/app/components/my_component.rb",
  #   view_identifier: "/app/components/my_component.html.erb"  # nil for inline call components
  # }
end

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: joelhawksley <1940294+joelhawksley@users.noreply.github.com>
Copilot AI changed the title [WIP] Add event emission for specific view file in ViewComponent Instrumentation: include view template path in render.view_component payload Mar 5, 2026
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.

2 participants