Describe the bug
Hello, I'm trying to migrate from sentry-raven to sentry-ruby, but I haven't been able to figure out how to replicate this behaviour:
Raven.capture do
# capture any exceptions which happen during execution of this block
1 / 0
end
https://github.com/getsentry/sentry-ruby/tree/master/sentry-raven#usage
It seems that there is not an equivalent Sentry.capture method and I couldn't find it in the migration guide.
I'm using this in a Ruby AWS Lambda function, which is why I'm looking to use a capture block to essentially wrap my entire application code, rather than being able to use something like the rails integration.
Is anyone able to provide some guidance? Thanks!
To Reproduce
Sentry.capture do
# capture any exceptions which happen during execution of this block
1 / 0
end
Expected behavior
Capture the exception.
Actual behavior
NoMethodError: undefined method `capture' for Sentry:Module
Environment
sentry-ruby 4.2.0Raven Config
ruby
Sentry.init do |config|
config.dsn = ENV['SENTRY_DSN']
end
For anyone else reading this, the best way I've found to do this so far is:
# Your application code.
1 / 0
rescue ScriptError, StandardError => e # Figure out what errors are right for you.
Sentry.capture_exception(e)
raise
end
And specific to using this is in AWS Lambda, I also found that I had to disable the default asynchronous sending to get it to work – presumably this is because the Lambda function would exit before my Sentry error was able to be logged, but I didn't spend the time to confirm the cause.
Sentry.init do |config|
config.dsn = ENV['SENTRY_DSN']
config.background_worker_threads = 0 # Force synchronous sending.
end
Docs: https://github.com/getsentry/sentry-ruby#blocking-vs-non-blocking
thanks for reporting this and provide an example. but to keep sentry-ruby's APIs align with other SDKs, we don't plan to bring Sentry.capture back atm 🙂
Most helpful comment
For anyone else reading this, the best way I've found to do this so far is:
And specific to using this is in AWS Lambda, I also found that I had to disable the default asynchronous sending to get it to work – presumably this is because the Lambda function would exit before my Sentry error was able to be logged, but I didn't spend the time to confirm the cause.
Docs: https://github.com/getsentry/sentry-ruby#blocking-vs-non-blocking