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-84801: fix issue of init msg not sent #135

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion lib/oboe_metal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class << self
def start
options = SolarWindsAPM::OboeInitOptions.instance.array_for_oboe # creates an array with the options in the right order
SolarWindsAPM.reporter = Oboe_metal::Reporter.new(*options)
report_init
SolarWindsAPM.loaded = true
report_init
rescue StandardError => e
warn e.message
SolarWindsAPM.loaded = false
Expand Down Expand Up @@ -76,6 +76,7 @@ def report_init(layer = :rack) # :nodoc:

platform_info = build_swo_init_report
log_init(layer, platform_info)
SolarWindsAPM.logger.debug { "[#{self.class}/#{__method__}] Init message has been sent." }
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/solarwinds_apm/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module SolarWindsAPM
module Version
MAJOR = 6 # breaking,
MINOR = 0 # feature,
PATCH = 1 # fix => BFF
PATCH = 2 # fix => BFF
PRE = nil

STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
Expand Down
71 changes: 71 additions & 0 deletions test/solarwinds_apm/oboe_metal_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

# Copyright (c) 2023 SolarWinds, LLC.
# All rights reserved.

require 'minitest_helper'

describe 'Oboe Metal Test' do
describe 'Reporter Test' do
before do
module SolarWindsAPM # rubocop:disable Lint/ConstantDefinitionInBlock
module Oboe_metal # rubocop:disable Naming/ClassAndModuleCamelCase
class Reporter
def initialize(*); end
end
end
end

require './lib/oboe_metal'
require './lib/solarwinds_apm/config'
require './lib/solarwinds_apm/oboe_init_options'
end

it 'test_report_init' do
log_output = StringIO.new
SolarWindsAPM.logger = Logger.new(log_output)
SolarWindsAPM.loaded = true
SolarWindsAPM::Reporter.send(:report_init, :rack)
assert_includes log_output.string, 'Init message has been sent.'
end

it 'test_reporter_start' do
log_output = StringIO.new
SolarWindsAPM.logger = Logger.new(log_output)
SolarWindsAPM::Reporter.start
assert_includes log_output.string, 'Init message has been sent.'
end

it 'test_build_swo_init_report_with_error' do
platform_info = SolarWindsAPM::Reporter.send(:build_swo_init_report)
_(platform_info['__Init']).must_equal true
_(platform_info['APM.Version'].nil?).must_equal false
_(platform_info['Error'].nil?).must_equal false
end

it 'test_build_swo_init_report_without_error' do
module Gem # rubocop:disable Lint/ConstantDefinitionInBlock
class Specification
def self.find_by_name(_name, *requirements)
Gem::Dependency.new('irb', *requirements).to_spec
end
end
end

SolarWindsAPM::Reporter.stub(:extension_lib_version, '0.0.1') do
platform_info = SolarWindsAPM::Reporter.send(:build_swo_init_report)
_(platform_info['__Init']).must_equal true
_(platform_info['APM.Version']).wont_be_nil
_(platform_info['APM.Extension.Version']).must_equal '0.0.1'
_(platform_info['process.executable.path']).wont_be_nil
_(platform_info['process.executable.name']).must_equal 'ruby'
_(platform_info['process.command_line']).wont_be_nil
_(platform_info['process.telemetry.path']).wont_be_nil
_(platform_info['os.type']).wont_be_nil
_(platform_info['Ruby.irb.Version']).wont_be_nil
_(platform_info['telemetry.sdk.name']).must_equal 'opentelemetry'
_(platform_info['process.runtime.name']).must_equal 'ruby'
end
end
end
end