From 3b326d6dbf1a4dd91a4dd6ff067796490c51c998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 28 Apr 2015 18:26:00 +0200 Subject: [PATCH] Add Sentry for exception tracking --- Gemfile | 1 + Gemfile.lock | 6 +++++ lib/remote_storage/swift.rb | 44 ++++++++----------------------------- liquor-cabinet.rb | 10 +++++++++ 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/Gemfile b/Gemfile index eb64702..2266ada 100644 --- a/Gemfile +++ b/Gemfile @@ -16,4 +16,5 @@ end group :staging, :production do gem "rainbows" + gem "sentry-raven" end diff --git a/Gemfile.lock b/Gemfile.lock index 6a0f7ba..aa7d813 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -21,6 +21,8 @@ GEM builder (3.2.2) eventmachine (1.0.3) excon (0.16.10) + faraday (0.9.1) + multipart-post (>= 1.2, < 3) fog (1.7.0) builder excon (~> 0.14) @@ -42,6 +44,7 @@ GEM mime-types (1.23) minitest (2.10.0) multi_json (1.10.0) + multipart-post (2.0.0) net-scp (1.0.4) net-ssh (>= 1.99.1) net-ssh (2.6.7) @@ -63,6 +66,8 @@ GEM rest-client (1.6.7) mime-types (>= 1.16) ruby-hmac (0.4.0) + sentry-raven (0.13.1) + faraday (>= 0.7.6) sinatra (1.4.5) rack (~> 1.4) rack-protection (~> 1.4) @@ -93,5 +98,6 @@ DEPENDENCIES redis rest-client riak-client! + sentry-raven sinatra (~> 1.4) sinatra-contrib diff --git a/lib/remote_storage/swift.rb b/lib/remote_storage/swift.rb index 63e73d1..8c4c696 100644 --- a/lib/remote_storage/swift.rb +++ b/lib/remote_storage/swift.rb @@ -37,13 +37,8 @@ module RemoteStorage res = do_head_request(url) set_response_headers(res) - rescue => exception - if exception.is_a? RestClient::ResourceNotFound - server.halt 404 - end - - puts exception.inspect - server.halt 499 + rescue RestClient::ResourceNotFound + server.halt 404 end def get_data(user, directory, key) @@ -57,13 +52,8 @@ module RemoteStorage server.halt 304 if none_match.include? %Q("#{res.headers[:etag]}") return res.body - rescue => exception - if exception.is_a? RestClient::ResourceNotFound - server.halt 404 - end - - puts exception.inspect - server.halt 499 + rescue RestClient::ResourceNotFound + server.halt 404 end def get_head_directory_listing(user, directory) @@ -71,13 +61,8 @@ module RemoteStorage server.headers["Content-Type"] = "application/json" server.headers["ETag"] = %Q("#{res.headers[:etag]}") - rescue => exception - if exception.is_a? RestClient::ResourceNotFound - server.halt 404 - end - - puts exception.inspect - server.halt 499 + rescue RestClient::ResourceNotFound + server.halt 404 end def get_directory_listing(user, directory) @@ -102,9 +87,6 @@ module RemoteStorage end listing.to_json - rescue => exception - puts exception.inspect - server.halt 499 end def put_data(user, directory, key, data, content_type) @@ -129,11 +111,8 @@ module RemoteStorage server.headers["ETag"] = %Q("#{res.headers[:etag]}") server.halt 200 else - server.halt 499 # TODO use sth more suitable + server.halt 500 end - rescue => exception - puts exception.inspect - server.halt 499 # TODO use sth more suitable end def delete_data(user, directory, key) @@ -149,13 +128,8 @@ module RemoteStorage delete_dir_objects(user, directory) server.halt 200 - rescue => exception - if exception.is_a? RestClient::ResourceNotFound - server.halt 404 - end - - puts exception.inspect - server.halt 499 + rescue RestClient::ResourceNotFound + server.halt 404 end private diff --git a/liquor-cabinet.rb b/liquor-cabinet.rb index 50f80c8..d74d8dd 100644 --- a/liquor-cabinet.rb +++ b/liquor-cabinet.rb @@ -30,6 +30,16 @@ class LiquorCabinet < Sinatra::Base configure :production, :staging do require "rack/common_logger" + if ENV['SENTRY_DSN'] + require "raven" + + Raven.configure do |config| + config.dsn = ENV['SENTRY_DSN'] + config.tags = { environment: settings.environment.to_s } + end + + use Raven::Rack + end end #