Profiling custom Ruby scripts

For standalone scripts, context start-end needs to be marked specifically and optionally extended events can be called.

#!/usr/bin/env ruby
require 'raygun/apm'

class Hello
  def rdoc
    sleep 0.5
  end
end

tracer = Raygun::Apm::Tracer.new
tracer.udp_sink!
tracer.start_trace
Hello.new.rdoc
tracer.end_trace
tracer.process_ended

Extended events can be sent where appropiate to capture web requests and SQL queries manually.

event = Raygun::Apm::Event::HttpIn.new
event[:pid] = Process.pid
event[:tid] = 0
event[:timestamp] = tracer.now
event[:url] = 'https://google.com/'
event[:verb] = 'GET'
event[:status] = 200
event[:duration] = 1000  
tracer.emit(event)
event = Raygun::Apm::Event::Sql.new
event[:pid] = Process.pid
event[:tid] = 0
event[:timestamp] = tracer.now
event[:provider] = 'postgres'
event[:host] = 'localhost'
event[:database] = 'rails'
event[:query] = 'SELECT * from FOO;'
event[:duration] = 1000
tracer.emit(event)