Add Sentry for exception tracking

This commit is contained in:
Greg Karékinian
2015-04-28 18:26:00 +02:00
parent 35c04f85e4
commit 3b326d6dbf
4 changed files with 26 additions and 35 deletions

View File

@@ -16,4 +16,5 @@ end
group :staging, :production do group :staging, :production do
gem "rainbows" gem "rainbows"
gem "sentry-raven"
end end

View File

@@ -21,6 +21,8 @@ GEM
builder (3.2.2) builder (3.2.2)
eventmachine (1.0.3) eventmachine (1.0.3)
excon (0.16.10) excon (0.16.10)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
fog (1.7.0) fog (1.7.0)
builder builder
excon (~> 0.14) excon (~> 0.14)
@@ -42,6 +44,7 @@ GEM
mime-types (1.23) mime-types (1.23)
minitest (2.10.0) minitest (2.10.0)
multi_json (1.10.0) multi_json (1.10.0)
multipart-post (2.0.0)
net-scp (1.0.4) net-scp (1.0.4)
net-ssh (>= 1.99.1) net-ssh (>= 1.99.1)
net-ssh (2.6.7) net-ssh (2.6.7)
@@ -63,6 +66,8 @@ GEM
rest-client (1.6.7) rest-client (1.6.7)
mime-types (>= 1.16) mime-types (>= 1.16)
ruby-hmac (0.4.0) ruby-hmac (0.4.0)
sentry-raven (0.13.1)
faraday (>= 0.7.6)
sinatra (1.4.5) sinatra (1.4.5)
rack (~> 1.4) rack (~> 1.4)
rack-protection (~> 1.4) rack-protection (~> 1.4)
@@ -93,5 +98,6 @@ DEPENDENCIES
redis redis
rest-client rest-client
riak-client! riak-client!
sentry-raven
sinatra (~> 1.4) sinatra (~> 1.4)
sinatra-contrib sinatra-contrib

View File

@@ -37,13 +37,8 @@ module RemoteStorage
res = do_head_request(url) res = do_head_request(url)
set_response_headers(res) set_response_headers(res)
rescue => exception rescue RestClient::ResourceNotFound
if exception.is_a? RestClient::ResourceNotFound server.halt 404
server.halt 404
end
puts exception.inspect
server.halt 499
end end
def get_data(user, directory, key) def get_data(user, directory, key)
@@ -57,13 +52,8 @@ module RemoteStorage
server.halt 304 if none_match.include? %Q("#{res.headers[:etag]}") server.halt 304 if none_match.include? %Q("#{res.headers[:etag]}")
return res.body return res.body
rescue => exception rescue RestClient::ResourceNotFound
if exception.is_a? RestClient::ResourceNotFound server.halt 404
server.halt 404
end
puts exception.inspect
server.halt 499
end end
def get_head_directory_listing(user, directory) def get_head_directory_listing(user, directory)
@@ -71,13 +61,8 @@ module RemoteStorage
server.headers["Content-Type"] = "application/json" server.headers["Content-Type"] = "application/json"
server.headers["ETag"] = %Q("#{res.headers[:etag]}") server.headers["ETag"] = %Q("#{res.headers[:etag]}")
rescue => exception rescue RestClient::ResourceNotFound
if exception.is_a? RestClient::ResourceNotFound server.halt 404
server.halt 404
end
puts exception.inspect
server.halt 499
end end
def get_directory_listing(user, directory) def get_directory_listing(user, directory)
@@ -102,9 +87,6 @@ module RemoteStorage
end end
listing.to_json listing.to_json
rescue => exception
puts exception.inspect
server.halt 499
end end
def put_data(user, directory, key, data, content_type) def put_data(user, directory, key, data, content_type)
@@ -129,11 +111,8 @@ module RemoteStorage
server.headers["ETag"] = %Q("#{res.headers[:etag]}") server.headers["ETag"] = %Q("#{res.headers[:etag]}")
server.halt 200 server.halt 200
else else
server.halt 499 # TODO use sth more suitable server.halt 500
end end
rescue => exception
puts exception.inspect
server.halt 499 # TODO use sth more suitable
end end
def delete_data(user, directory, key) def delete_data(user, directory, key)
@@ -149,13 +128,8 @@ module RemoteStorage
delete_dir_objects(user, directory) delete_dir_objects(user, directory)
server.halt 200 server.halt 200
rescue => exception rescue RestClient::ResourceNotFound
if exception.is_a? RestClient::ResourceNotFound server.halt 404
server.halt 404
end
puts exception.inspect
server.halt 499
end end
private private

View File

@@ -30,6 +30,16 @@ class LiquorCabinet < Sinatra::Base
configure :production, :staging do configure :production, :staging do
require "rack/common_logger" 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 end
# #