=begin = datadog.rb *Copyright*:: (C) 2013 by Novu, LLC *Author(s)*:: Tamara Temple *Since*:: 2013-05-01 == Description Manage the connection and communication from the app to DataDog service. == Usage require '.../datadog.rb' class MyClass include DataDog api_key = 'Your DD API Key' dogger "Hi from MyClass!" begin # some operations rescue Exception => e dogger "Woops, an Error", :type => :error, :body => "#{e.class}: #{e}\n#{e.backtrace.join("\n")}" end # ... other class code end == Caveats This module integrates with methadone, using it's logging features in addition to sending the log message to data dog. This isn't necessarily the most robust intermingling... =end require 'dogapi' require 'methadone' module NewBackup module DataDog include Methadone::CLILogging @api_key = nil @environment = (ENV['RAILS_ENV'].nil? || ENV['RAILS_ENV'].empty?) ? 'development' : ENV['RAILS_ENV'] module_function def api_key @api_key end def api_key=(api_key) @api_key=api_key end def dogger(msg, options={}) return if msg.nil? || msg.empty? if options[:type] == :error error msg else info msg end return if @api_key.nil? || @api_key.empty? @client ||= Datadog::Client.new(@api_key) emit_options = { :msg_title => msg, :alert_type => (options[:type] == :error) ? 'Error' : 'Normal', :tags => [ "host:#{`hostname`}", "env:#{@environment}" ], :priority => 'normal', :source => 'MyApps'} body = options[:body] ||= msg @client.emit_event(Dogapi::Event.new(body, emit_options)) end end end