Skip to content

NH-132896: increase test coverage#254

Open
xuan-cao-swi wants to merge 12 commits intomainfrom
NH-132896
Open

NH-132896: increase test coverage#254
xuan-cao-swi wants to merge 12 commits intomainfrom
NH-132896

Conversation

@xuan-cao-swi
Copy link
Copy Markdown
Contributor

Description

Test (if applicable)

Copy link
Copy Markdown
Contributor

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuboCop found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@xuan-cao-swi xuan-cao-swi marked this pull request as ready for review March 20, 2026 02:47
@xuan-cao-swi xuan-cao-swi requested review from a team as code owners March 20, 2026 02:47
@cheempz
Copy link
Copy Markdown
Contributor

cheempz commented Mar 24, 2026

@xuan-cao-swi any way to easily see the coverage info? Quick check there seem to be GHA integrations available.

@xuan-cao-swi
Copy link
Copy Markdown
Contributor Author

@xuan-cao-swi any way to easily see the coverage info? Quick check there seem to be GHA integrations available.

Yeah, I integrated the codecov.io

Copy link
Copy Markdown
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall i like the improvements on test description and coverage, but from spot-checking what tests are actually doing, there are gaps between what descriptions say are being tested and actual setup/assertions.

@xuan-cao-swi xuan-cao-swi requested a review from cheempz March 26, 2026 18:09
- When code under test logs warnings or errors, **stub the logger** to capture and assert the log message.
- Use `assert_equal expected, actual` form consistently. Avoid mixing `_(x).must_equal y` and `assert_equal` in the same file.
- Use `assert_match` with regex for format patterns (e.g., UUIDs, hex strings).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above on whether the instruction needs to be duplicated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xuan-cao-swi is this one really needed?

@xuan-cao-swi xuan-cao-swi requested a review from cheempz March 31, 2026 16:41
parent = make_span({ remote: true, sampled: true, sw: true })
params = make_sample_params(parent: parent)

result = sampler.should_sample?(params)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would these work?

Suggested change
result = sampler.should_sample?(params)
result = sampler.should_sample?(params)
assert_equal TEST_OTEL_SAMPLING_DECISION::RECORD_ONLY, sample.instance_variable_get(:@decision)
refute result.attributes['TriggeredTrace']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be result. I can update these assertion.

request_headers: headers
)

parent = make_span({ remote: true, sampled: false })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
parent = make_span({ remote: true, sampled: false })
# a parent decision is available but ignored because it is not from us
# i.e. no sw tracestate
parent = make_span({ remote: true, sampled: false })

buckets: {
SolarWindsAPM::BucketType::DEFAULT => { capacity: 100, rate: 10 },
SolarWindsAPM::BucketType::TRIGGER_RELAXED => { capacity: 100, rate: 10 },
SolarWindsAPM::BucketType::TRIGGER_STRICT => { capacity: 100, rate: 10 }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work to ensure relaxed bucket setting used?

Suggested change
SolarWindsAPM::BucketType::TRIGGER_STRICT => { capacity: 100, rate: 10 }
SolarWindsAPM::BucketType::TRIGGER_STRICT => { capacity: 0, rate: 0 }

flags: SolarWindsAPM::Flags::SAMPLE_START | SolarWindsAPM::Flags::TRIGGERED_TRACE,
buckets: {
SolarWindsAPM::BucketType::DEFAULT => { capacity: 100, rate: 10 },
SolarWindsAPM::BucketType::TRIGGER_RELAXED => { capacity: 100, rate: 10 },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SolarWindsAPM::BucketType::TRIGGER_RELAXED => { capacity: 100, rate: 10 },
SolarWindsAPM::BucketType::TRIGGER_RELAXED => { capacity: 0, rate: 0 },


result = sampler.should_sample?(params)
assert_equal TEST_OTEL_SAMPLING_DECISION::RECORD_AND_SAMPLE, result.instance_variable_get(:@decision)
assert_equal true, result.attributes['TriggeredTrace']
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_equal true, result.attributes['TriggeredTrace']
assert_equal true, result.attributes['TriggeredTrace']
assert_equal 'trigger-trace:ok', result.tracestate['xtrace_options_response']

assert_match(/^[0-9a-f]{16}-01$/, result.tracestate['sw'])
end

it 'updates existing tracestate for valid parent' do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not seeing how this checks an existing tracestate is updated?

assert_nil result
end

it 'logs warning from parsed settings' do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it 'logs warning from parsed settings' do
it 'updates with warning from parsed settings' do

Comment on lines +626 to +639
describe 'http_span_metadata additional' do
before do
@sampler = TestSampler.new({ local_settings: {} })
end

it 'uses defaults when attributes are missing' do
attrs = { 'http.request.method' => 'GET' }
result = @sampler.http_span_metadata(OpenTelemetry::Trace::SpanKind::SERVER, attrs)
assert result[:http]
assert_equal 'http', result[:scheme]
assert_equal 'localhost', result[:hostname]
assert_equal 0, result[:status]
end
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is making me think that the http_span_metadata method shouldn't be setting defaults when attributes are missing--the transaction filtering should just run against an empty string which would not match/filter out the request, rather than making assumptions that the request was made to http://localhost

Comment on lines +12 to +18
metric1 = Minitest::Mock.new
metric1.expect(:data_points, [])

[metric1]
# After reject!, empty metrics remain so we need the exporter
# The patch calls super if any data_points are present
# When all are empty it should return SUCCESS
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the metric1 setup here, and the comment about "empty metrics remain so we need the exporter".

tracer.in_span('test_span') do |s|
span = s
end
# Span should have finished with expected name and kind
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some way to assert that on_finishing was called in the processor?

SolarWindsAPM::Config.class_variable_get(:@@config)[:log_args] = original
end

it 'handles tracing_mode assignment' do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test seems to be confusing this with trigger tracing mode

SolarWindsAPM::Config[:log_traceId] = original
end

it 'handles string message with error-like content' do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at logger_formatter.rb it seems to handle not just error-like content that's still a String, but an actual Exception object. If so this test should be updated to reflect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants