File: instrumentation.rb

package info (click to toggle)
ruby-view-component 4.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 472 kB
  • sloc: ruby: 2,278; makefile: 4
file content (25 lines) | stat: -rw-r--r-- 600 bytes parent folder | download
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
# frozen_string_literal: true

require "active_support/notifications"

module ViewComponent # :nodoc:
  module Instrumentation
    def self.included(mod)
      mod.prepend(self) unless self <= ViewComponent::Instrumentation
    end

    def render_in(view_context, &block)
      return super if !Rails.application.config.view_component.instrumentation_enabled.present?

      ActiveSupport::Notifications.instrument(
        "render.view_component",
        {
          name: self.class.name,
          identifier: self.class.identifier
        }
      ) do
        super
      end
    end
  end
end