module NewRelic::Agent::Instrumentation::Tilt

Constants

INSTRUMENTATION_NAME

Public Instance Methods

create_filename_for_metric(file) click to toggle source

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

# 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) click to toggle source
# 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) { || ... } click to toggle source
# 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