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

prepare oboe_metal change for fork change #168

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 6 additions & 2 deletions lib/oboe_metal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ module SolarWindsAPM
@loaded = false
@reporter = nil
@oboe_api = nil
@init_sent = false

class << self
attr_accessor :reporter, :loaded, :oboe_api
attr_accessor :reporter, :loaded, :oboe_api, :init_sent

def sample_rate(rate)
return unless SolarWindsAPM.loaded
Expand All @@ -38,7 +39,7 @@ 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)
SolarWindsAPM.loaded = true
report_init
report_init if (options[22]).zero? # report init at beginning if no after fork enabled
rescue StandardError => e
warn e.message
SolarWindsAPM.loaded = false
Expand Down Expand Up @@ -72,10 +73,13 @@ def send_status(evt, context = nil, with_system_timestamp: true)
def report_init(layer = :rack) # :nodoc:
# Don't send __Init in test or if SolarWindsAPM
# isn't fully loaded (e.g. missing c-extension)
return if SolarWindsAPM.init_sent
return unless SolarWindsAPM.loaded

platform_info = build_swo_init_report
log_init(layer, platform_info)

SolarWindsAPM.init_sent = true
SolarWindsAPM.logger.debug { "[#{self.class}/#{__method__}] Init message has been sent." }
end

Expand Down
9 changes: 8 additions & 1 deletion lib/solarwinds_apm/oboe_init_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def initialize
@metric_format = determine_the_metric_model
# log type (0 = stderr; 1 = stdout; 2 = file; 3 = null; 4 = disabled; default = 0)
@log_type = determine_oboe_log_type
# after fork enablement (0 = no after fork, only pre-fork; 1 = after fork enabled; default = 0)
@after_fork = determine_oboe_after_fork
end

# for testing with changed ENV vars
Expand Down Expand Up @@ -97,7 +99,8 @@ def array_for_oboe
@grpc_proxy, # 18
0, # 19 arg for lambda (no lambda for ruby yet)
@metric_format, # 20
@log_type # 21
@log_type, # 21
@after_fork # 22
]
end

Expand Down Expand Up @@ -211,5 +214,9 @@ def determine_lambda
true
end
end

def determine_oboe_after_fork
ENV['SW_APM_ENABLE_AFTER_FORK'].to_s == 'true' ? 1 : 0
end
end
end
2 changes: 2 additions & 0 deletions lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def on_finish(span)

return if non_entry_span(span: span)

SolarWindsAPM::Reporter.send(:report_init) # This only happens if after_fork enabled

span_time = calculate_span_time(start_time: span.start_timestamp, end_time: span.end_timestamp)
domain = nil
has_error = error?(span)
Expand Down