diff --git a/config.ru b/config.ru index 5612c837..e0be66b1 100644 --- a/config.ru +++ b/config.ru @@ -30,51 +30,5 @@ class RackTimer end end -if ENV['SKYLIGHT_APPLICATION'] - require 'skylight' - - class DalliProbe - def install - %w[get get_multi set add incr decr delete replace append prepend].each do |method_name| - next unless Dalli::Client.method_defined?(method_name.to_sym) - Dalli::Client.class_eval <<-EOD - alias #{method_name}_without_sk #{method_name} - def #{method_name}(*args, &block) - Skylight.instrument(category: "api.memcache.#{method_name}", title: "Memcache #{method_name}") do - #{method_name}_without_sk(*args, &block) - end - end - EOD - end - end - end - Skylight::Probes.register("Dalli::Client", "dalli", DalliProbe.new) - - class RedisProbe - def install - ::Redis::Client.class_eval do - alias call_without_sk call - - def call(command_parts, &block) - command = command_parts[0].upcase - - opts = { - category: "api.redis.#{command.downcase}", - title: "Redis #{command}", - annotations: { - command: command.to_s - } - } - - Skylight.instrument(opts) do - call_without_sk(command_parts, &block) - end - end - end - end - end - Skylight::Probes.register("Redis", "redis", RedisProbe.new) -end - use RackTimer run Travis::Api::App.new diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 4bb9bd21..b9b81779 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -9,7 +9,9 @@ class Travis::Api::App if ENV['SKYLIGHT_APPLICATION'] require 'skylight' - register Skylight::Sinatra + require 'travis/api/app/skylight/dalli_probe' + require 'travis/api/app/skylight/redis_probe' + register ::Skylight::Sinatra end error NotImplementedError do diff --git a/lib/travis/api/app/skylight/dalli_probe.rb b/lib/travis/api/app/skylight/dalli_probe.rb new file mode 100644 index 00000000..8a63cc95 --- /dev/null +++ b/lib/travis/api/app/skylight/dalli_probe.rb @@ -0,0 +1,24 @@ +require 'skylight' +require 'travis/api/app' + +class Travis::Api::App + module Skylight + class DalliProbe + def install + %w[get get_multi set add incr decr delete replace append prepend].each do |method_name| + next unless Dalli::Client.method_defined?(method_name.to_sym) + Dalli::Client.class_eval <<-EOD + alias #{method_name}_without_sk #{method_name} + def #{method_name}(*args, &block) + ::Skylight.instrument(category: "api.memcache.#{method_name}", title: "Memcache #{method_name}") do + #{method_name}_without_sk(*args, &block) + end + end + EOD + end + end + end + + ::Skylight::Probes.register("Dalli::Client", "dalli", DalliProbe.new) + end +end diff --git a/lib/travis/api/app/skylight/redis_probe.rb b/lib/travis/api/app/skylight/redis_probe.rb new file mode 100644 index 00000000..491e6886 --- /dev/null +++ b/lib/travis/api/app/skylight/redis_probe.rb @@ -0,0 +1,31 @@ +require 'skylight' +require 'travis/api/app' + +class Travis::Api::App + module Skylight + class RedisProbe + def install + ::Redis::Client.class_eval do + alias call_without_sk call + + def call(command_parts, &block) + command = command_parts[0].upcase + + opts = { + category: "api.redis.#{command.downcase}", + title: "Redis #{command}", + annotations: { + command: command.to_s + } + } + + ::Skylight.instrument(opts) do + call_without_sk(command_parts, &block) + end + end + end + end + end + ::Skylight::Probes.register("Redis", "redis", RedisProbe.new) + end +end