Skip to content

Commit

Permalink
NH-65512: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xuan-cao-swi committed Oct 25, 2023
1 parent e64e7df commit 6433474
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/api/opentelemetry_inspan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

require 'minitest_helper'
require './lib/solarwinds_apm/api'
# act -j unit_test --container-architecture linux/arm64 -s SW_APM_SERVICE_KEY=your_key
#

describe 'SolarWinds Set Transaction Name Test' do
before do
@op = -> { 1.times {[9, 6, 12, 2, 7, 1, 9, 3, 4, 14, 5, 8].sort} }
@op = -> { 10.times {[9, 6, 12, 2, 7, 1, 9, 3, 4, 14, 5, 8].sort} }
end

it 'test_in_span_wrapper_from_solarwinds_apm' do

in_memory_exporter = CustomInMemorySpanExporter.new
in_memory_exporter = ::OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
OpenTelemetry::SDK.configure do |c|
c.service_name = 'test_in_span_wrapper_from_solarwinds_apm'
c.add_span_processor(
Expand All @@ -23,7 +25,7 @@
@op.call
end

finished_spans = in_memory_exporter.finished_spans
finished_spans = extract_span(in_memory_exporter)

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

Expand All @@ -32,7 +34,7 @@

it 'test_in_span_wrapper_from_solarwinds_apm_with_span' do

in_memory_exporter = CustomInMemorySpanExporter.new
in_memory_exporter = ::OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
OpenTelemetry::SDK.configure do |c|
c.service_name = 'test_in_span_wrapper_from_solarwinds_apm_with_span'
c.add_span_processor(
Expand All @@ -45,7 +47,7 @@
@op.call
end

finished_spans = in_memory_exporter.finished_spans
finished_spans = extract_span(in_memory_exporter)

_(finished_spans.first.name).must_equal 'custom_span'
_(finished_spans.first.attributes['test_attribute']).must_equal 'attribute_1'
Expand All @@ -55,7 +57,7 @@

it 'test_in_span_wrapper_from_solarwinds_apm_without_block' do

in_memory_exporter = CustomInMemorySpanExporter.new
in_memory_exporter = ::OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
OpenTelemetry::SDK.configure do |c|
c.service_name = 'test_in_span_wrapper_from_solarwinds_apm'
c.add_span_processor(
Expand All @@ -65,7 +67,7 @@

SolarWindsAPM::API.in_span('custom_span')

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

in_memory_exporter.shutdown
Expand Down
21 changes: 21 additions & 0 deletions test/minitest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,27 @@ def export(span_datas)
end
end


##
# extract_span
#
# get finished_span from exporter that overcome time issue
#
def extract_span(exporter)
finished_spans = []
retry_count = 5
while finished_spans.size == 0

break if retry_count > 5

finished_spans = exporter.finished_spans
retry_count += 1
sleep retry_count
end

finished_spans
end

##
# create_span_data
#
Expand Down

0 comments on commit 6433474

Please sign in to comment.