Skip to content

JRuby: Stacktraces from Java exceptions do not get sent #333

@marshalium

Description

@marshalium

I have found that when running a JRuby application, Java exceptions that are sent to Sentry are missing their stack traces. While Ruby exceptions don't have that problem.

It is getting stripped out somewhere Raven::Event. stacktrace_interface_from. I think it is trying to find the actual code to include context in the event, but it can't find it for Java code. I would prefer that it just fallback to the exact lines from e.backtrace when no context can be found.

Here is example code that can be used to reproduce the issue:

require 'ap'
require 'sentry-raven'

def raises_java_exception
  raise java.lang.OutOfMemoryError.new("A Java error")
end

def raises_ruby_exception
  raise RuntimeError.new("A Ruby error")
end

begin
  raises_java_exception
rescue Exception => e
  result = Raven.capture_exception(e)
  puts "Java exception resulted in this:"
  ap result[:exception]
end

begin
  raises_ruby_exception
rescue Exception => e
  result = Raven.capture_exception(e)
  puts "Ruby exception resulting in this:"
  ap result[:exception]
end

Running it for me with sentry-raven 0.13.2, jruby 1.7.19, java build 1.7.0_75-b13, and OSX 10.10.3 results in the following output:

I, [2015-05-12T15:30:58.706000 #92349]  INFO -- : ** [Raven] Raven 0.13.2 ready to catch errors
W, [2015-05-12T15:30:58.747000 #92349]  WARN -- : ** [Raven] DEPRECATION WARNING: Calling #send on Raven::Base will be         removed in Raven-Ruby 0.14! Use #send_event instead!
Java exception resulted in this:
{
    :values => [
        [0] {
            :stacktrace => {
                :frames => []
            },
                 :value => "A Java error",
                  :type => "Java::JavaLang::OutOfMemoryError",
                :module => "Java::JavaLang"
        }
    ]
}
W, [2015-05-12T15:31:00.419000 #92349]  WARN -- : ** [Raven] DEPRECATION WARNING: Calling #send on Raven::Base will be         removed in Raven-Ruby 0.14! Use #send_event instead!
Ruby exception resulting in this:
{
    :values => [
        [0] {
            :stacktrace => {
                :frames => [
                    [0] {
                        :project_root => nil,
                         :pre_context => [
                            [0] "end\n",
                            [1] "\n",
                            [2] "begin\n"
                        ],
                              :in_app => false,
                              :lineno => 27,
                            :abs_path => "./raven_bug.rb",
                        :post_context => [
                            [0] "rescue Exception => e\n",
                            [1] "  result = Raven.capture_exception(e)\n",
                            [2] "  puts \"Ruby exception resulting in this:\"\n"
                        ],
                        :context_line => "  raises_ruby_exception\n",
                            :function => "(root)",
                            :filename => "./raven_bug.rb"
                    },
                    [1] {
                        :project_root => nil,
                         :pre_context => [
                            [0] "end\n",
                            [1] "\n",
                            [2] "def raises_ruby_exception\n"
                        ],
                              :in_app => false,
                              :lineno => 15,
                            :abs_path => "./raven_bug.rb",
                        :post_context => [
                            [0] "end\n",
                            [1] "\n",
                            [2] "begin\n"
                        ],
                        :context_line => "  raise RuntimeError.new(\"A Ruby error\")\n",
                            :function => "raises_ruby_exception",
                            :filename => "./raven_bug.rb"
                    }
                ]
            },
                 :value => "A Ruby error",
                  :type => "RuntimeError",
                :module => ""
        }
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions