Skip to content

Commit 21d3751

Browse files
committed
merge
1 parent a3329e2 commit 21d3751

File tree

6 files changed

+47
-56
lines changed

6 files changed

+47
-56
lines changed

lib/oboe_metal.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def start
3939
options = SolarWindsAPM::OboeInitOptions.instance.array_for_oboe # creates an array with the options in the right order
4040
SolarWindsAPM.reporter = Oboe_metal::Reporter.new(*options)
4141
SolarWindsAPM.loaded = true
42-
report_init if (options[22]).zero? # report init at beginning if no after fork enabled
42+
report_init if options[22].zero? # report init at beginning if no after fork enabled
4343
rescue StandardError => e
4444
warn e.message
4545
SolarWindsAPM.loaded = false

lib/solarwinds_apm/api/tracing.rb

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,20 @@ module Tracing
2727
# === Argument:
2828
#
2929
# * +wait_milliseconds+ - (int, default 3000) the maximum time to wait in milliseconds
30-
# * +integer_response+ - (boolean, default false) determine whether return status code of reporter or not
3130
#
3231
# === Example:
3332
#
3433
# unless SolarWindsAPM::API.solarwinds_ready?(10_000)
3534
# Logger.info "SolarWindsAPM not ready after 10 seconds, no metrics will be sent"
3635
# end
3736
#
38-
# # with status code print out
39-
# status = SolarWindsAPM::API.solarwinds_ready?(10_000, integer_response: true)
40-
# unless status == 1
41-
# Logger.info "SolarWindsAPM not ready after 10 seconds, no metrics will be sent. Error code "#{status}"
42-
# end
43-
#
4437
# === Returns:
45-
# * Boolean (if integer_response: false)
46-
# * Integer (if integer_response: true)
38+
# * Boolean
4739
#
48-
def solarwinds_ready?(wait_milliseconds = 3000, integer_response: false)
49-
if SolarWindsAPM::OTelConfig[:metrics_processor].nil?
50-
# OTelConfig not initialize, use sampler solarwinds_ready from http sampler
51-
sampler_solarwinds_ready?(wait_milliseconds)
52-
else
53-
oboe_solarwinds_ready?(wait_milliseconds, integer_response: integer_response)
54-
end
55-
end
56-
57-
def oboe_solarwinds_ready?(wait_milliseconds = 3000, integer_response: false)
58-
return false unless SolarWindsAPM.loaded
59-
60-
is_ready = SolarWindsAPM::Context.isReady(wait_milliseconds)
61-
integer_response ? is_ready : is_ready == 1
62-
end
63-
64-
def sampler_solarwinds_ready?(wait_milliseconds = 3000)
40+
def solarwinds_ready?(wait_milliseconds = 3000)
6541
root_sampler = ::OpenTelemetry.tracer_provider.sampler.instance_variable_get(:@root)
6642
is_ready = root_sampler.wait_until_ready(wait_milliseconds / 1000)
43+
puts "is_ready: #{is_ready}"
6744
!!is_ready
6845
end
6946
end

lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def create_xtraceoptions_response_value(liboboe_decision, parent_span_context, x
222222
if xtraceoptions.trigger_trace
223223
# If a traceparent header was provided then oboe does not generate the message
224224
tracestring = Utils.traceparent_from_context(parent_span_context) if parent_span_context.valid? && parent_span_context.remote?
225-
trigger_msg = tracestring && (liboboe_decision['decision_type']).zero? ? XTRACEOPTIONS_RESP_TRIGGER_IGNORED : liboboe_decision['status_msg']
225+
trigger_msg = tracestring && liboboe_decision['decision_type'].zero? ? XTRACEOPTIONS_RESP_TRIGGER_IGNORED : liboboe_decision['status_msg']
226226
SolarWindsAPM.logger.debug do
227227
"[#{self.class}/#{__method__}] tracestring: #{tracestring}; trigger_msg: #{trigger_msg}"
228228
end

lib/solarwinds_apm/sampling/sampler.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@ def wait_until_ready(timeout = 10)
3535
thread = Thread.new { settings_ready }
3636
thread.join(timeout) || (thread.kill
3737
false)
38+
@ready
3839
end
3940

40-
def settings_ready
41+
def settings_ready(timeout = 10)
42+
deadline = Time.now
4143
loop do
4244
break unless @settings.empty?
45+
46+
sleep 0.1
47+
break if (Time.now - deadline).round(0) >= timeout
4348
end
49+
@ready = true unless @settings[:signature_key].nil?
4450
end
4551

4652
def resolve_tracing_mode(config)

test/api/tracing_ready_test.rb

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,50 @@
66
require 'minitest_helper'
77
require 'minitest/mock'
88
require './lib/solarwinds_apm/api'
9+
require './lib/solarwinds_apm/sampling'
10+
require 'sampling_test_helper'
911

1012
describe 'Test solarwinds_ready API call' do
11-
it 'default_test_solarwinds_ready' do
12-
SolarWindsAPM::Context.stub(:isReady, 1) do
13-
_(SolarWindsAPM::API.solarwinds_ready?).must_equal true
14-
end
15-
end
16-
17-
it 'solarwinds_ready_with_5000_wait_time' do
18-
SolarWindsAPM::Context.stub(:isReady, 1) do
19-
_(SolarWindsAPM::API.solarwinds_ready?(5000)).must_equal true
20-
end
13+
let(:tracer) { OpenTelemetry.tracer_provider.tracer('test') }
14+
before do
15+
ENV['OTEL_TRACES_EXPORTER'] = 'none'
16+
OpenTelemetry::SDK.configure
17+
18+
@memory_exporter = OpenTelemetry::SDK::Trace::Export::InMemorySpanExporter.new
19+
OpenTelemetry.tracer_provider.add_span_processor(OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor.new(@memory_exporter))
20+
21+
@config = {
22+
collector: 'https://apm.collector.st-ssp.solarwinds.com:443',
23+
service: 'test-ruby',
24+
headers: "Bearer #{ENV.fetch('APM_RUBY_TEST_STAGING_KEY', nil)}",
25+
tracing_mode: true,
26+
trigger_trace_enabled: true
27+
}
2128
end
2229

23-
it 'solarwinds_ready_with_5000_wait_time_and_int_response' do
24-
SolarWindsAPM::Context.stub(:isReady, 1) do
25-
_(SolarWindsAPM::API.solarwinds_ready?(5000, integer_response: true)).must_equal 1
26-
end
30+
after do
31+
OpenTelemetry::TestHelpers.reset_opentelemetry
32+
@memory_exporter.reset
2733
end
2834

29-
it 'solarwinds_ready_with_default_wait_time_and_int_response' do
30-
SolarWindsAPM::Context.stub(:isReady, 1) do
31-
_(SolarWindsAPM::API.solarwinds_ready?(integer_response: true)).must_equal 1
32-
end
35+
it 'default_test_solarwinds_ready' do
36+
new_config = @config.dup
37+
sampler = SolarWindsAPM::HttpSampler.new(new_config)
38+
replace_sampler(sampler)
39+
_(SolarWindsAPM::API.solarwinds_ready?).must_equal true
3340
end
3441

35-
it 'solarwinds_ready_with_default_wait_time_and_int_response_as_4' do
36-
SolarWindsAPM::Context.stub(:isReady, 4) do
37-
_(SolarWindsAPM::API.solarwinds_ready?(integer_response: true)).must_equal 4
38-
end
42+
it 'solarwinds_ready_with_5000_wait_time' do
43+
new_config = @config.dup
44+
sampler = SolarWindsAPM::HttpSampler.new(new_config)
45+
replace_sampler(sampler)
46+
_(SolarWindsAPM::API.solarwinds_ready?(5000)).must_equal true
3947
end
4048

41-
it 'solarwinds_ready_with_default_wait_time_and_int_response_as_false' do
42-
SolarWindsAPM::Context.stub(:isReady, 1) do
43-
_(SolarWindsAPM::API.solarwinds_ready?(integer_response: false)).must_equal true
44-
end
49+
it 'solarwinds_ready_with_invalid_collector' do
50+
new_config = @config.merge(collector: URI('https://collector.invalid'))
51+
sampler = SolarWindsAPM::HttpSampler.new(new_config)
52+
replace_sampler(sampler)
53+
_(SolarWindsAPM::API.solarwinds_ready?(100_000)).must_equal false
4554
end
4655
end

test/sampling/http_sampler_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Copyright (c) 2025 SolarWinds, LLC.
44
# All rights reserved.
55

6-
# BUNDLE_GEMFILE=gemfiles/unit.gemfile bundle exec ruby -I test test/sampling/http_sampler_test.rb
76
require 'minitest_helper'
87
require './lib/solarwinds_apm/sampling'
98
require 'sampling_test_helper'

0 commit comments

Comments
 (0)