Sha256: 095ba84301e5d2fc89a2140193c297d918f204437ebf335fcfc1eb7164118bdf

Contents?: true

Size: 1.79 KB

Versions: 17

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module ElasticAPM
  module Normalizers
    module ActionView
      # @api private
      class RenderNormalizer < Normalizer
        private

        def normalize_render(payload, type)
          [path_for(payload[:identifier]), type, nil]
        end

        def path_for(path)
          return 'Unknown template' unless path
          return path unless path.start_with?('/')

          view_path(path) || gem_path(path) || 'Absolute path'
        end

        def view_path(path)
          root = @config.view_paths.find { |vp| path.start_with?(vp) }
          return unless root

          strip_root(root, path)
        end

        def gem_path(path)
          root = Gem.path.find { |gp| path.start_with? gp }
          return unless root

          format '$GEM_PATH/%s', strip_root(root, path)
        end

        def strip_root(root, path)
          start = root.length + 1
          path[start, path.length]
        end
      end

      # @api private
      class RenderTemplateNormalizer < RenderNormalizer
        register 'render_template.action_view'
        TYPE = 'template.view'

        def normalize(_transaction, _name, payload)
          normalize_render(payload, TYPE)
        end
      end

      # @api private
      class RenderPartialNormalizer < RenderNormalizer
        register 'render_partial.action_view'
        TYPE = 'template.view.partial'

        def normalize(_transaction, _name, payload)
          normalize_render(payload, TYPE)
        end
      end

      # @api private
      class RenderCollectionNormalizer < RenderNormalizer
        register 'render_collection.action_view'
        TYPE = 'template.view.collection'

        def normalize(_transaction, _name, payload)
          normalize_render(payload, TYPE)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
elastic-apm-2.9.1 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.9.0 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.8.1 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.8.0 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.7.0 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.6.1 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.6.0 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.5.0 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.4.0 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.3.1 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.3.0 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.2.0 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.1.2 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.1.1 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.1.0 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.0.1 lib/elastic_apm/normalizers/action_view.rb
elastic-apm-2.0.0 lib/elastic_apm/normalizers/action_view.rb