Module: NewRelic::Agent::Instrumentation::Tilt

Included in:
Prepend
Defined in:
lib/new_relic/agent/instrumentation/tilt/chain.rb,
lib/new_relic/agent/instrumentation/tilt/instrumentation.rb

Defined Under Namespace

Modules: Chain, Prepend

Constant Summary collapse

INSTRUMENTATION_NAME =
NewRelic::Agent.base_name(name)

Instance Method Summary collapse

Instance Method Details

#create_filename_for_metric(file) ⇒ Object

Sinatra uses #caller_locations for the file name in Tilt (unlike Rails/Rack) So here we are only grabbing the file name and name of directory it is in



17
18
19
20
21
22
23
# File 'lib/new_relic/agent/instrumentation/tilt/instrumentation.rb', line 17

def create_filename_for_metric(file)
  return file unless defined?(::Sinatra) && defined?(::Sinatra::Base)

  file.split('/')[-2..-1].join('/')
rescue NoMethodError
  file
end

#metric_name(klass, file) ⇒ Object



11
12
13
# File 'lib/new_relic/agent/instrumentation/tilt/instrumentation.rb', line 11

def metric_name(klass, file)
  "View/#{klass}/#{file}/Rendering"
end

#render_with_tracing(*args, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/new_relic/agent/instrumentation/tilt/instrumentation.rb', line 25

def render_with_tracing(*args, &block)
  NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)

  begin
    finishable = Tracer.start_segment(
      name: metric_name(self.class, create_filename_for_metric(self.file))
    )
    begin
      yield
    rescue => error
      NewRelic::Agent.notice_error(error)
      raise
    end
  ensure
    # The following line needs else branch coverage
    finishable.finish if finishable # rubocop:disable Style/SafeNavigation
  end
end