Skip to content

Commit

Permalink
Merge pull request #73 from solarwindscloud/NH-58498
Browse files Browse the repository at this point in the history
NH-58498: add more test case for ensuring OTEL_TRACES_EXPORTER is wor…
  • Loading branch information
xuan-cao-swi authored Sep 11, 2023
2 parents f938e6a + 0b72bf1 commit 23f94a5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/solarwinds_apm/otel_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def self.initialize

print_config if SolarWindsAPM.logger.level.zero?

ENV['OTEL_TRACES_EXPORTER'] = 'none' if ENV['OTEL_TRACES_EXPORTER'].nil?
ENV['OTEL_TRACES_EXPORTER'] = 'none' if ENV['OTEL_TRACES_EXPORTER'].to_s.empty?

::OpenTelemetry::SDK.configure { |c| c.use_all(@@config_map) }

Expand Down
2 changes: 1 addition & 1 deletion test/opentelemetry/solarwinds_sampler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
tracestate = ::OpenTelemetry::Trace::Tracestate.from_hash(content)
parent_context = ::OpenTelemetry::Trace::SpanContext.new(span_id: "k1\xBF6\xB7k\xA7\x8B", trace_id: "H\x86\xC9\xC2\x16\xB2\xAA \xCE0@g\x81\xA1=P", tracestate: tracestate)
trace_state = @sampler.send(:calculate_trace_state, @decision, parent_context, @xtraceoptions)
puts "trace_state #{trace_state.inspect}"

_(trace_state.to_h.keys.size).must_equal 3
_(trace_state.value("sw")).must_equal "6b31bf36b76ba78b-00"
_(trace_state.value("abc")).must_equal "cba"
Expand Down
55 changes: 44 additions & 11 deletions test/solarwinds_apm/otel_config_exporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,64 @@

SolarWindsAPM::OTelConfig.initialize
_(SolarWindsAPM::OTelConfig.class_variable_get(:@@agent_enabled)).must_equal true
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors).count).must_equal 1
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)[0].class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsProcessor
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)[0].instance_variable_get(:@exporter).class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsExporter

span_processors = ::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)
_(span_processors.count).must_equal 1
_(span_processors[0].class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsProcessor
_(span_processors[0].instance_variable_get(:@exporter).class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsExporter
end

it 'test_exporter_with_default_otlp_exporter' do

ENV['OTEL_TRACES_EXPORTER'] = 'otlp'
SolarWindsAPM::OTelConfig.initialize
_(SolarWindsAPM::OTelConfig.class_variable_get(:@@agent_enabled)).must_equal true
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors).count).must_equal 2
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)[0].class).must_equal ::OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)[0].instance_variable_get(:@exporter).class).must_equal OpenTelemetry::Exporter::OTLP::Exporter
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)[1].class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsProcessor
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)[1].instance_variable_get(:@exporter).class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsExporter
span_processors = ::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)
_(span_processors.count).must_equal 2
_(span_processors[0].class).must_equal ::OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor
_(span_processors[0].instance_variable_get(:@exporter).class).must_equal OpenTelemetry::Exporter::OTLP::Exporter
_(span_processors[1].class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsProcessor
_(span_processors[1].instance_variable_get(:@exporter).class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsExporter
end

it 'test_exporter_with_bad_exporter' do

ENV['OTEL_TRACES_EXPORTER'] = 'abcd'
SolarWindsAPM::OTelConfig.initialize
_(SolarWindsAPM::OTelConfig.class_variable_get(:@@agent_enabled)).must_equal true
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors).count).must_equal 1
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)[0].class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsProcessor
_(::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)[0].instance_variable_get(:@exporter).class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsExporter

span_processors = ::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)
_(span_processors.count).must_equal 1
_(span_processors[0].class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsProcessor
_(span_processors[0].instance_variable_get(:@exporter).class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsExporter
end

it 'test_exporter_with_zipkin_jaeger_exporter' do

ENV['OTEL_TRACES_EXPORTER'] = 'otlp,console'
SolarWindsAPM::OTelConfig.initialize
_(SolarWindsAPM::OTelConfig.class_variable_get(:@@agent_enabled)).must_equal true

span_processors = ::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)
_(span_processors.count).must_equal 3
_(span_processors[0].class).must_equal ::OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor
_(span_processors[0].instance_variable_get(:@exporter).class).must_equal OpenTelemetry::Exporter::OTLP::Exporter
_(span_processors[1].class).must_equal ::OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor
_(span_processors[1].instance_variable_get(:@span_exporter).class).must_equal ::OpenTelemetry::SDK::Trace::Export::ConsoleSpanExporter
_(span_processors[2].class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsProcessor
_(span_processors[2].instance_variable_get(:@exporter).class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsExporter
end

it 'test_exporter_with_empty_OTEL_TRACES_EXPORTER' do

ENV['OTEL_TRACES_EXPORTER'] = ''
SolarWindsAPM::OTelConfig.initialize
_(SolarWindsAPM::OTelConfig.class_variable_get(:@@agent_enabled)).must_equal true

span_processors = ::OpenTelemetry.tracer_provider.instance_variable_get(:@span_processors)
_(span_processors.count).must_equal 1
_(span_processors[0].class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsProcessor
_(span_processors[0].instance_variable_get(:@exporter).class).must_equal SolarWindsAPM::OpenTelemetry::SolarWindsExporter
end
end

0 comments on commit 23f94a5

Please sign in to comment.