From c5b6a3e664db73e2a4752078c4d971fbb2c74102 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Mon, 20 Feb 2017 13:29:29 +0100 Subject: [PATCH 01/12] JRuby: avoid using Sqlite3 --- gemfiles/Gemfile.base | 2 +- spec/opbeat/injections/sequel_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gemfiles/Gemfile.base b/gemfiles/Gemfile.base index 421e0cd..aa70631 100644 --- a/gemfiles/Gemfile.base +++ b/gemfiles/Gemfile.base @@ -15,7 +15,7 @@ gem 'simplecov' gem 'redis' gem 'fakeredis' -gem 'sqlite3' +gem 'sqlite3', platform: :mri gem 'sequel' gem 'delayed_job', require: false diff --git a/spec/opbeat/injections/sequel_spec.rb b/spec/opbeat/injections/sequel_spec.rb index 983aa06..36166f0 100644 --- a/spec/opbeat/injections/sequel_spec.rb +++ b/spec/opbeat/injections/sequel_spec.rb @@ -2,7 +2,7 @@ require 'sequel' module Opbeat - RSpec.describe Injections::Sequel do + RSpec.describe Injections::Sequel, unless: RSpec::Support::Ruby.jruby? do it "is installed" do reg = Opbeat::Injections.installed['Sequel'] From c6ed55a61fd3a21446276042971fbe8e4bf9d0ee Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Mon, 20 Feb 2017 14:01:57 +0100 Subject: [PATCH 02/12] Spec --- spec/opbeat/error_message/stacktrace_spec.rb | 64 +++++++++++++------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/spec/opbeat/error_message/stacktrace_spec.rb b/spec/opbeat/error_message/stacktrace_spec.rb index 8862010..1c15c9d 100644 --- a/spec/opbeat/error_message/stacktrace_spec.rb +++ b/spec/opbeat/error_message/stacktrace_spec.rb @@ -2,37 +2,58 @@ module Opbeat RSpec.describe ErrorMessage::Stacktrace do - def real_exception 1 / 0 rescue => e e end + def java_exception + require 'java' + java_import 'java.lang.ClassNotFoundException' + java.lang::Class.forName('foo.Bar') + rescue ClassNotFoundException => e + e + end + let(:config) { Configuration.new } let(:exception) { real_exception } - describe ".from" do - it "initializes from an exception" do - stacktrace = ErrorMessage::Stacktrace.from config, exception - expect(stacktrace.frames).to_not be_empty - - # so meta - last_frame = stacktrace.frames.last - expect(last_frame.filename).to eq "opbeat/error_message/stacktrace_spec.rb" - expect(last_frame.lineno).to be 7 - expect(last_frame.abs_path).to_not be_nil - expect(last_frame.function).to eq "/" - expect(last_frame.vars).to be_nil - - expect(last_frame.pre_context.last).to match(/def real_exception/) - expect(last_frame.context_line).to match(/1 \/ 0/) - expect(last_frame.post_context.first).to match(/rescue/) + describe '.from' do + context 'when on JRuby', if: RSpec::Support::Ruby.jruby? do + it 'initializes from a Java exception' do + stacktrace = ErrorMessage::Stacktrace.from config, java_exception + expect(stacktrace.frames).to_not be_empty + end + + it 'initializes from an exception' do + stacktrace = ErrorMessage::Stacktrace.from config, exception + expect(stacktrace.frames).to_not be_empty + end end - context "when context lines are off" do + context 'when on MRI', unless: RSpec::Support::Ruby.jruby? do + it 'initializes from an exception' do + stacktrace = ErrorMessage::Stacktrace.from config, exception + expect(stacktrace.frames).to_not be_empty + + # so meta + last_frame = stacktrace.frames.last + expect(last_frame.filename).to eq 'opbeat/error_message/stacktrace_spec.rb' + expect(last_frame.lineno).to be 6 + expect(last_frame.abs_path).to_not be_nil + expect(last_frame.function).to eq '/' + expect(last_frame.vars).to be_nil + + expect(last_frame.pre_context.last).to match(/def real_exception/) + expect(last_frame.context_line).to match(/1 \/ 0/) + expect(last_frame.post_context.first).to match(/rescue/) + end + end + + context 'when context lines are off' do let(:config) { Configuration.new context_lines: nil } - it "initializes too" do + it 'initializes too' do stacktrace = ErrorMessage::Stacktrace.from config, exception expect(stacktrace.frames).to_not be_empty @@ -44,13 +65,12 @@ def real_exception end end - describe "#to_h" do - it "is a hash" do + describe '#to_h' do + it 'is a hash' do hsh = ErrorMessage::Stacktrace.from(config, exception).to_h expect(hsh).to be_a Hash expect(hsh.keys).to eq [:frames] end end - end end From aceaa60ba366dc655b4ba62d55f8569ec2db1720 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Mon, 20 Feb 2017 16:08:11 +0100 Subject: [PATCH 03/12] Stacktrace: Borrow parse_line from Sentry - See https://github.com/getsentry/raven-ruby/blob/e5e6642239c019d4b7f302d0acbdc4a6630c2c1e/lib/raven/backtrace.rb --- lib/opbeat/error_message/stacktrace.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/opbeat/error_message/stacktrace.rb b/lib/opbeat/error_message/stacktrace.rb index 6133f6f..0bb8704 100644 --- a/lib/opbeat/error_message/stacktrace.rb +++ b/lib/opbeat/error_message/stacktrace.rb @@ -27,9 +27,19 @@ class Frame < Struct.new(:filename, :lineno, :abs_path, :function, :vars, BACKTRACE_REGEX = /^(.+?):(\d+)(?::in `(.+?)')?$/.freeze + # regexp (optional leading X: on windows, or JRuby9000 class-prefix) + RUBY_INPUT_FORMAT = / + ^ \s* (?: [a-zA-Z]: | uri:classloader: )? ([^:]+ | <.*>): + (\d+) + (?: :in \s `([^']+)')?$ + /x + + # org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170) + JAVA_INPUT_FORMAT = /^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$/ + class << self def from_line config, line - _, abs_path, lineno, function = line.match(BACKTRACE_REGEX).to_a + abs_path, lineno, function, _module_name = parse_line(line) lineno = lineno.to_i filename = strip_load_path(abs_path) @@ -44,7 +54,21 @@ def from_line config, line private + def parse_line(unparsed_line) + ruby_match = unparsed_line.match(RUBY_INPUT_FORMAT) + if ruby_match + _, file, number, method = ruby_match.to_a + file.sub!(/\.class$/, '.rb') + module_name = nil + else + java_match = unparsed_line.match(JAVA_INPUT_FORMAT) + _, module_name, method, file, number = java_match.to_a + end + [file, number, method, module_name] + end + def strip_load_path path + return '' unless path prefix = $: .map(&:to_s) .select { |s| path.start_with?(s) } From 9e5cc1b0ab545a5ef08b070f06ce3e75cfc8d925 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Mon, 20 Feb 2017 16:25:58 +0100 Subject: [PATCH 04/12] Travis: Add JRuby 9.1.7.0 x 1 --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4a33b58..2c28bf2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ rvm: - 2.2.3 - 2.3.3 - 2.4.0 + - jruby-9.1.7.0 gemfile: - gemfiles/Gemfile.rails-3.2.x - gemfiles/Gemfile.rails-4.0.x @@ -19,6 +20,8 @@ matrix: include: - rvm: 2.3.3 gemfile: gemfiles/Gemfile.rails-HEAD + - rvm: jruby-9.1.7.0 + gemfile: gemfiles/Gemfile.rails-5.0.x exclude: - rvm: 2.0.0 @@ -33,6 +36,14 @@ matrix: gemfile: gemfiles/Gemfile.rails-4.1.x - rvm: 2.4.0 gemfile: gemfiles/Gemfile.rails-4.2.x + - rvm: jruby-9.1.7.0 + gemfile: gemfiles/Gemfile.rails-3.2.x + - rvm: jruby-9.1.7.0 + gemfile: gemfiles/Gemfile.rails-4.0.x + - rvm: jruby-9.1.7.0 + gemfile: gemfiles/Gemfile.rails-4.1.x + - rvm: jruby-9.1.7.0 + gemfile: gemfiles/Gemfile.rails-4.2.x notifications: email: false From ca6427e3e00a2e08639536cfe77a69df99b33656 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 15 Jun 2017 13:37:06 +0200 Subject: [PATCH 05/12] Travis: use jruby-9.1.11.0 --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2c28bf2..dccf6a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ rvm: - 2.2.3 - 2.3.3 - 2.4.0 - - jruby-9.1.7.0 + - jruby-9.1.11.0 gemfile: - gemfiles/Gemfile.rails-3.2.x - gemfiles/Gemfile.rails-4.0.x @@ -20,7 +20,7 @@ matrix: include: - rvm: 2.3.3 gemfile: gemfiles/Gemfile.rails-HEAD - - rvm: jruby-9.1.7.0 + - rvm: jruby-9.1.11.0 gemfile: gemfiles/Gemfile.rails-5.0.x exclude: @@ -36,13 +36,13 @@ matrix: gemfile: gemfiles/Gemfile.rails-4.1.x - rvm: 2.4.0 gemfile: gemfiles/Gemfile.rails-4.2.x - - rvm: jruby-9.1.7.0 + - rvm: jruby-9.1.11.0 gemfile: gemfiles/Gemfile.rails-3.2.x - - rvm: jruby-9.1.7.0 + - rvm: jruby-9.1.11.0 gemfile: gemfiles/Gemfile.rails-4.0.x - - rvm: jruby-9.1.7.0 + - rvm: jruby-9.1.11.0 gemfile: gemfiles/Gemfile.rails-4.1.x - - rvm: jruby-9.1.7.0 + - rvm: jruby-9.1.11.0 gemfile: gemfiles/Gemfile.rails-4.2.x notifications: From 165e59c33881e6047bbd4a5f6255115e74949acf Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 15 Jun 2017 13:51:57 +0200 Subject: [PATCH 06/12] Travis: Ensure new Bundler --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index dccf6a2..4b3a2b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ language: ruby cache: bundler env: - CI=true +before_install: + - gem install bundler rvm: - 2.0.0 - 2.1.6 From b45048dfe812dbf06ade8104f3daacd2bc0fd020 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 15 Jun 2017 13:52:34 +0200 Subject: [PATCH 07/12] Gemspec: add a required_ruby_version >= 2.0.0 --- opbeat.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/opbeat.gemspec b/opbeat.gemspec index 65d2516..ef6e202 100644 --- a/opbeat.gemspec +++ b/opbeat.gemspec @@ -11,6 +11,7 @@ Gem::Specification.new do |gem| gem.summary = "The official Opbeat Ruby client library" gem.homepage = "https://github.com/opbeat/opbeat-ruby" gem.license = "BSD-3-Clause" + gem.required_ruby_version = ">= 2.0.0" gem.files = `git ls-files -z`.split("\x0") gem.require_paths = ["lib"] From 32d8dcd7290f8d06aa7baa48afe32ffaad45669a Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 15 Jun 2017 13:53:03 +0200 Subject: [PATCH 08/12] Sinatra gem dependency from RubyGems.org --- gemfiles/Gemfile.rails-5.0.x | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/Gemfile.rails-5.0.x b/gemfiles/Gemfile.rails-5.0.x index 692d6c1..0353904 100644 --- a/gemfiles/Gemfile.rails-5.0.x +++ b/gemfiles/Gemfile.rails-5.0.x @@ -1,4 +1,4 @@ eval_gemfile File.expand_path('../Gemfile.base', __FILE__) gem 'rails', '~> 5.0.0' -gem 'sinatra', git: 'https://github.com/sinatra/sinatra.git' +gem 'sinatra' From 5ec236c7516a8ec32d660e74fe4a3190c9142aa9 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 15 Jun 2017 13:53:23 +0200 Subject: [PATCH 09/12] Gemfile: add ruby RUBY_VERSION hinting for Bundler --- gemfiles/Gemfile.base | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gemfiles/Gemfile.base b/gemfiles/Gemfile.base index aa70631..7d7ea70 100644 --- a/gemfiles/Gemfile.base +++ b/gemfiles/Gemfile.base @@ -2,6 +2,8 @@ source "http://rubygems.org" gemspec path: File.expand_path('../..', __FILE__) +ruby RUBY_VERSION + gem 'rake' gem 'rspec' gem 'timecop' From 25817a533516aa9c119558b91081b4b1a76eb613 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 15 Jun 2017 14:18:37 +0200 Subject: [PATCH 10/12] Gemfile: Sidekiq < 5 if we lack Ruby 2.2.2 --- gemfiles/Gemfile.base | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gemfiles/Gemfile.base b/gemfiles/Gemfile.base index 7d7ea70..e6089c4 100644 --- a/gemfiles/Gemfile.base +++ b/gemfiles/Gemfile.base @@ -23,6 +23,7 @@ gem 'sequel' gem 'delayed_job', require: false gem 'resque', require: false -unless RUBY_VERSION.to_i <= 1 - gem 'sidekiq', require: false +# Freeze Sidekiq to < 5 in Ruby 2.2 Gemfiles +if RUBY_VERSION >= '2' + gem 'sidekiq', (RUBY_VERSION >= '2.2.2' ? '~> 5' : '~> 4'), require: false end From c43ac8df7eadcb32e8aa356fdca614a55474e24b Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 15 Jun 2017 14:32:06 +0200 Subject: [PATCH 11/12] Travis: JRuby 9 test on rails-HEAD --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4b3a2b2..bb512ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ matrix: - rvm: 2.3.3 gemfile: gemfiles/Gemfile.rails-HEAD - rvm: jruby-9.1.11.0 - gemfile: gemfiles/Gemfile.rails-5.0.x + gemfile: gemfiles/Gemfile.rails-HEAD exclude: - rvm: 2.0.0 From 6a6a72cd0c7b2cf8ea305f11938d22700e8a1140 Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Thu, 15 Jun 2017 14:46:26 +0200 Subject: [PATCH 12/12] Travis: Keep CI=true and JRUBY_OPTS=--debug global --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb512ee..7042f27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,9 @@ language: ruby cache: bundler env: - - CI=true + global: + - CI=true + - JRUBY_OPTS=--debug before_install: - gem install bundler rvm: