sentry-ruby 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.craft.yml +18 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sentry.rb +97 -0
- data/lib/sentry/backtrace.rb +128 -0
- data/lib/sentry/breadcrumb.rb +25 -0
- data/lib/sentry/breadcrumb/sentry_logger.rb +103 -0
- data/lib/sentry/breadcrumb_buffer.rb +50 -0
- data/lib/sentry/client.rb +85 -0
- data/lib/sentry/configuration.rb +401 -0
- data/lib/sentry/core_ext/object/deep_dup.rb +57 -0
- data/lib/sentry/core_ext/object/duplicable.rb +153 -0
- data/lib/sentry/dsn.rb +45 -0
- data/lib/sentry/event.rb +175 -0
- data/lib/sentry/event/options.rb +31 -0
- data/lib/sentry/hub.rb +126 -0
- data/lib/sentry/interface.rb +22 -0
- data/lib/sentry/interfaces/exception.rb +11 -0
- data/lib/sentry/interfaces/request.rb +104 -0
- data/lib/sentry/interfaces/single_exception.rb +14 -0
- data/lib/sentry/interfaces/stacktrace.rb +57 -0
- data/lib/sentry/linecache.rb +44 -0
- data/lib/sentry/logger.rb +20 -0
- data/lib/sentry/rack.rb +4 -0
- data/lib/sentry/rack/capture_exception.rb +45 -0
- data/lib/sentry/ruby.rb +1 -0
- data/lib/sentry/scope.rb +192 -0
- data/lib/sentry/transport.rb +110 -0
- data/lib/sentry/transport/configuration.rb +28 -0
- data/lib/sentry/transport/dummy_transport.rb +14 -0
- data/lib/sentry/transport/http_transport.rb +62 -0
- data/lib/sentry/transport/state.rb +40 -0
- data/lib/sentry/utils/deep_merge.rb +22 -0
- data/lib/sentry/utils/exception_cause_chain.rb +20 -0
- data/lib/sentry/utils/real_ip.rb +70 -0
- data/lib/sentry/version.rb +3 -0
- data/sentry-ruby.gemspec +26 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd48cd818d98c18e281aab8c37346fc7dc204b78396afe0ccaa64fa3cc8c0d2f
|
4
|
+
data.tar.gz: 2d4f7e657e9a3abc1d1063aa73e86ef7d9e09b0e5205f2a16b54d2242955316e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 612e9205c0d42c107a9a3a1d5b7bc759fd4daae5ede8ffd0efec1a0c3d1aa22860669f5f4d5a244397dcfe481f7784ae3f23c42c9e316338702cf372f8610e48
|
7
|
+
data.tar.gz: 45535f8367e8b37ba0f106b78ee2e9b7f40622ccb9b7207ba34ee49238600c6885a16125f15ff65957d713871f576b8579ecdbc88fbfb45cc6feecab0e64b1aa
|
data/.craft.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
minVersion: '0.13.2'
|
2
|
+
github:
|
3
|
+
owner: getsentry
|
4
|
+
repo: sentry-ruby
|
5
|
+
changelogPolicy: simple
|
6
|
+
preReleaseCommand: ruby ../.scripts/bump-version.rb
|
7
|
+
releaseBranchPrefix: release-sentry-ruby
|
8
|
+
statusProvider:
|
9
|
+
name: github
|
10
|
+
artifactProvider:
|
11
|
+
name: github
|
12
|
+
targets:
|
13
|
+
- name: gem
|
14
|
+
- name: github
|
15
|
+
- name: registry
|
16
|
+
type: sdk
|
17
|
+
config:
|
18
|
+
canonical: 'gem:sentry-ruby'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at stan001212@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 st0012
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Sentry::Ruby
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sentry/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sentry-ruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sentry-ruby
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sentry-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/sentry-ruby/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the Sentry::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sentry-ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sentry/ruby"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/sentry.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "sentry/version"
|
2
|
+
require "sentry/core_ext/object/deep_dup"
|
3
|
+
require "sentry/configuration"
|
4
|
+
require "sentry/logger"
|
5
|
+
require "sentry/event"
|
6
|
+
require "sentry/hub"
|
7
|
+
require "sentry/rack"
|
8
|
+
|
9
|
+
module Sentry
|
10
|
+
class Error < StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
META = { "name" => "sentry.ruby", "version" => Sentry::VERSION }.freeze
|
14
|
+
|
15
|
+
LOGGER_PROGNAME = "sentry".freeze
|
16
|
+
|
17
|
+
THREAD_LOCAL = :sentry_hub
|
18
|
+
|
19
|
+
def self.sdk_meta
|
20
|
+
META
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def init(&block)
|
25
|
+
config = Configuration.new
|
26
|
+
yield(config)
|
27
|
+
client = Client.new(config)
|
28
|
+
scope = Scope.new
|
29
|
+
hub = Hub.new(client, scope)
|
30
|
+
Thread.current[THREAD_LOCAL] = hub
|
31
|
+
@main_hub = hub
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_main_hub
|
35
|
+
@main_hub
|
36
|
+
end
|
37
|
+
|
38
|
+
def logger
|
39
|
+
configuration.logger
|
40
|
+
end
|
41
|
+
|
42
|
+
def breadcrumbs
|
43
|
+
get_current_scope.breadcrumbs
|
44
|
+
end
|
45
|
+
|
46
|
+
def configuration
|
47
|
+
get_current_client.configuration
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_current_client
|
51
|
+
get_current_hub.current_client
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_current_hub
|
55
|
+
Thread.current[THREAD_LOCAL]
|
56
|
+
end
|
57
|
+
|
58
|
+
def clone_hub_to_current_thread
|
59
|
+
Thread.current[THREAD_LOCAL] = get_main_hub.clone
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_current_scope
|
63
|
+
get_current_hub.current_scope
|
64
|
+
end
|
65
|
+
|
66
|
+
def with_scope(&block)
|
67
|
+
get_current_hub.with_scope(&block)
|
68
|
+
end
|
69
|
+
|
70
|
+
def configure_scope(&block)
|
71
|
+
get_current_hub.configure_scope(&block)
|
72
|
+
end
|
73
|
+
|
74
|
+
def capture_event(event)
|
75
|
+
get_current_hub.capture_event(event)
|
76
|
+
end
|
77
|
+
|
78
|
+
def capture_exception(exception, **options, &block)
|
79
|
+
get_current_hub.capture_exception(exception, **options, &block)
|
80
|
+
end
|
81
|
+
|
82
|
+
def capture_message(message, **options, &block)
|
83
|
+
get_current_hub.capture_message(message, **options, &block)
|
84
|
+
end
|
85
|
+
|
86
|
+
def last_event_id
|
87
|
+
get_current_hub.last_event_id
|
88
|
+
end
|
89
|
+
|
90
|
+
def sys_command(command)
|
91
|
+
result = `#{command} 2>&1` rescue nil
|
92
|
+
return if result.nil? || result.empty? || ($CHILD_STATUS && $CHILD_STATUS.exitstatus != 0)
|
93
|
+
|
94
|
+
result.strip
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
## Inspired by Rails' and Airbrake's backtrace parsers.
|
4
|
+
|
5
|
+
module Sentry
|
6
|
+
# Front end to parsing the backtrace for each notice
|
7
|
+
class Backtrace
|
8
|
+
# Handles backtrace parsing line by line
|
9
|
+
class Line
|
10
|
+
RB_EXTENSION = ".rb"
|
11
|
+
# regexp (optional leading X: on windows, or JRuby9000 class-prefix)
|
12
|
+
RUBY_INPUT_FORMAT = /
|
13
|
+
^ \s* (?: [a-zA-Z]: | uri:classloader: )? ([^:]+ | <.*>):
|
14
|
+
(\d+)
|
15
|
+
(?: :in \s `([^']+)')?$
|
16
|
+
/x.freeze
|
17
|
+
|
18
|
+
# org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
|
19
|
+
JAVA_INPUT_FORMAT = /^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$/.freeze
|
20
|
+
|
21
|
+
# The file portion of the line (such as app/models/user.rb)
|
22
|
+
attr_reader :file
|
23
|
+
|
24
|
+
# The line number portion of the line
|
25
|
+
attr_reader :number
|
26
|
+
|
27
|
+
# The method of the line (such as index)
|
28
|
+
attr_reader :method
|
29
|
+
|
30
|
+
# The module name (JRuby)
|
31
|
+
attr_reader :module_name
|
32
|
+
|
33
|
+
attr_reader :in_app_pattern
|
34
|
+
|
35
|
+
# Parses a single line of a given backtrace
|
36
|
+
# @param [String] unparsed_line The raw line from +caller+ or some backtrace
|
37
|
+
# @return [Line] The parsed backtrace line
|
38
|
+
def self.parse(unparsed_line, in_app_pattern)
|
39
|
+
ruby_match = unparsed_line.match(RUBY_INPUT_FORMAT)
|
40
|
+
if ruby_match
|
41
|
+
_, file, number, method = ruby_match.to_a
|
42
|
+
file.sub!(/\.class$/, RB_EXTENSION)
|
43
|
+
module_name = nil
|
44
|
+
else
|
45
|
+
java_match = unparsed_line.match(JAVA_INPUT_FORMAT)
|
46
|
+
_, module_name, method, file, number = java_match.to_a
|
47
|
+
end
|
48
|
+
new(file, number, method, module_name, in_app_pattern)
|
49
|
+
end
|
50
|
+
|
51
|
+
def initialize(file, number, method, module_name, in_app_pattern)
|
52
|
+
@file = file
|
53
|
+
@module_name = module_name
|
54
|
+
@number = number.to_i
|
55
|
+
@method = method
|
56
|
+
@in_app_pattern = in_app_pattern
|
57
|
+
end
|
58
|
+
|
59
|
+
def in_app
|
60
|
+
if file =~ in_app_pattern
|
61
|
+
true
|
62
|
+
else
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Reconstructs the line in a readable fashion
|
68
|
+
def to_s
|
69
|
+
"#{file}:#{number}:in `#{method}'"
|
70
|
+
end
|
71
|
+
|
72
|
+
def ==(other)
|
73
|
+
to_s == other.to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
def inspect
|
77
|
+
"<Line:#{self}>"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
APP_DIRS_PATTERN = /(bin|exe|app|config|lib|test)/.freeze
|
82
|
+
|
83
|
+
# holder for an Array of Backtrace::Line instances
|
84
|
+
attr_reader :lines
|
85
|
+
attr_reader :configuration
|
86
|
+
|
87
|
+
def self.parse(backtrace, configuration:)
|
88
|
+
ruby_lines = backtrace.is_a?(Array) ? backtrace : backtrace.split(/\n\s*/)
|
89
|
+
|
90
|
+
ruby_lines = configuration.backtrace_cleanup_callback.call(ruby_lines) if configuration&.backtrace_cleanup_callback
|
91
|
+
|
92
|
+
in_app_pattern ||= begin
|
93
|
+
project_root = configuration.project_root&.to_s
|
94
|
+
Regexp.new("^(#{project_root}/)?#{configuration.app_dirs_pattern || APP_DIRS_PATTERN}")
|
95
|
+
end
|
96
|
+
|
97
|
+
lines = ruby_lines.to_a.map do |unparsed_line|
|
98
|
+
Line.parse(unparsed_line, in_app_pattern)
|
99
|
+
end
|
100
|
+
|
101
|
+
new(lines)
|
102
|
+
end
|
103
|
+
|
104
|
+
def initialize(lines)
|
105
|
+
@lines = lines
|
106
|
+
end
|
107
|
+
|
108
|
+
def inspect
|
109
|
+
"<Backtrace: " + lines.map(&:inspect).join(", ") + ">"
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_s
|
113
|
+
content = []
|
114
|
+
lines.each do |line|
|
115
|
+
content << line
|
116
|
+
end
|
117
|
+
content.join("\n")
|
118
|
+
end
|
119
|
+
|
120
|
+
def ==(other)
|
121
|
+
if other.respond_to?(:lines)
|
122
|
+
lines == other.lines
|
123
|
+
else
|
124
|
+
false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|