class Datadog::Tasks::Exec

Wraps command with Datadog tracing

Attributes

args[R]

Public Class Methods

new(args) click to toggle source
# File lib/ddtrace/tasks/exec.rb, line 8
def initialize(args)
  @args = args
end

Public Instance Methods

rubyopts() click to toggle source
# File lib/ddtrace/tasks/exec.rb, line 17
def rubyopts
  [
    '-rddtrace/profiling/preload'
  ]
end
run() click to toggle source
# File lib/ddtrace/tasks/exec.rb, line 12
def run
  set_rubyopt!
  exec_with_error_handling(args)
end

Private Instance Methods

exec_with_error_handling(args) click to toggle source

If there's an error here, rather than throwing a cryptic stack trace, let's instead have clearer messages, and follow the same status codes as the shell uses See also:

# File lib/ddtrace/tasks/exec.rb, line 36
def exec_with_error_handling(args)
  Kernel.exec(*args)
rescue Errno::ENOENT => e
  Kernel.warn "ddtracerb exec failed: #{e.message} (command was '#{args.join(' ')}')"
  Kernel.exit 127
rescue Errno::EACCES, Errno::ENOEXEC => e
  Kernel.warn "ddtracerb exec failed: #{e.message} (command was '#{args.join(' ')}')"
  Kernel.exit 126
end
set_rubyopt!() click to toggle source
# File lib/ddtrace/tasks/exec.rb, line 25
def set_rubyopt!
  existing_rubyopt = ENV['RUBYOPT']

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