Skip to content

Commit 5f30ec5

Browse files
committed
Merge branch 'master' of https://github.com/getsentry/raven-ruby
2 parents ea6d22e + ec22b8f commit 5f30ec5

File tree

16 files changed

+130
-23
lines changed

16 files changed

+130
-23
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ notifications:
2424

2525
matrix:
2626
allow_failures:
27-
- rvm: jruby-19mode
2827
- rvm: ruby-head
2928
exclude:
3029
- rvm: 1.8.7

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2015 Functional Software, Inc
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

lib/raven/backtrace.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ class Backtrace
99
class Line
1010

1111
# regexp (optionnally allowing leading X: for windows support)
12-
INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+|<.*>):(\d+)(?::in `([^']+)')?$}.freeze
12+
RUBY_INPUT_FORMAT = %r{^((?:[a-zA-Z]:)?[^:]+|<.*>):(\d+)(?::in `([^']+)')?$}.freeze
13+
14+
# org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
15+
JAVA_INPUT_FORMAT = %r{^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$}.freeze
1316

1417
APP_DIRS_PATTERN = /(bin|app|config|lib|test)/
1518

@@ -22,16 +25,27 @@ class Line
2225
# The method of the line (such as index)
2326
attr_reader :method
2427

28+
# The module name (JRuby)
29+
attr_reader :module_name
30+
2531
# Parses a single line of a given backtrace
2632
# @param [String] unparsed_line The raw line from +caller+ or some backtrace
2733
# @return [Line] The parsed backtrace line
2834
def self.parse(unparsed_line)
29-
_, file, number, method = unparsed_line.match(INPUT_FORMAT).to_a
30-
new(file, number, method)
35+
ruby_match = unparsed_line.match(RUBY_INPUT_FORMAT)
36+
if ruby_match
37+
_, file, number, method = ruby_match.to_a
38+
module_name = nil
39+
else
40+
java_match = unparsed_line.match(JAVA_INPUT_FORMAT)
41+
_, module_name, method, file, number = java_match.to_a
42+
end
43+
new(file, number, method, module_name)
3144
end
3245

33-
def initialize(file, number, method)
46+
def initialize(file, number, method, module_name)
3447
self.file = file
48+
self.module_name = module_name
3549
self.number = number.to_i
3650
self.method = method
3751
end
@@ -66,7 +80,7 @@ def inspect
6680

6781
private
6882

69-
attr_writer :file, :number, :method
83+
attr_writer :file, :number, :method, :module_name
7084
end
7185

7286
# holder for an Array of Backtrace::Line instances

lib/raven/base.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def capture_type(obj, options = {})
121121
else
122122
send_event(evt)
123123
end
124+
125+
evt
124126
end
125127
end
126128
alias_method :capture_message, :capture_type

lib/raven/configuration.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'certifi'
12
require 'logger'
23
require 'uri'
34

@@ -58,6 +59,9 @@ class Configuration
5859
# Should the SSL certificate of the server be verified?
5960
attr_accessor :ssl_verification
6061

62+
# The path to the SSL certificate file
63+
attr_accessor :ssl_ca_file
64+
6165
# SSl settings passed direactly to faraday's ssl option
6266
attr_accessor :ssl
6367

@@ -113,7 +117,8 @@ def initialize
113117
self.send_modules = true
114118
self.excluded_exceptions = IGNORE_DEFAULT
115119
self.processors = [Raven::Processor::RemoveCircularReferences, Raven::Processor::UTF8Conversion, Raven::Processor::SanitizeData]
116-
self.ssl_verification = false
120+
self.ssl_verification = true
121+
self.ssl_ca_file = Certifi.where
117122
self.encoding = 'gzip'
118123
self.timeout = 1
119124
self.open_timeout = 1

lib/raven/event.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'rubygems'
22
require 'socket'
33
require 'securerandom'
4+
require 'digest/md5'
45

56
require 'raven/error'
67
require 'raven/linecache'
@@ -24,7 +25,8 @@ class Event
2425

2526
attr_reader :id
2627
attr_accessor :project, :message, :timestamp, :time_spent, :level, :logger,
27-
:culprit, :server_name, :release, :modules, :extra, :tags, :context, :configuration
28+
:culprit, :server_name, :release, :modules, :extra, :tags, :context, :configuration,
29+
:checksum
2830

2931
def initialize(init = {})
3032
@configuration = Raven.configuration
@@ -43,6 +45,7 @@ def initialize(init = {})
4345
@user = {}
4446
@extra = {}
4547
@tags = {}
48+
@checksum = nil
4649

4750
yield self if block_given?
4851

@@ -108,6 +111,7 @@ def to_hash
108111
data[:extra] = @extra if @extra
109112
data[:tags] = @tags if @tags
110113
data[:user] = @user if @user
114+
data[:checksum] = @checksum if @checksum
111115
@interfaces.each_pair do |name, int_data|
112116
data[name.to_sym] = int_data.to_hash
113117
end
@@ -186,10 +190,11 @@ def self.stacktrace_interface_from(int, evt, backtrace)
186190
backtrace = Backtrace.parse(backtrace)
187191
int.frames = backtrace.lines.reverse.map do |line|
188192
StacktraceInterface::Frame.new.tap do |frame|
189-
frame.abs_path = line.file
190-
frame.function = line.method
193+
frame.abs_path = line.file if line.file
194+
frame.function = line.method if line.method
191195
frame.lineno = line.number
192196
frame.in_app = line.in_app
197+
frame.module = line.module_name if line.module_name
193198

194199
if evt.configuration[:context_lines] && frame.abs_path
195200
frame.pre_context, frame.context_line, frame.post_context = \
@@ -206,6 +211,7 @@ def self._source_lines(_path, _from, _to)
206211
end
207212

208213
def get_file_context(filename, lineno, context)
214+
return nil, nil, nil unless Raven::LineCache.is_valid_file(filename)
209215
lines = (2 * context + 1).times.map do |i|
210216
Raven::LineCache.getline(filename, lineno - context + i)
211217
end
@@ -234,7 +240,7 @@ def generate_event_id
234240
ary[2] = (ary[2] & 0x0fff) | 0x4000
235241
ary[3] = (ary[3] & 0x3fff) | 0x8000
236242
uuid = "%08x-%04x-%04x-%04x-%04x%08x" % ary
237-
Digest::MD5.hexdigest(uuid)
243+
::Digest::MD5.hexdigest(uuid)
238244
end
239245
end
240246
end

lib/raven/integrations/rails.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ class Rails < ::Rails::Railtie
1414
end
1515
end
1616

17+
initializer 'raven.active_job' do
18+
ActiveSupport.on_load :active_job do
19+
require 'raven/integrations/rails/active_job'
20+
include Raven::Rails::ActiveJob
21+
end
22+
end
23+
1724
config.after_initialize do
1825
Raven.configure do |config|
1926
config.logger ||= ::Rails.logger
@@ -34,5 +41,9 @@ class Rails < ::Rails::Railtie
3441
rake_tasks do
3542
require 'raven/integrations/tasks'
3643
end
44+
45+
runner do
46+
Raven.capture
47+
end
3748
end
3849
end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Raven
2+
class Rails
3+
module ActiveJob
4+
def self.included(base)
5+
base.class_eval do
6+
rescue_from(Exception) do |exception|
7+
# Do not capture exceptions when using Sidekiq so we don't capture
8+
# The same exception twice.
9+
unless self.class.queue_adapter.to_s == 'ActiveJob::QueueAdapters::SidekiqAdapter'
10+
Raven.capture_exception(exception, :extra => { :active_job => self.class.name })
11+
raise exception
12+
end
13+
end
14+
end
15+
end
16+
end
17+
end
18+
end

lib/raven/interfaces/stack_trace.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Frame < Interface
2525
attr_accessor :pre_context
2626
attr_accessor :post_context
2727
attr_accessor :context_line
28+
attr_accessor :module
2829
attr_accessor :lineno
2930
attr_accessor :in_app
3031

lib/raven/linecache.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ class LineCache
55
class << self
66
CACHE = {}
77

8+
def is_valid_file(path)
9+
lines = getlines(path)
10+
return lines != nil
11+
end
12+
813
def getlines(path)
914
CACHE[path] ||= begin
1015
IO.readlines(path)
1116
rescue
12-
[]
17+
nil
1318
end
1419
end
1520

1621
def getline(path, n)
1722
return nil if n < 1
18-
getlines(path)[n - 1]
23+
lines = getlines(path)
24+
return nil if lines == nil
25+
lines[n - 1]
1926
end
2027
end
2128
end

0 commit comments

Comments
 (0)