lib/opentelemetry/instrumentation/base.rb in opentelemetry-instrumentation-base-0.21.0 vs lib/opentelemetry/instrumentation/base.rb in opentelemetry-instrumentation-base-0.21.1

- old
+ new

@@ -70,13 +70,13 @@ string: ->(v) { v.is_a?(String) } }.freeze private_constant :NAME_REGEX, :VALIDATORS - private :new # rubocop:disable Style/AccessModifierDeclarations + private :new - def inherited(subclass) + def inherited(subclass) # rubocop:disable Lint/MissingSuper OpenTelemetry::Instrumentation.registry.register(subclass) end # Optionally set the name of this instrumentation. If not # explicitly set, the name will default to the namespace of the class, @@ -191,10 +191,11 @@ attr_reader :name, :version, :config, :installed, :tracer alias installed? installed + # rubocop:disable Metrics/ParameterLists def initialize(name, version, install_blk, present_blk, compatible_blk, options) @name = name @version = version @install_blk = install_blk @@ -203,10 +204,11 @@ @config = {} @installed = false @options = options @tracer = OpenTelemetry::Trace::Tracer.new end + # rubocop:enable Metrics/ParameterLists # Install instrumentation with the given config. The present? and compatible? # will be run first, and install will return false if either fail. Will # return true if install was completed successfully. # @@ -264,19 +266,20 @@ # config hash is valid. # Unknown configuration keys are not included in the final config hash. # Invalid configuration values are logged, and replaced by the default. # # @param [Hash] user_config The user supplied configuration hash - def config_options(user_config) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + def config_options(user_config) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity @options ||= {} user_config ||= {} config_overrides = config_overrides_from_env validated_config = @options.each_with_object({}) do |option, h| option_name = option[:name] config_value = user_config[option_name] config_override = coerce_env_var(config_overrides[option_name], option[:validation_type]) if config_overrides[option_name] + # rubocop:disable Lint/DuplicateBranch value = if config_value.nil? && config_override.nil? option[:default] elsif option[:validator].respond_to?(:include?) && option[:validator].include?(config_override) config_override elsif option[:validator].respond_to?(:include?) && option[:validator].include?(config_value) @@ -290,9 +293,10 @@ "Instrumentation #{name} configuration option #{option_name} value=#{config_value} " \ "failed validation, falling back to default value=#{option[:default]}" ) option[:default] end + # rubocop:enable Lint/DuplicateBranch h[option_name] = value rescue StandardError => e OpenTelemetry.handle_error(exception: e, message: "Instrumentation #{name} unexpected configuration error") h[option_name] = option[:default]