1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
---
layout: default
title: Instrumentation
parent: How-to guide
---
# Instrumentation
Since 2.34.0
{: .label }
To enable ActiveSupport notifications, use the `instrumentation_enabled` option:
```ruby
# config/application.rb
# Enable ActiveSupport notifications for all ViewComponents
config.view_component.instrumentation_enabled = true
```
Subscribe to the event:
```ruby
ActiveSupport::Notifications.subscribe("render.view_component") do |event| # or !render.view_component
event.name # => "render.view_component"
event.payload # => { name: "MyComponent", identifier: "/Users/mona/project/app/components/my_component.rb" }
end
```
_Note: Enabling instrumentation negatively impacts the performance of ViewComponent._
## Viewing instrumentation sums in the browser developer tools
When using `render.view_component` with `config.server_timing = true` (default in development) in Rails 7, the browser developer tools display the sum total timing information in Network > Timing under the key `render.view_component`.

## Viewing instrumentation breakdowns in rack-mini-profiler
The [rack-mini-profiler gem](https://rubygems.org/gems/rack-mini-profiler) is a popular tool for profiling rack-based Ruby applications.
To profile ViewComponent rendering alongside views and partials:
```ruby
# config/environments/development.rb
# Profile rendering of ViewComponents
Rack::MiniProfilerRails.subscribe("render.view_component") do |_name, start, finish, _id, payload|
Rack::MiniProfilerRails.render_notification_handler(
Rack::MiniProfilerRails.shorten_identifier(payload[:identifier]),
finish,
start
)
end
```
|