Sha256: 3b61cff94c9c36bb45875b32caceee3259126a94277c1372c7acd3bb083ff93c

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 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::Agent::Instrumentation
  module ViewComponent
    INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name)

    def render_in_with_tracing(*args)
      NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)

      begin
        segment = NewRelic::Agent::Tracer.start_segment(
          name: metric_name(self.class.identifier, self.class.name)
        )
        yield
      rescue => e
        NewRelic::Agent.notice_error(e)
        raise
      ensure
        segment&.finish
      end
    end

    def metric_name(identifier, component)
      "View/#{metric_path(identifier)}/#{component}"
    end

    def metric_path(identifier)
      return 'component' unless identifier

      if (parts = identifier.split('/')).size > 1
        parts[-2..-1].join('/') # Get filepath by assuming the Rails' structure: app/components/home/example_component.rb
      else
        NewRelic::Agent::UNKNOWN_METRIC
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
newrelic_rpm-9.13.0 lib/new_relic/agent/instrumentation/view_component/instrumentation.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/instrumentation/view_component/instrumentation.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/instrumentation/view_component/instrumentation.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/instrumentation/view_component/instrumentation.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/instrumentation/view_component/instrumentation.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/instrumentation/view_component/instrumentation.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/instrumentation/view_component/instrumentation.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/instrumentation/view_component/instrumentation.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/instrumentation/view_component/instrumentation.rb