From 37f21025135aea4391274fb7b99cb3b0b0b3b28e Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 00:09:09 -0500 Subject: [PATCH 01/10] Add Skylight stuff --- Gemfile | 1 + Gemfile.lock | 3 +++ config.ru | 13 +++++++++++++ lib/travis/api/app/base.rb | 2 +- lib/travis/api/app/extensions/skylight.rb | 18 ++++++++++++++++++ tmp/.gitkeep | 0 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 lib/travis/api/app/extensions/skylight.rb create mode 100644 tmp/.gitkeep diff --git a/Gemfile b/Gemfile index 58bc4852..4cc2c1d3 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem 'bunny', '~> 0.8.0' gem 'dalli' gem 'pry' gem 'metriks', '0.9.9.5' +gem 'skylight' group :test do gem 'rspec', '~> 2.13' diff --git a/Gemfile.lock b/Gemfile.lock index 3dfced19..6050f13c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -251,6 +251,8 @@ GEM rack-test sinatra (~> 1.4.0) tilt (~> 1.3) + skylight (0.3.10) + activesupport (>= 3.0.0) slop (3.4.7) sprockets (2.2.2) hike (~> 1.2) @@ -299,6 +301,7 @@ DEPENDENCIES sentry-raven! sinatra sinatra-contrib + skylight travis-api! travis-core! travis-sidekiqs! diff --git a/config.ru b/config.ru index e0be66b1..3e624c3c 100644 --- a/config.ru +++ b/config.ru @@ -30,5 +30,18 @@ class RackTimer end end +if ENV['SKYLIGHT_APPLICATION'] + require 'skylight' + require 'logger' + config = Skylight::Config.load(nil, ENV['RACK_ENV'], ENV) + config['root'] = File.expand_path('..', __FILE__) + config['agent.sockfile_path'] = File.expand_path('../tmp', __FILE__) + config.logger = Logger.new(STDOUT) + config.validate! + Skylight.start!(config) + + use Skylight::Middleware +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 082be3ea..99f0518d 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -44,7 +44,7 @@ class Travis::Api::App disable :protection, :logging, :setup enable :raise_errors # disable :dump_errors - register :subclass_tracker, :expose_pattern + register :subclass_tracker, :expose_pattern, :skylight helpers :respond_with, :mime_types end diff --git a/lib/travis/api/app/extensions/skylight.rb b/lib/travis/api/app/extensions/skylight.rb new file mode 100644 index 00000000..1ba19304 --- /dev/null +++ b/lib/travis/api/app/extensions/skylight.rb @@ -0,0 +1,18 @@ +require 'travis/api/app' +require 'skylight' + +class Travis::Api::App + module Extensions + module Skylight + def route(verb, path, *) + condition do + trace = ::Skylight::Instrumenter.instance.current_trace + endpoint = settings.name.to_s.split("::", 5).last.gsub(/::/, "/").downcase + trace.endpoint = "#{verb} /#{endpoint}#{path}" + end + + super + end + end + end +end diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 00000000..e69de29b From 738cbb54d38f59fd80bfe7ad5ae11cbc780149fb Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 03:08:22 -0500 Subject: [PATCH 02/10] Add Dalli instrumentation to Skylight --- config.ru | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/config.ru b/config.ru index 3e624c3c..c617e0ca 100644 --- a/config.ru +++ b/config.ru @@ -32,12 +32,31 @@ end if ENV['SKYLIGHT_APPLICATION'] require 'skylight' + require 'skylight/probes/net_http' require 'logger' config = Skylight::Config.load(nil, ENV['RACK_ENV'], ENV) config['root'] = File.expand_path('..', __FILE__) config['agent.sockfile_path'] = File.expand_path('../tmp', __FILE__) config.logger = Logger.new(STDOUT) config.validate! + + 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) + Skylight.start!(config) use Skylight::Middleware From 749ee8b943c6c0d74013d25fc8217d27cc17d2e0 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 04:14:19 -0500 Subject: [PATCH 03/10] skylight: only load extension if skylight is available --- lib/travis/api/app/extensions/skylight.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/travis/api/app/extensions/skylight.rb b/lib/travis/api/app/extensions/skylight.rb index 1ba19304..5496fd45 100644 --- a/lib/travis/api/app/extensions/skylight.rb +++ b/lib/travis/api/app/extensions/skylight.rb @@ -1,14 +1,15 @@ require 'travis/api/app' -require 'skylight' class Travis::Api::App module Extensions module Skylight def route(verb, path, *) condition do - trace = ::Skylight::Instrumenter.instance.current_trace - endpoint = settings.name.to_s.split("::", 5).last.gsub(/::/, "/").downcase - trace.endpoint = "#{verb} /#{endpoint}#{path}" + if ENV['SKYLIGHT_APPLICATION'] + trace = ::Skylight::Instrumenter.instance.current_trace + endpoint = settings.name.to_s.split("::", 5).last.gsub(/::/, "/").downcase + trace.endpoint = "#{verb} /#{endpoint}#{path}" + end end super From 610d38517187b6ba3b7fe0601b16cc3ecb8ce901 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 04:33:02 -0500 Subject: [PATCH 04/10] skylight: Add Redis probe --- config.ru | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/config.ru b/config.ru index c617e0ca..a1ed6919 100644 --- a/config.ru +++ b/config.ru @@ -57,6 +57,31 @@ if ENV['SKYLIGHT_APPLICATION'] 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) + Skylight.start!(config) use Skylight::Middleware From da92cfd6407d4cd64b66b7c362a07ed67c8282a4 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 05:25:00 -0500 Subject: [PATCH 05/10] Remove New Relic --- Gemfile.lock | 2 -- config/newrelic.yml | 39 -------------------------------------- lib/travis/api/app/base.rb | 6 ------ script/console | 2 -- travis-api.gemspec | 2 -- 5 files changed, 51 deletions(-) delete mode 100644 config/newrelic.yml diff --git a/Gemfile.lock b/Gemfile.lock index 6050f13c..d218472b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,7 +69,6 @@ PATH travis-api (0.0.1) backports (~> 2.5) memcachier - newrelic_rpm (~> 3.6.6) pg (~> 0.13.2) rack-contrib (~> 1.1) rack-ssl (~> 1.3, >= 1.3.3) @@ -175,7 +174,6 @@ GEM multipart-post (2.0.0) net-http-persistent (2.9.4) net-http-pipeline (1.0.1) - newrelic_rpm (3.6.9.171) pg (0.13.2) polyglot (0.3.4) proxies (0.2.1) diff --git a/config/newrelic.yml b/config/newrelic.yml deleted file mode 100644 index d1ab9cd0..00000000 --- a/config/newrelic.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- -staging: - error_collector: - capture_source: true - enabled: true - ignore_errors: ActionController::RoutingError - apdex_t: 0.5 - ssl: false - monitor_mode: true - license_key: <%= ENV["NEW_RELIC_LICENSE_KEY"] %> - developer_mode: false - app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> - transaction_tracer: - record_sql: obfuscated - enabled: true - stack_trace_threshold: 0.5 - transaction_threshold: apdex_f - capture_params: false - log_level: info - -production: - error_collector: - capture_source: true - enabled: true - ignore_errors: ActionController::RoutingError - apdex_t: 0.5 - ssl: false - monitor_mode: true - license_key: <%= ENV["NEW_RELIC_LICENSE_KEY"] %> - developer_mode: false - app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> - transaction_tracer: - record_sql: obfuscated - enabled: true - stack_trace_threshold: 0.5 - transaction_threshold: apdex_f - capture_params: false - log_level: info - diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index 99f0518d..e197bfe6 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -7,12 +7,6 @@ class Travis::Api::App class Base < Sinatra::Base register Extensions::SmartConstants - configure :production do - require 'newrelic_rpm' - ::NewRelic::Agent.manual_start() - ::NewRelic::Agent.after_fork(:force_reconnect => true) - end - error NotImplementedError do content_type :txt status 501 diff --git a/script/console b/script/console index 3d9291dd..fd1fd99c 100755 --- a/script/console +++ b/script/console @@ -1,8 +1,6 @@ #!/usr/bin/env ruby # encoding: UTF-8 -ENV["NEWRELIC_ENABLE"] = "false" - require 'bundler/setup' require 'travis/api/app' require 'pry' diff --git a/travis-api.gemspec b/travis-api.gemspec index 58460613..43570731 100644 --- a/travis-api.gemspec +++ b/travis-api.gemspec @@ -55,7 +55,6 @@ Gem::Specification.new do |s| "bin/start-nginx", "config.ru", "config/database.yml", - "config/newrelic.yml", "config/nginx.conf.erb", "config/puma-config.rb", "config/unicorn.rb", @@ -174,7 +173,6 @@ Gem::Specification.new do |s| s.add_dependency 'backports', '~> 2.5' s.add_dependency 'pg', '~> 0.13.2' - s.add_dependency 'newrelic_rpm', '~> 3.6.6' s.add_dependency 'thin', '~> 1.4' s.add_dependency 'sinatra', '~> 1.3' s.add_dependency 'sinatra-contrib', '~> 1.3' From e698e01f7c62929254aa4c34d55b5c09bcd6e278 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 05:27:42 -0500 Subject: [PATCH 06/10] Update travis-support This is needed so travis-support does not fail on loading NewRelic RPM. --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d218472b..f74969a5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -53,7 +53,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-support.git - revision: d2cce5dbbee64fb1574386b16da3768feadb372a + revision: d37220d766a3fb218f0f8e60ab8764034f6b376f specs: travis-support (0.0.1) From 208a8248f757c8c876d25948939d774412af07f4 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 06:07:25 -0500 Subject: [PATCH 07/10] skylight: refactor more into extension --- config.ru | 11 ----------- lib/travis/api/app/base.rb | 6 +++++- lib/travis/api/app/extensions/skylight.rb | 22 +++++++++++++++++----- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/config.ru b/config.ru index a1ed6919..5612c837 100644 --- a/config.ru +++ b/config.ru @@ -32,13 +32,6 @@ end if ENV['SKYLIGHT_APPLICATION'] require 'skylight' - require 'skylight/probes/net_http' - require 'logger' - config = Skylight::Config.load(nil, ENV['RACK_ENV'], ENV) - config['root'] = File.expand_path('..', __FILE__) - config['agent.sockfile_path'] = File.expand_path('../tmp', __FILE__) - config.logger = Logger.new(STDOUT) - config.validate! class DalliProbe def install @@ -81,10 +74,6 @@ if ENV['SKYLIGHT_APPLICATION'] end end Skylight::Probes.register("Redis", "redis", RedisProbe.new) - - Skylight.start!(config) - - use Skylight::Middleware end use RackTimer diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index e197bfe6..b21b860c 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -7,6 +7,10 @@ class Travis::Api::App class Base < Sinatra::Base register Extensions::SmartConstants + if ENV['SKYLIGHT_APPLICATION'] + register :skylight + end + error NotImplementedError do content_type :txt status 501 @@ -38,7 +42,7 @@ class Travis::Api::App disable :protection, :logging, :setup enable :raise_errors # disable :dump_errors - register :subclass_tracker, :expose_pattern, :skylight + register :subclass_tracker, :expose_pattern helpers :respond_with, :mime_types end diff --git a/lib/travis/api/app/extensions/skylight.rb b/lib/travis/api/app/extensions/skylight.rb index 5496fd45..1d59ded2 100644 --- a/lib/travis/api/app/extensions/skylight.rb +++ b/lib/travis/api/app/extensions/skylight.rb @@ -1,15 +1,27 @@ +require 'logger' +require 'skylight' require 'travis/api/app' class Travis::Api::App module Extensions module Skylight + def self.registered(base) + config = ::Skylight::Config.load(nil, ENV['RACK_ENV'], ENV) + config['root'] = base.root + config['agent.sockfile_path'] = File.join(config['root'], 'tmp') + config.logger = Logger.new(STDOUT) + config.validate! + + ::Skylight.start!(config) + + base.use ::Skylight::Middleware + end + def route(verb, path, *) condition do - if ENV['SKYLIGHT_APPLICATION'] - trace = ::Skylight::Instrumenter.instance.current_trace - endpoint = settings.name.to_s.split("::", 5).last.gsub(/::/, "/").downcase - trace.endpoint = "#{verb} /#{endpoint}#{path}" - end + trace = ::Skylight::Instrumenter.instance.current_trace + endpoint = settings.name.to_s.split("::", 5).last.gsub(/::/, "/").downcase + trace.endpoint = "#{verb} /#{endpoint}#{path}" end super From 928ed11c6233a13faf5609336232a8dcc46d650b Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 14:30:04 -0500 Subject: [PATCH 08/10] skylight: use Sinatra support from skylight gem This hasn't been merged in yet, so use my fork for now. --- Gemfile | 3 ++- Gemfile.lock | 12 ++++++--- lib/travis/api/app/base.rb | 3 ++- lib/travis/api/app/extensions/skylight.rb | 31 ----------------------- 4 files changed, 13 insertions(+), 36 deletions(-) delete mode 100644 lib/travis/api/app/extensions/skylight.rb diff --git a/Gemfile b/Gemfile index 4cc2c1d3..b3237c2e 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,8 @@ gem 'bunny', '~> 0.8.0' gem 'dalli' gem 'pry' gem 'metriks', '0.9.9.5' -gem 'skylight' + +gem 'skylight', github: 'henrikhodne/skylight-ruby', branch: 'sinatra-support' group :test do gem 'rspec', '~> 2.13' diff --git a/Gemfile.lock b/Gemfile.lock index f74969a5..9668f4bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,14 @@ GIT hashie (>= 1.1.0) uuidtools +GIT + remote: git://github.com/henrikhodne/skylight-ruby.git + revision: 44904fe824e202deb6389fb9b547bd4345abdc2d + branch: sinatra-support + specs: + skylight (0.3.10) + activesupport (>= 3.0.0) + GIT remote: git://github.com/rack/rack-contrib.git revision: 951760b1710634623ebbccef8d65df9139bb41c2 @@ -249,8 +257,6 @@ GEM rack-test sinatra (~> 1.4.0) tilt (~> 1.3) - skylight (0.3.10) - activesupport (>= 3.0.0) slop (3.4.7) sprockets (2.2.2) hike (~> 1.2) @@ -299,7 +305,7 @@ DEPENDENCIES sentry-raven! sinatra sinatra-contrib - skylight + skylight! travis-api! travis-core! travis-sidekiqs! diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index b21b860c..4bb9bd21 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -8,7 +8,8 @@ class Travis::Api::App register Extensions::SmartConstants if ENV['SKYLIGHT_APPLICATION'] - register :skylight + require 'skylight' + register Skylight::Sinatra end error NotImplementedError do diff --git a/lib/travis/api/app/extensions/skylight.rb b/lib/travis/api/app/extensions/skylight.rb deleted file mode 100644 index 1d59ded2..00000000 --- a/lib/travis/api/app/extensions/skylight.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'logger' -require 'skylight' -require 'travis/api/app' - -class Travis::Api::App - module Extensions - module Skylight - def self.registered(base) - config = ::Skylight::Config.load(nil, ENV['RACK_ENV'], ENV) - config['root'] = base.root - config['agent.sockfile_path'] = File.join(config['root'], 'tmp') - config.logger = Logger.new(STDOUT) - config.validate! - - ::Skylight.start!(config) - - base.use ::Skylight::Middleware - end - - def route(verb, path, *) - condition do - trace = ::Skylight::Instrumenter.instance.current_trace - endpoint = settings.name.to_s.split("::", 5).last.gsub(/::/, "/").downcase - trace.endpoint = "#{verb} /#{endpoint}#{path}" - end - - super - end - end - end -end From 162b5b0ccac05cedbf3569055c2947d87fac1cc2 Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 14:34:20 -0500 Subject: [PATCH 09/10] skylight: extract probes from config.ru --- config.ru | 46 ---------------------- lib/travis/api/app/base.rb | 4 +- lib/travis/api/app/skylight/dalli_probe.rb | 24 +++++++++++ lib/travis/api/app/skylight/redis_probe.rb | 31 +++++++++++++++ 4 files changed, 58 insertions(+), 47 deletions(-) create mode 100644 lib/travis/api/app/skylight/dalli_probe.rb create mode 100644 lib/travis/api/app/skylight/redis_probe.rb 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 From 9b0fb64ba11558939e2fc3fad034e703d265c81e Mon Sep 17 00:00:00 2001 From: Henrik Hodne Date: Wed, 9 Apr 2014 16:47:25 -0500 Subject: [PATCH 10/10] skylight: add service probe --- lib/travis/api/app/base.rb | 1 + lib/travis/api/app/skylight/service_probe.rb | 51 ++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 lib/travis/api/app/skylight/service_probe.rb diff --git a/lib/travis/api/app/base.rb b/lib/travis/api/app/base.rb index b9b81779..93ecab1a 100644 --- a/lib/travis/api/app/base.rb +++ b/lib/travis/api/app/base.rb @@ -11,6 +11,7 @@ class Travis::Api::App require 'skylight' require 'travis/api/app/skylight/dalli_probe' require 'travis/api/app/skylight/redis_probe' + require 'travis/api/app/skylight/service_probe' register ::Skylight::Sinatra end diff --git a/lib/travis/api/app/skylight/service_probe.rb b/lib/travis/api/app/skylight/service_probe.rb new file mode 100644 index 00000000..b71dc661 --- /dev/null +++ b/lib/travis/api/app/skylight/service_probe.rb @@ -0,0 +1,51 @@ +require 'skylight' +require 'travis/api/app' + +class Travis::Api::App + module Skylight + class ServiceProbe + class ServiceProxy < Delegator + def initialize(key, service) + super(service) + @key = key + @service = service + end + + def __getobj__ + @service + end + + def __setobj__(obj) + @service = obj + end + + def run(*args) + opts = { + category: "api.service.#{@key}", + title: "Service #{@key}", + annotations: { + service: @key.to_s + } + } + + ::Skylight.instrument(opts) do + @service.run(*args) + end + end + end + + def install + Travis::Services::Helpers.class_eval do + alias service_without_sk service + + def service(key, *args) + s = service_without_sk(key, *args) + ServiceProxy.new(key, s) + end + end + end + end + + ::Skylight::Probes.register("Travis::Services::Helpers", "travis/services/helpers", ServiceProbe.new) + end +end