module Vx::Lib::Instrumentation
Constants
- DATE_FORMAT
- THREAD_KEY
- VERSION
Public Instance Methods
activate!()
click to toggle source
# File lib/vx/lib/instrumentation.rb, line 27 def activate! Dir[root + "/instrumentation/probe/*.rb"].each do |f| require f end end
app_name()
click to toggle source
# File lib/vx/lib/instrumentation.rb, line 19 def app_name @@app_name end
default()
click to toggle source
# File lib/vx/lib/instrumentation.rb, line 53 def default Thread.current[THREAD_KEY] || {} end
delivery(name, payload, tags, started, finished)
click to toggle source
# File lib/vx/lib/instrumentation.rb, line 79 def delivery(name, payload, tags, started, finished) Lib::Instrumentation::Logger.logger.log( ::Logger::INFO, "@event" => name, "@timestamp" => started.strftime(DATE_FORMAT), "@duration" => (finished - started).to_f, "@fields" => payload, "@tags" => tags, process_id: Process.pid, thread_id: Thread.current.object_id, app_name: app_name ) end
handle_exception(event, ex, env = {})
click to toggle source
# File lib/vx/lib/instrumentation.rb, line 57 def handle_exception(event, ex, env = {}) tags = event.split(".") tags << "exception" tags.uniq! payload = { "@event" => event, "@timestamp" => Time.now.strftime(DATE_FORMAT), "@tags" => tags, "@fields" => env, app_name: app_name, process_id: Process.pid, thread_id: Thread.current.object_id, exception: ex.class.to_s, message: ex.message.to_s, backtrace: (ex.backtrace || []).map(&:to_s).join("\n"), } notify_stderr(ex) Lib::Instrumentation::Logger.logger.error(payload) end
install(target, options = {})
click to toggle source
# File lib/vx/lib/instrumentation.rb, line 33 def install(target, options = {}) $stdout.puts " --> activate Vx::Lib::Instrumentation, log stored in #{target}" log_level = options[:log_level] || 0 @@app_name = options[:app_name] || 'default' Lib::Instrumentation::Logger.setup target Lib::Instrumentation::Logger.logger.level = log_level end
root()
click to toggle source
# File lib/vx/lib/instrumentation.rb, line 23 def root File.expand_path("../", __FILE__) end
with(new_keys) { || ... }
click to toggle source
# File lib/vx/lib/instrumentation.rb, line 43 def with(new_keys) old_keys = Thread.current[THREAD_KEY] begin Thread.current[THREAD_KEY] = (old_keys || {}).merge(new_keys) yield if block_given? ensure Thread.current[THREAD_KEY] = old_keys end end