Skip to content

Commit

Permalink
NH-65512: try to fix the in_span issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xuan-cao-swi committed Oct 25, 2023
1 parent d7ff935 commit e64e7df
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions test/api/opentelemetry_inspan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,68 @@

describe 'SolarWinds Set Transaction Name Test' do
before do
ENV['OTEL_SERVICE_NAME'] = 'my_service'
@op = -> { 10.times {[9, 6, 12, 2, 7, 1, 9, 3, 4, 14, 5, 8].sort} }
@in_memory_exporter = CustomInMemorySpanExporter.new(recording: false)
@op = -> { 1.times {[9, 6, 12, 2, 7, 1, 9, 3, 4, 14, 5, 8].sort} }

Check warning

Code scanning / Rubocop

Checks for useless `Integer#times` calls. Warning test

Lint/UselessTimes: Useless call to 1.times detected.
end

it 'test_in_span_wrapper_from_solarwinds_apm' do

in_memory_exporter = CustomInMemorySpanExporter.new
OpenTelemetry::SDK.configure do |c|
c.service_name = 'my_service'
c.add_span_processor(::OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(@in_memory_exporter))
c.service_name = 'test_in_span_wrapper_from_solarwinds_apm'
c.add_span_processor(
::OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
in_memory_exporter))
end
end

after do
ENV['OTEL_SERVICE_NAME'] = nil
end

it 'test_in_span_wrapper_from_solarwinds_apm' do
@in_memory_exporter.recording = true
SolarWindsAPM::API.in_span('custom_span') do
@op.call
end

finished_spans = @in_memory_exporter.finished_spans
finished_spans = in_memory_exporter.finished_spans

_(finished_spans.first.name).must_equal 'custom_span'

in_memory_exporter.shutdown
end

it 'test_in_span_wrapper_from_solarwinds_apm_with_span' do
@in_memory_exporter.recording = true

in_memory_exporter = CustomInMemorySpanExporter.new
OpenTelemetry::SDK.configure do |c|
c.service_name = 'test_in_span_wrapper_from_solarwinds_apm_with_span'
c.add_span_processor(
::OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
in_memory_exporter))
end

SolarWindsAPM::API.in_span('custom_span') do |span|
span.add_attributes({"test_attribute" => "attribute_1"})
@op.call
end

finished_spans = @in_memory_exporter.finished_spans
finished_spans = in_memory_exporter.finished_spans

_(finished_spans.first.name).must_equal 'custom_span'
_(finished_spans.first.attributes['test_attribute']).must_equal 'attribute_1'

in_memory_exporter.shutdown
end

it 'test_in_span_wrapper_from_solarwinds_apm_without_block' do
@in_memory_exporter.recording = true

in_memory_exporter = CustomInMemorySpanExporter.new
OpenTelemetry::SDK.configure do |c|
c.service_name = 'test_in_span_wrapper_from_solarwinds_apm'
c.add_span_processor(
::OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(
in_memory_exporter))
end

SolarWindsAPM::API.in_span('custom_span')

finished_spans = @in_memory_exporter.finished_spans
finished_spans = in_memory_exporter.finished_spans
_(finished_spans.size).must_equal 0

in_memory_exporter.shutdown
end
end

0 comments on commit e64e7df

Please sign in to comment.