Debugging code is never a fun challenge, let alone when it happens to be running in a scheduled ActiveJob
, behind a VPN, on a remote server, within a docker container.
Thankfully there many error tracking Sass products out there.
We started using sentry offering at DocHub mid 2018 and have so far really enjoy the event tracking coverage throughout the stack, and reasonable price point for the product, especially compared to others products such as New Relic.
One of the best features sentry is its freemium offering for developers, which provides (at the time of writing this) coverage of 5,000 events per month, although I am currently getting 15,000.
Integration is straight forward if you are fortunate enough to use one of their sdk's. Following their ruby guide:
Add sentry-raven
gem to your Gemfile
bundle add sentry-raven
Create the initializer config/initializers/raven.rb
Raven.configure do |config|
config.dsn = Rails.application.credentials[:reaven][:dsn]
end
dsn is generated for you project found on sentry's platform page
That is the complete setup for ruby on rails application, start capturing some exceptions! The following is an excerpt from a small active job, and consists of Ravens tags_context
for adding context variables as a Hash
, and then capturing the exception if raised with capture_exception
require 'scrappers/proxy_scrapper'
class AddProxiesJob < ApplicationJob
queue_as :maintenance
Raven.tags_context(job: 'add_proxies')
def perform
begin
ProxyScraper.get_list.each do |proxy|
IpProxy.create(proxy) unless IpProxy.find_by(address: proxy[:address], port: proxy[:port])
end
rescue => e
Raven.capture_exception(e)
end
end
end