Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NH-65512: try to fix the in_span issue #87

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions test/api/opentelemetry_inspan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,73 @@

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
xuan-cao-swi marked this conversation as resolved.
Show resolved Hide resolved
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)
end

it 'test_in_span_wrapper_from_solarwinds_apm' do

in_memory_exporter = ::OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.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 = extract_span(in_memory_exporter)

_(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 = ::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(
::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 = extract_span(in_memory_exporter)

_(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 = ::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(
::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 = extract_span(in_memory_exporter)
_(finished_spans.size).must_equal 0

in_memory_exporter.shutdown
end
end
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 @@
end
end


Fixed Show fixed Hide fixed
##
# extract_span
#
# get finished_span from exporter that overcome time issue
#
def extract_span(exporter)
Fixed Show fixed Hide fixed
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
Loading