Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replicate Raven.capture using sentry-ruby #1267

Closed
josherickson opened this issue Feb 4, 2021 · 3 comments
Closed

Replicate Raven.capture using sentry-ruby #1267

josherickson opened this issue Feb 4, 2021 · 3 comments
Assignees
Labels
Projects

Comments

@josherickson
Copy link

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

  • Ruby Version: 2.7
  • SDK Version: sentry-ruby 4.2.0
  • Integration Versions (if any): N/A

Raven Config

Sentry.init do |config|
  config.dsn = ENV['SENTRY_DSN']
end```
@josherickson
Copy link
Author

For anyone else reading this, the best way I've found to do this so far is:

begin
  # 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

@st0012
Copy link
Collaborator

st0012 commented Feb 10, 2021

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 🙂

@st0012 st0012 closed this as completed Feb 10, 2021
@st0012 st0012 added this to To do in 4.x via automation Feb 10, 2021
@st0012 st0012 added wontfix and removed Type: Bug labels Feb 10, 2021
@st0012 st0012 moved this from To do to Done in 4.x Oct 28, 2021
@Pontus4
Copy link

Pontus4 commented Aug 1, 2022

Release 5.4.0 includes Sentry.with_exception_captured which seems to be the equivalent we've been waiting for! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
4.x
  
Done
Development

No branches or pull requests

3 participants