-
Notifications
You must be signed in to change notification settings - Fork 3
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-71431: refactor log msg and remove unused code #115
Changes from 4 commits
f51af88
9246774
d446d33
cc079e3
2978ac8
3a72f2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,69 +5,73 @@ | |
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
|
||
begin | ||
require 'solarwinds_apm/version' | ||
require 'solarwinds_apm/logger' | ||
if ENV.fetch('SW_APM_ENABLED', 'true') == 'false' | ||
SolarWindsAPM.logger.warn 'SW_APM_ENABLED environment variable detected and was set to false; SolarWindsAPM disabled' | ||
return | ||
end | ||
|
||
require 'solarwinds_apm/version' | ||
require 'solarwinds_apm/thread_local' | ||
require 'solarwinds_apm/support_report' | ||
require 'solarwinds_apm/constants' | ||
require 'solarwinds_apm/api' | ||
require 'solarwinds_apm/base' | ||
require 'solarwinds_apm/logger' | ||
require 'solarwinds_apm/config' | ||
|
||
SolarWindsAPM::Config.load_config_file | ||
SolarWindsAPM.loaded = false | ||
begin | ||
if /linux/.match?(RUBY_PLATFORM) | ||
require_relative './libsolarwinds_apm.so' | ||
require 'solarwinds_apm/oboe_init_options' | ||
require_relative './oboe_metal' # initialize Reporter; sets SolarWindsAPM.loaded = true if successful | ||
require 'solarwinds_apm/config' | ||
SolarWindsAPM::Config.load_config_file | ||
|
||
require_relative './libsolarwinds_apm.so' # load c-lib oboe | ||
require 'solarwinds_apm/oboe_init_options' # setup oboe reporter options | ||
require_relative './oboe_metal' # initialize reporter: SolarWindsAPM.loaded = true | ||
|
||
SolarWindsAPM.logger.info '===================================================================' | ||
SolarWindsAPM.logger.info "SolarWindsAPM info: Platform #{RUBY_PLATFORM}." | ||
xuan-cao-swi marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also add a log message about the Ruby version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
SolarWindsAPM.logger.info "Current solarwinds_apm version: #{SolarWindsAPM::Version::STRING}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to also detect and log out the OTel API/SDK versions (and possibly the instrumentation-all version) installed, seems useful for troubleshooting. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. also updated the test page.
|
||
SolarWindsAPM.logger.info '===================================================================' | ||
|
||
SolarWindsAPM::Reporter.start # start the reporter, any issue will be logged | ||
|
||
if SolarWindsAPM.loaded | ||
require 'solarwinds_apm/constants' | ||
require 'solarwinds_apm/api' | ||
require 'solarwinds_apm/support' | ||
require 'solarwinds_apm/opentelemetry' | ||
require 'solarwinds_apm/otel_config' | ||
|
||
if ENV['SW_APM_AUTO_CONFIGURE'] != 'false' | ||
SolarWindsAPM::OTelConfig.initialize | ||
elsif ENV['SW_APM_AUTO_CONFIGURE'] == 'false' | ||
SolarWindsAPM.logger.warn '==============================================================' | ||
SolarWindsAPM.logger.warn 'SW_APM_AUTO_CONFIGURE set to false.' | ||
SolarWindsAPM.logger.warn 'You need to initialize Ruby library in application with' | ||
SolarWindsAPM.logger.warn 'SolarWindsAPM::OTelConfig.initialize_with_config do |config|' | ||
SolarWindsAPM.logger.warn ' config[key] = value' | ||
SolarWindsAPM.logger.warn 'end' | ||
SolarWindsAPM.logger.warn 'See: https://github.com/solarwinds/apm-ruby/blob/main/CONFIGURATION.md#in-code-configuration' | ||
SolarWindsAPM.logger.warn "\e[1mPlease discard this message if application have already taken this action.\e[0m" | ||
SolarWindsAPM.logger.warn '==============================================================' | ||
end | ||
else | ||
require 'solarwinds_apm/noop' | ||
SolarWindsAPM.logger.warn '==============================================================' | ||
SolarWindsAPM.logger.warn 'SolarWindsAPM not loaded. Tracing disabled.' | ||
SolarWindsAPM.logger.warn 'There may be a problem with the service key or other settings.' | ||
SolarWindsAPM.logger.warn 'Please check previous log messages.' | ||
SolarWindsAPM.logger.warn '==============================================================' | ||
end | ||
else | ||
SolarWindsAPM.logger.warn '===================================================================' | ||
SolarWindsAPM.logger.warn "SolarWindsAPM warning: Platform #{RUBY_PLATFORM} not yet supported." | ||
SolarWindsAPM.logger.warn "SolarWindsAPM warning: Platform #{RUBY_PLATFORM} not yet supported on current solarwinds_apm #{SolarWindsAPM::Version::STRING}" | ||
SolarWindsAPM.logger.warn 'see: https://documentation.solarwinds.com/en/success_center/observability/default.htm#cshid=config-ruby-agent' | ||
SolarWindsAPM.logger.warn 'Tracing disabled.' | ||
SolarWindsAPM.logger.warn 'Contact technicalsupport@solarwinds.com if this is unexpected.' | ||
SolarWindsAPM.logger.warn '===================================================================' | ||
end | ||
rescue LoadError => e | ||
unless ENV['RAILS_GROUP'] == 'assets' || ENV['SW_APM_NO_LIBRARIES_WARNING'] | ||
SolarWindsAPM.logger.error '==============================================================' | ||
SolarWindsAPM.logger.error 'Missing SolarWindsAPM libraries. Tracing disabled.' | ||
SolarWindsAPM.logger.error "Error: #{e.message}" | ||
SolarWindsAPM.logger.error 'See: https://documentation.solarwinds.com/en/success_center/observability/default.htm#cshid=config-ruby-agent' | ||
SolarWindsAPM.logger.error '==============================================================' | ||
end | ||
end | ||
|
||
if SolarWindsAPM.loaded | ||
require 'solarwinds_apm/support' | ||
require 'solarwinds_apm/opentelemetry' | ||
require 'solarwinds_apm/otel_config' | ||
if ENV['SW_APM_AUTO_CONFIGURE'] == 'false' | ||
SolarWindsAPM.logger.warn "SolarWindsAPM warning: Ruby library is not initilaized. | ||
You may need to initialize Ruby library in application like the following: | ||
SolarWindsAPM::OTelConfig.initialize_with_config do |config| | ||
... | ||
end" | ||
else | ||
SolarWindsAPM::OTelConfig.initialize | ||
end | ||
|
||
SolarWindsAPM::Reporter.start | ||
else | ||
SolarWindsAPM.logger.warn '==============================================================' | ||
SolarWindsAPM.logger.warn 'SolarWindsAPM not loaded. Tracing disabled.' | ||
SolarWindsAPM.logger.warn 'There may be a problem with the service key or other settings.' | ||
SolarWindsAPM.logger.warn 'Please check previous log messages.' | ||
SolarWindsAPM.logger.warn '==============================================================' | ||
require 'solarwinds_apm/noop/context' | ||
require 'solarwinds_apm/noop/metadata' | ||
SolarWindsAPM.logger.error '==============================================================' | ||
SolarWindsAPM.logger.error 'Missing SolarWindsAPM libraries or components. Tracing disabled.' | ||
SolarWindsAPM.logger.error "Error: #{e.message}" | ||
SolarWindsAPM.logger.error 'See: https://documentation.solarwinds.com/en/success_center/observability/default.htm#cshid=config-ruby-agent' | ||
SolarWindsAPM.logger.error '==============================================================' | ||
end | ||
|
||
rescue StandardError => e | ||
$stderr.puts "[solarwinds_apm/error] Problem loading: #{e.inspect}" | ||
$stderr.puts e.backtrace | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ module API | |
extend SolarWindsAPM::API::OpenTelemetry | ||
extend SolarWindsAPM::API::CustomMetrics | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,4 @@ def in_span(name, attributes: nil, links: nil, start_timestamp: nil, kind: nil, | |
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,4 @@ def solarwinds_ready?(wait_milliseconds=3000, integer_response: false) | |
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# © 2023 SolarWinds Worldwide, LLC. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
|
||
require_relative './noop/context' | ||
require_relative './noop/metadata' | ||
require_relative './noop/reporter' | ||
require_relative './noop/span' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,4 +173,4 @@ def calculate_span_time(start_time: nil, end_time: nil) | |
end | ||
end | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why github auto-remove the newline... |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,4 +291,4 @@ def otel_sampled?(otel_decision) | |
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems safer to keep this initialization of
loaded
to false, any reason to remove?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I changed the structure of SolarWindsAPM module (oboe_metal.rb) that initialize the loaded as false; so its default will be false as always. It will change to true once reporter initialization process finished without any issue.