Sha256: 93d2b5f0a7f79435c0a3b65bcba743ea1725dc618bd76f4731a061ef819cdb12

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

module NewRelic
  module Agent
    module Instrumentation
      module Tilt
        def metric_name(klass, file)
          "View/#{klass}/#{file}/Rendering"
        end

        # 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
        def create_filename_for_metric(file)
          return file unless defined?(::Sinatra) && defined?(::Sinatra::Base)

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

        def render_with_tracing(*args, &block)
          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
            finishable.finish if finishable
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
newrelic_rpm-9.0.0 lib/new_relic/agent/instrumentation/tilt/instrumentation.rb
newrelic_rpm-8.16.0 lib/new_relic/agent/instrumentation/tilt/instrumentation.rb
newrelic_rpm-8.15.0 lib/new_relic/agent/instrumentation/tilt/instrumentation.rb
newrelic_rpm-8.14.0 lib/new_relic/agent/instrumentation/tilt/instrumentation.rb
newrelic_rpm-8.13.1 lib/new_relic/agent/instrumentation/tilt/instrumentation.rb
newrelic_rpm-8.13.0 lib/new_relic/agent/instrumentation/tilt/instrumentation.rb
newrelic_rpm-8.12.0 lib/new_relic/agent/instrumentation/tilt/instrumentation.rb