opentelemetry-instrumentation-base 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8922540a64bf732b865d3a980635d9352ad990dcf1d53e790dacef2e1de53b02
4
- data.tar.gz: 335dbd4e09103cba8ba00aa8f026e096a71bd61d612b7443751f791b10e98d44
3
+ metadata.gz: 164a4d7f0afcc437a79f2e2569ff80d904644d512a7a241a462eb26054127cff
4
+ data.tar.gz: 1807fe5154e3d77093429e7a6355bd952615f410ffe199f3e587b3af22c45184
5
5
  SHA512:
6
- metadata.gz: 96a6bff956fea730b3d40c9b20206597f9490a8970bbfa67b1dbb28d1529fdef7c70984325d7753e524af6723c5d0116352c22e14ad88978b586cf722472d1a8
7
- data.tar.gz: 49de180e839687bf7cc064a16ea1a52e2c137dfaa9cb2f96f5eadb44a770d0fb36016dfeaad2aacb82470918af762fc07a6ff22dfeefb0a087cd562e7fa04e68
6
+ metadata.gz: 83b29693b52c0d2d0e3e668f7fb4229be83149c1833146604fc719d794566a504029fd9c9d241d1e25b1c28fd166ae286da7f383b609afdbf2d6f8195839b3b0
7
+ data.tar.gz: e86bdac3678dde4c77a56402a3ea0fb4fb8289dbc82fa31ac134d38f943372c7083542a5d35110ed674ea08d99724e5b15cc2bbf51cec0591847381351231cbb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Release History: opentelemetry-instrumentation-base
2
2
 
3
+ ### v0.19.0 / 2021-12-01
4
+
5
+ * ADDED: Add default options config helper + env var config option support
6
+
7
+ ### v0.18.3 / 2021-09-29
8
+
9
+ * (No significant changes)
10
+
11
+ ### v0.18.2 / 2021-08-12
12
+
13
+ * (No significant changes)
14
+
15
+ ### v0.18.1 / 2021-06-23
16
+
17
+ * (No significant changes)
18
+
3
19
  ### v0.18.0 / 2021-05-21
4
20
 
5
21
  * ADDED: Updated API depedency for 1.0.0.rc1
@@ -146,11 +146,20 @@ module OpenTelemetry
146
146
  # a key in the VALIDATORS hash. The supported keys are, :array, :boolean,
147
147
  # :callable, :integer, :string.
148
148
  def option(name, default:, validate:)
149
- validate = VALIDATORS[validate] || validate
150
- raise ArgumentError, "validate must be #{VALIDATORS.keys.join(', ')}, or a callable" unless validate.respond_to?(:call)
149
+ validator = VALIDATORS[validate] || validate
150
+ raise ArgumentError, "validate must be #{VALIDATORS.keys.join(', ')}, or a callable" unless validator.respond_to?(:call) || validator.respond_to?(:include?)
151
151
 
152
152
  @options ||= []
153
- @options << { name: name, default: default, validate: validate }
153
+
154
+ validation_type = if VALIDATORS[validate]
155
+ validate
156
+ elsif validate.respond_to?(:include?)
157
+ :enum
158
+ else
159
+ :callable
160
+ end
161
+
162
+ @options << { name: name, default: default, validator: validator, validation_type: validation_type }
154
163
  end
155
164
 
156
165
  def instance
@@ -257,16 +266,24 @@ module OpenTelemetry
257
266
  # Invalid configuration values are logged, and replaced by the default.
258
267
  #
259
268
  # @param [Hash] user_config The user supplied configuration hash
260
- def config_options(user_config) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
269
+ def config_options(user_config) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
261
270
  @options ||= {}
262
271
  user_config ||= {}
272
+ config_overrides = config_overrides_from_env
263
273
  validated_config = @options.each_with_object({}) do |option, h|
264
274
  option_name = option[:name]
265
275
  config_value = user_config[option_name]
276
+ config_override = coerce_env_var(config_overrides[option_name], option[:validation_type]) if config_overrides[option_name]
266
277
 
267
- value = if config_value.nil?
278
+ value = if config_value.nil? && config_override.nil?
268
279
  option[:default]
269
- elsif option[:validate].call(config_value)
280
+ elsif option[:validator].respond_to?(:include?) && option[:validator].include?(config_override)
281
+ config_override
282
+ elsif option[:validator].respond_to?(:include?) && option[:validator].include?(config_value)
283
+ config_value
284
+ elsif option[:validator].respond_to?(:call) && option[:validator].call(config_override)
285
+ config_override
286
+ elsif option[:validator].respond_to?(:call) && option[:validator].call(config_value)
270
287
  config_value
271
288
  else
272
289
  OpenTelemetry.logger.warn(
@@ -303,6 +320,49 @@ module OpenTelemetry
303
320
  end
304
321
  ENV[var_name] != 'false'
305
322
  end
323
+
324
+ def config_overrides_from_env
325
+ var_name = name.dup.tap do |n|
326
+ n.upcase!
327
+ n.gsub!('::', '_')
328
+ n.gsub!('OPENTELEMETRY_', 'OTEL_RUBY_')
329
+ n << '_CONFIG_OPTS'
330
+ end
331
+
332
+ environment_config_overrides = {}
333
+ env_config_options = ENV[var_name]&.split(';')
334
+
335
+ return environment_config_overrides if env_config_options.nil?
336
+
337
+ env_config_options.each_with_object(environment_config_overrides) do |env_config_option, eco|
338
+ parts = env_config_option.split('=')
339
+ option_name = parts[0].to_sym
340
+ eco[option_name] = parts[1]
341
+ end
342
+
343
+ environment_config_overrides
344
+ end
345
+
346
+ def coerce_env_var(env_var, validation_type) # rubocop:disable Metrics/CyclomaticComplexity
347
+ case validation_type
348
+ when :array
349
+ env_var.split(',').map(&:strip)
350
+ when :boolean
351
+ env_var.to_s.strip.downcase == 'true'
352
+ when :integer
353
+ env_var.to_i
354
+ when :string
355
+ env_var.to_s.strip
356
+ when :enum
357
+ env_var.to_s.strip.to_sym
358
+ when :callable
359
+ OpenTelemetry.logger.warn(
360
+ "Instrumentation #{name} options that accept a callable are not " \
361
+ "configurable using environment variables. Ignoring raw value: #{env_var}"
362
+ )
363
+ nil
364
+ end
365
+ end
306
366
  end
307
367
  end
308
368
  end
@@ -6,6 +6,6 @@
6
6
 
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
- VERSION = '0.18.0'
9
+ VERSION = '0.19.0'
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-21 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0.rc1
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0.rc1
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -142,10 +142,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
142
142
  licenses:
143
143
  - Apache-2.0
144
144
  metadata:
145
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-base/v0.18.0/file.CHANGELOG.html
145
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-base/v0.19.0/file.CHANGELOG.html
146
146
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/base
147
147
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
148
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-base/v0.18.0
148
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-base/v0.19.0
149
149
  post_install_message:
150
150
  rdoc_options: []
151
151
  require_paths: