Sentry-ruby: Capture backtrace on Raven.capture_message

Created on 7 Nov 2013  路  12Comments  路  Source: getsentry/sentry-ruby

Hey,

I'm trying to use raven-ruby to capture rails deprecation warnings but I'm not finding a way to pass the backtrace to sentry.

My current approach:

ActiveSupport::Notifications.subscribe('deprecation.rails') do |name, start, finish, id, payload|
  Raven.capture_message(
    "DEPRECATION WARNING: #{payload[:message]}",
    :level => :warning
  )
end

Rails provides the payload[:callstack] which is the backtrace of the deprecation.

Just the message won't be really useful since I will not be able to trace from where it was triggered.

Suggestions?

_Inspired on @jonleighton approach for honey badger: https://gist.github.com/jonleighton/7122210_

documentation

Most helpful comment

Fixed! :)

All 12 comments

I haven't tried it myself yet but check out this recent article: http://beforeitwasround.com/2014/02/sending-rails-deprecation-warnings-to-sentry.html

I'll give it a try, thanks!

I'm looking to do a similar thing and that shared link is currently dead for me. Has anyone been able to do this successfully?

Also looking to do something similar.

In case anyone stumbles upon this, one way to do it is to add the 'backtrace' option like:

rescue => e
  Raven.capture_message("Something happened", :backtrace => e.backtrace)

Closing in favor of #766.

@sobrinho - This doesn't seem related to #766 ... they're different things, right? Capturing the backtrace for messages (this issue) isn't the same as capturing the request body. Having an option to capture backtrace would still be nice - even though you can kind of do it with capture_message("message", extra: {backtrace: caller})

It seems we already have backtrace option.

https://github.com/getsentry/raven-ruby/blob/69e0d4bc216d14d7418a3a35e24a00210abeca19/lib/raven/event.rb#L71

So Raven.capture_message("message", backtrace: caller) will work

Oh wow, does that work? That's awesome...
Sure would be nice if that were documented somewhere! Maybe here, for instance: https://docs.sentry.io/platforms/ruby/usage/#optional-attributes

Documentation PR already exists https://github.com/getsentry/sentry-docs/pull/766
It's 1 year old PR though

Oooh! This makes so much more sense! @sobrinho's closing comment above linked to the wrong # 766 馃槅 Okay, yup - that's awesome - hopefully someone can merge it...

Fixed! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sanjibukai picture sanjibukai  路  5Comments

tomvo picture tomvo  路  7Comments

knapo picture knapo  路  3Comments

budnik picture budnik  路  5Comments

steverob picture steverob  路  6Comments