Module: RailsPerformance::Gems::CustomExtension

Extended by:
CustomExtension
Included in:
CustomExtension
Defined in:
lib/rails_performance/gems/custom_ext.rb

Instance Method Summary collapse

Instance Method Details

#measure(tag_name, namespace_name = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rails_performance/gems/custom_ext.rb', line 6

def measure(tag_name, namespace_name = nil)
  return yield unless RailsPerformance.enabled
  return yield unless RailsPerformance.include_custom_events

  begin
    now = Time.current
    status = "success"
    result = yield
    result
  rescue Exception => ex # rubocop:disable Lint/RescueException
    status = "error"
    raise(ex)
  ensure
    RailsPerformance::Models::CustomRecord.new(
      tag_name: tag_name,
      namespace_name: namespace_name,
      status: status,
      duration: (Time.current - now) * 1000,
      datetime: now.strftime(RailsPerformance::FORMAT),
      datetimei: now.to_i
    ).save
  end
end