class Datadog::Profiling::Tasks::Exec

Wraps command with Datadog tracing

def exec_with_error_handling(args)

* https://github.com/rubygems/rubygems/blob/dd93966cac224532035deda533cba2685dfa30cc/bundler/lib/bundler/cli/exec.rb#L45
* https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
See also:
follow the same status codes as the shell uses
If there's an error here, rather than throwing a cryptic stack trace, let's instead have clearer messages, and
def exec_with_error_handling(args)
  Kernel.exec(*args)
rescue Errno::ENOENT => e
  Kernel.warn "ddtracerb exec failed: #{e.class.name} #{e.message} (command was '#{args.join(' ')}')"
  Kernel.exit 127
rescue Errno::EACCES, Errno::ENOEXEC => e
  Kernel.warn "ddtracerb exec failed: #{e.class.name} #{e.message} (command was '#{args.join(' ')}')"
  Kernel.exit 126
end

def initialize(args)

def initialize(args)
  @args = args
end

def rubyopts

def rubyopts
  [
    '-rdatadog/profiling/preload'
  ]
end

def run

def run
  set_rubyopt!
  exec_with_error_handling(args)
end

def set_rubyopt!

def set_rubyopt!
  existing_rubyopt = ENV['RUBYOPT']
  ENV['RUBYOPT'] = existing_rubyopt ? "#{existing_rubyopt} #{rubyopts.join(' ')}" : rubyopts.join(' ')
end