module Vx::Instrumentation
Constants
- DATE_FORMAT
- THREAD_KEY
- VERSION
Public Instance Methods
activate(*probes)
click to toggle source
# File lib/vx/instrumentation.rb, line 24 def activate(*probes) probes.each do |probe| require File.expand_path("../instrumentation/probe/#{probe}", __FILE__) $stdout.puts " --> activate instrumentations for #{probe}" end end
default()
click to toggle source
# File lib/vx/instrumentation.rb, line 41 def default Thread.current[THREAD_KEY] || {} end
delivery(name, payload, tags, started, finished)
click to toggle source
# File lib/vx/instrumentation.rb, line 66 def delivery(name, payload, tags, started, finished) Vx::Instrumentation::Logger.logger.log( ::Logger::INFO, "@event" => name, process_id: Process.pid, thread_id: Thread.current.object_id, "@timestamp" => started.strftime(DATE_FORMAT), "@duration" => (finished - started).to_f, "@fields" => payload, "@tags" => tags ) end
handle_exception(event, ex, env = {})
click to toggle source
# File lib/vx/instrumentation.rb, line 45 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, 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) Vx::Instrumentation::Logger.logger.error(payload) end
install(target, log_level = 0)
click to toggle source
# File lib/vx/instrumentation.rb, line 18 def install(target, log_level = 0) $stdout.puts " --> activate Vx::Instrumentation, log stored in #{target}" Instrumentation::Logger.setup target Instrumentation::Logger.logger.level = log_level end
with(new_keys) { || ... }
click to toggle source
# File lib/vx/instrumentation.rb, line 31 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