Sha256: 65e703b03a496ba52205c851b11c3a846e65178f45f725fece31be8832d90c91

Contents?: true

Size: 1.28 KB

Versions: 26

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module ElasticAPM # :nodoc:
  # @api private
  module Normalizers
    # @api privagte
    class Normalizer
      def initialize(config)
        @config = config
      end

      def self.register(name)
        Normalizers.register(name, self)
      end
    end

    def self.register(name, klass)
      @registered ||= {}
      @registered[name] = klass
    end

    def self.build(config)
      normalizers = @registered.each_with_object({}) do |(name, klass), built|
        built[name] = klass.new(config)
      end

      Collection.new(normalizers)
    end

    # @api private
    class Collection
      # @api private
      class SkipNormalizer
        def initialize; end

        def normalize(*_args)
          :skip
        end
      end

      def initialize(normalizers)
        @normalizers = normalizers
        @default = SkipNormalizer.new
      end

      def for(name)
        @normalizers.fetch(name) { @default }
      end

      def keys
        @normalizers.keys
      end

      def normalize(transaction, name, payload)
        self.for(name).normalize(transaction, name, payload)
      end
    end
  end

  %w[
    action_controller
    action_mailer
    action_view
    active_record
  ].each do |lib|
    require "elastic_apm/normalizers/#{lib}"
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
elastic-apm-2.0.1 lib/elastic_apm/normalizers.rb
elastic-apm-2.0.0 lib/elastic_apm/normalizers.rb
elastic-apm-1.1.0 lib/elastic_apm/normalizers.rb
elastic-apm-1.0.2 lib/elastic_apm/normalizers.rb
elastic-apm-1.0.1 lib/elastic_apm/normalizers.rb
elastic-apm-1.0.0 lib/elastic_apm/normalizers.rb