Skip to content

Commit

Permalink
fix: OTEL_TRACE -> OTEL_TRACES env vars (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbogsany authored Feb 10, 2021
1 parent dc109c7 commit f5c2e8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions sdk/lib/opentelemetry/sdk/trace/config/trace_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def initialize(sampler: sampler_from_environment(Samplers.parent_based(root: Sam
private

def sampler_from_environment(default_sampler) # rubocop:disable Metrics/CyclomaticComplexity
case ENV['OTEL_TRACE_SAMPLER']
case ENV['OTEL_TRACES_SAMPLER']
when 'always_on' then Samplers::ALWAYS_ON
when 'always_off' then Samplers::ALWAYS_OFF
when 'traceidratio' then Samplers.trace_id_ratio_based(Float(ENV.fetch('OTEL_TRACE_SAMPLER_ARG', 1.0)))
when 'traceidratio' then Samplers.trace_id_ratio_based(Float(ENV.fetch('OTEL_TRACES_SAMPLER_ARG', 1.0)))
when 'parentbased_always_on' then Samplers.parent_based(root: Samplers::ALWAYS_ON)
when 'parentbased_always_off' then Samplers.parent_based(root: Samplers::ALWAYS_OFF)
when 'parentbased_traceidratio' then Samplers.parent_based(root: Samplers.trace_id_ratio_based(Float(ENV.fetch('OTEL_TRACE_SAMPLER_ARG', 1.0))))
when 'parentbased_traceidratio' then Samplers.parent_based(root: Samplers.trace_id_ratio_based(Float(ENV.fetch('OTEL_TRACES_SAMPLER_ARG', 1.0))))
else default_sampler
end
rescue StandardError => e
Expand Down
20 changes: 10 additions & 10 deletions sdk/test/opentelemetry/sdk/trace/config/trace_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
with_env('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT' => '1',
'OTEL_SPAN_EVENT_COUNT_LIMIT' => '2',
'OTEL_SPAN_LINK_COUNT_LIMIT' => '3',
'OTEL_TRACE_SAMPLER' => 'always_on') do
'OTEL_TRACES_SAMPLER' => 'always_on') do
config = trace_config.new
_(config.sampler).must_equal samplers::ALWAYS_ON
_(config.max_attributes_count).must_equal 1
Expand All @@ -40,7 +40,7 @@
with_env('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT' => '1',
'OTEL_SPAN_EVENT_COUNT_LIMIT' => '2',
'OTEL_SPAN_LINK_COUNT_LIMIT' => '3',
'OTEL_TRACE_SAMPLER' => 'always_on') do
'OTEL_TRACES_SAMPLER' => 'always_on') do
config = trace_config.new(sampler: samplers::ALWAYS_OFF,
max_attributes_count: 10,
max_events_count: 11,
Expand All @@ -57,28 +57,28 @@
end

it 'configures samplers from environment' do
sampler = with_env('OTEL_TRACE_SAMPLER' => 'always_on') { trace_config.new.sampler }
sampler = with_env('OTEL_TRACES_SAMPLER' => 'always_on') { trace_config.new.sampler }
_(sampler).must_equal samplers::ALWAYS_ON

sampler = with_env('OTEL_TRACE_SAMPLER' => 'always_off') { trace_config.new.sampler }
sampler = with_env('OTEL_TRACES_SAMPLER' => 'always_off') { trace_config.new.sampler }
_(sampler).must_equal samplers::ALWAYS_OFF

sampler = with_env('OTEL_TRACE_SAMPLER' => 'traceidratio', 'OTEL_TRACE_SAMPLER_ARG' => '0.1') { trace_config.new.sampler }
sampler = with_env('OTEL_TRACES_SAMPLER' => 'traceidratio', 'OTEL_TRACES_SAMPLER_ARG' => '0.1') { trace_config.new.sampler }
_(sampler).must_equal samplers.trace_id_ratio_based(0.1)

sampler = with_env('OTEL_TRACE_SAMPLER' => 'traceidratio') { trace_config.new.sampler }
sampler = with_env('OTEL_TRACES_SAMPLER' => 'traceidratio') { trace_config.new.sampler }
_(sampler).must_equal samplers.trace_id_ratio_based(1.0)

sampler = with_env('OTEL_TRACE_SAMPLER' => 'parentbased_always_on') { trace_config.new.sampler }
sampler = with_env('OTEL_TRACES_SAMPLER' => 'parentbased_always_on') { trace_config.new.sampler }
_(sampler).must_equal samplers.parent_based(root: samplers::ALWAYS_ON)

sampler = with_env('OTEL_TRACE_SAMPLER' => 'parentbased_always_off') { trace_config.new.sampler }
sampler = with_env('OTEL_TRACES_SAMPLER' => 'parentbased_always_off') { trace_config.new.sampler }
_(sampler).must_equal samplers.parent_based(root: samplers::ALWAYS_OFF)

sampler = with_env('OTEL_TRACE_SAMPLER' => 'parentbased_traceidratio', 'OTEL_TRACE_SAMPLER_ARG' => '0.2') { trace_config.new.sampler }
sampler = with_env('OTEL_TRACES_SAMPLER' => 'parentbased_traceidratio', 'OTEL_TRACES_SAMPLER_ARG' => '0.2') { trace_config.new.sampler }
_(sampler).must_equal samplers.parent_based(root: samplers.trace_id_ratio_based(0.2))

sampler = with_env('OTEL_TRACE_SAMPLER' => 'parentbased_traceidratio') { trace_config.new.sampler }
sampler = with_env('OTEL_TRACES_SAMPLER' => 'parentbased_traceidratio') { trace_config.new.sampler }
_(sampler).must_equal samplers.parent_based(root: samplers.trace_id_ratio_based(1.0))
end
end
Expand Down

0 comments on commit f5c2e8d

Please sign in to comment.