Lucky framework integration
Closed this issue · 7 comments
I'm actually using this in lucky right now, though, I'm having a few issues. It doesn't seem to be reporting most of the errors. We see 1 error reported a week, but we can hit a 500 page, and no reports....
I created this file:
require "raven/integrations/http/handler"
class Lucky::RavenHandler
include HTTP::Handler
include Raven::HTTPHandler
# Not really sure what this should return or do
def build_raven_culprit_context(context : HTTP::Server::Context)
context.request
end
def build_raven_http_url(context : HTTP::Server::Context)
req = context.request
String.build do |url|
url << "https://" << req.host_with_port << req.resource
end
end
def build_raven_http_data(context : HTTP::Server::Context)
context.request.query_params.to_h
end
end
I sort of copied it from the Amber one. I don't really know what all should go in these. Then in my server.cr
file, I added
Lucky::RavenHandler.new,
Lucky::ErrorHandler.new(action: Errors::Show),
in to my HTTP::Server.new
. I also added my config in.
Is this the right way to go? Or is it better to just use Raven.capture
?
Ok, this might actually be an issue with sentry. I just checked their page, and saw their awesome 500 error page
In any case, for anyone looking to add this in, here's what I'm currently doing:
in config/raven.cr
require "raven"
Raven.configure do |config|
config.dsn = "your thing here"
config.environments = ["production"]
end
in src/handlers/raven_handler.cr
class Lucky::RavenHandler < Lucky::ErrorHandler
def call(context : HTTP::Server::Context)
call_next(context)
rescue error : Exception
Raven.capture(error)
if settings.show_debug_output
print_debug_output(context, error)
else
call_error_action(context, error)
end
end
end
and in src/server.cr
replace the current Lucky::ErrorHandler.new
with Lucky::RavenHandler.new(action: Errors::Show)
@jwoertink Thanks for the detective work :) ATM it seems to work, I've added feature/lucky-integration
branch with complete PoC implementation. Could you test it out? (note: it requires lucky from the master
branch to work)
shard.yml
:
dependencies:
raven:
github: Sija/raven.cr
branch: feature/lucky-integration
config/raven.cr
:
require "raven"
require "raven/integrations/lucky"
Raven.configure do |config|
# ...
config.async = true
config.current_environment = Lucky::Env.name
end
src/app.cr
:
class App
# ...
def initialize
@server = HTTP::Server.new [
# ...
Lucky::ErrorHandler.new(action: Errors::Show),
Raven::Lucky::ErrorHandler.new,
# ...
]
end
end
Sweet, yeah, I'll check it out and report back how it goes. Thanks!
ok, tried this out. I get an error:
E, [2018-09-21 10:19:46 -07:00 #13063] ERROR -- sentry: Unable to record event with remote Sentry server (IO::Timeout - connect timed out): /usr/local/Cellar/crystal/0.26.1/src/socket/tcp_socket.cr:73:15 in 'initialize'
/usr/local/Cellar/crystal/0.26.1/src/socket/tcp_socket.cr:27:3 in 'new'
/usr/local/Cellar/crystal/0.26.1/src/http/client.cr:663:5 in 'socket'
/usr/local/Cellar/crystal/0.26.1/src/http/client.cr:559:5 in 'send_request'
/usr/local/Cellar/crystal/0.26.1/src/http/client.cr:498:5 in 'exec_internal_single'
/usr/local/Cellar/crystal/0.26.1/src/http/client.cr:485:5 in 'exec_internal'
/usr/local/Cellar/crystal/0.26.1/src/http/client.cr:481:5 in 'exec'
/usr/local/Cellar/crystal/0.26.1/src/http/client.cr:599:5 in 'exec'
/usr/local/Cellar/crystal/0.26.1/src/http/client.cr:329:3 in 'post'
lib/raven/src/raven/transports/http.cr:71:7 in 'send_event:content_type'
lib/raven/src/raven/client.cr:52:9 in 'send_event'
In that configure block, I added config.dsn = SENTRY_DSN
, but the rest is the same.
Hmm, connection problems again... Try adding config.connect_timeout = 10.seconds
.
Btw, which Sentry version you use + is it hosted or on-premise?
I'm just using the saas version. We're not self-hosting it.
Ok, tried it out and it works! I got the error, and it reported.