sentry-ruby 0.1.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd48cd818d98c18e281aab8c37346fc7dc204b78396afe0ccaa64fa3cc8c0d2f
4
- data.tar.gz: 2d4f7e657e9a3abc1d1063aa73e86ef7d9e09b0e5205f2a16b54d2242955316e
3
+ metadata.gz: 517bd830d9052aef4d3c9011f95e1d95f7740fae3bfdd746ece393766f637d84
4
+ data.tar.gz: 0b25ac7ffe3abf0c8b0a153681952bd36315fe406341add2e7e724632ca74d35
5
5
  SHA512:
6
- metadata.gz: 612e9205c0d42c107a9a3a1d5b7bc759fd4daae5ede8ffd0efec1a0c3d1aa22860669f5f4d5a244397dcfe481f7784ae3f23c42c9e316338702cf372f8610e48
7
- data.tar.gz: 45535f8367e8b37ba0f106b78ee2e9b7f40622ccb9b7207ba34ee49238600c6885a16125f15ff65957d713871f576b8579ecdbc88fbfb45cc6feecab0e64b1aa
6
+ metadata.gz: a717d3e5286400706e44f8bf1a17d6901e5fc7149efbff7f2f70758b1ac5c4f0f134f0d875a5543fa95777013aa1b0b0168f7c41fa149316bd9ced3a2f4ed48e
7
+ data.tar.gz: ad58cf9e97b482ff9b3107a677d1bc03d3429bba26052f908ce43b25635985f65525b3345afccd1488d5c94eabb0c6565b1ce16d003859da2e359f6ccbdd1eb9
data/.craft.yml CHANGED
@@ -12,6 +12,7 @@ artifactProvider:
12
12
  targets:
13
13
  - name: gem
14
14
  - name: github
15
+ tagPrefix: sentry-ruby-v
15
16
  - name: registry
16
17
  type: sdk
17
18
  config:
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.0.0
4
+
5
+ - Only documents update for the official release and no API/feature changes.
6
+
7
+ ## 0.3.0
8
+
9
+ - Major API changes: [1123](https://github.com/getsentry/sentry-ruby/pull/1123)
10
+ - Support event hint: [1122](https://github.com/getsentry/sentry-ruby/pull/1122)
11
+ - Add request-id tag to events: [1120](https://github.com/getsentry/sentry-ruby/pull/1120) (by @tvec)
12
+
13
+ ## 0.2.0
14
+
15
+ - Multiple fixes and refactorings
16
+ - Tracing support
17
+
18
+ ## 0.1.3
19
+
20
+ Fix require reference
21
+
22
+ ## 0.1.2
23
+
24
+ - Fix: Fix async callback [1098](https://github.com/getsentry/sentry-ruby/pull/1098)
25
+ - Refactor: Some code cleanup [1100](https://github.com/getsentry/sentry-ruby/pull/1100)
26
+ - Refactor: Remove Event options [1101](https://github.com/getsentry/sentry-ruby/pull/1101)
27
+
3
28
  ## 0.1.1
4
29
 
5
30
  - Feature: Allow passing custom scope to Hub#capture* helpers [1086](https://github.com/getsentry/sentry-ruby/pull/1086)
data/Gemfile CHANGED
@@ -9,3 +9,8 @@ gem "codecov"
9
9
 
10
10
  gem "pry"
11
11
  gem "rack"
12
+
13
+ gem "benchmark-ips"
14
+ gem "benchmark_driver"
15
+ gem "benchmark-ipsa"
16
+ gem "benchmark-memory"
data/README.md CHANGED
@@ -1,44 +1,220 @@
1
- # Sentry::Ruby
1
+ <p align="center">
2
+ <a href="https://sentry.io" target="_blank" align="center">
3
+ <img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
4
+ </a>
5
+ <br>
6
+ </p>
2
7
 
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.
8
+ # sentry-ruby, the Ruby Client for Sentry
4
9
 
5
- TODO: Delete this and the text above, and describe your gem
10
+ **The old `sentry-raven` client has entered maintenance mode and was moved to [here](https://github.com/getsentry/sentry-ruby/tree/master/sentry-raven).**
6
11
 
7
- ## Installation
12
+ ---
8
13
 
9
- Add this line to your application's Gemfile:
14
+
15
+ [![Gem Version](https://img.shields.io/gem/v/sentry-ruby.svg)](https://rubygems.org/gems/sentry-ruby)
16
+ ![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-ruby%20Test/badge.svg)
17
+ [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
18
+ [![Gem](https://img.shields.io/gem/dt/sentry-ruby.svg)](https://rubygems.org/gems/sentry-ruby/)
19
+ [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-ruby&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-ruby&package-manager=bundler&version-scheme=semver)
20
+
21
+
22
+ [Documentation](https://docs.sentry.io/platforms/ruby/) | [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues) | [Forum](https://forum.sentry.io/) | IRC: irc.freenode.net, #sentry
23
+
24
+ The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.
25
+
26
+
27
+ ## Requirements
28
+
29
+ We test on Ruby 2.4, 2.5, 2.6 and 2.7 at the latest patchlevel/teeny version. We also support JRuby 9.0.
30
+
31
+ ## Getting Started
32
+
33
+ ### Install
34
+
35
+ ```ruby
36
+ gem "sentry-ruby"
37
+ ```
38
+
39
+ and depends on the integrations you want to have, you might also want to install these:
40
+
41
+ ```ruby
42
+ gem "sentry-rails"
43
+ gem "sentry-sidekiq"
44
+ # and mores to come in the future!
45
+ ```
46
+
47
+ ### Sentry only runs when Sentry DSN is set
48
+
49
+ Sentry will capture and send exceptions to the Sentry server whenever its DSN is set. This makes environment-based configuration easy - if you don't want to send errors in a certain environment, just don't set the DSN in that environment!
50
+
51
+ ```bash
52
+ # Set your SENTRY_DSN environment variable.
53
+ export SENTRY_DSN=http://public@example.com/project-id
54
+ ```
55
+ ```ruby
56
+ # Or you can configure the client in the code.
57
+ Sentry.init do |config|
58
+ config.dsn = 'http://public@example.com/project-id'
59
+ end
60
+ ```
61
+
62
+ ### Sentry doesn't report some kinds of data by default
63
+
64
+ **Sentry ignores some exceptions by default** - most of these are related to 404s parameter parsing errors. [For a complete list, see the `IGNORE_DEFAULT` constant](https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/configuration.rb#L118) and the integration gems' `IGNORE_DEFAULT`, like [`sentry-rails`'s](https://github.com/getsentry/sentry-ruby/blob/update-readme/sentry-rails/lib/sentry/rails/configuration.rb#L12)
65
+
66
+ Sentry doesn't send personally identifiable information (pii) by default, such as request body, user ip or cookies. If you want those information to be sent, you can use the `send_default_pii` config option:
67
+
68
+ ```ruby
69
+ Sentry.init do |config|
70
+ # other configs
71
+ config.send_default_pii = true
72
+ end
73
+ ```
74
+
75
+ ### Performance Monitoring
76
+
77
+ You can activate performance monitoring by enabling traces sampling:
78
+
79
+ ```ruby
80
+ Sentry.init do |config|
81
+ # set a uniform sample rate between 0.0 and 1.0
82
+ config.traces_sample_rate = 0.2
83
+
84
+ # or control sampling dynamically
85
+ config.traces_sampler = lambda do |sampling_context|
86
+ # sampling_context[:transaction_context] contains the information about the transaction
87
+ # sampling_context[:parent_sampled] contains the transaction's parent's sample decision
88
+ true # return value can be a boolean or a float between 0.0 and 1.0
89
+ end
90
+ end
91
+ ```
92
+
93
+ To lean more about performance monitoring, please visit the [official documentation](https://docs.sentry.io/platforms/ruby/performance).
94
+
95
+ ### Usage
96
+
97
+ `sentry-ruby` has a default integration with `Rack`, so you only need to use the middleware in your application like:
98
+
99
+ ```ruby
100
+ require 'sentry-ruby'
101
+
102
+ Sentry.init do |config|
103
+ config.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0'
104
+
105
+ # To activate performance monitoring, set one of these options.
106
+ # We recommend adjusting the value in production:
107
+ config.traces_sample_rate = 0.5
108
+ # or
109
+ config.traces_sampler = lambda do |context|
110
+ true
111
+ end
112
+ end
113
+
114
+ use Sentry::Rack::Tracing # this needs to be placed first
115
+ use Sentry::Rack::CaptureException
116
+ ```
117
+
118
+ Otherwise, Sentry you can always use the capture helpers manually
119
+
120
+ ```ruby
121
+ Sentry.capture_message("hello world!")
122
+
123
+ begin
124
+ 1 / 0
125
+ rescue ZeroDivisionError => exception
126
+ Sentry.capture_exception(exception)
127
+ end
128
+ ```
129
+
130
+ We also provide integrations with popular frameworks/libraries with the related extensions:
131
+
132
+ - [sentry-rails](https://github.com/getsentry/sentry-ruby/tree/master/sentry-rails)
133
+ - [sentry-sidekiq](https://github.com/getsentry/sentry-ruby/tree/master/sentry-sidekiq)
134
+
135
+ ### More configuration
136
+
137
+ You're all set - but there's a few more settings you may want to know about too!
138
+
139
+ #### async
140
+
141
+ When an error or message occurs, the notification is immediately sent to Sentry. Sentry can be configured to send asynchronously:
142
+
143
+ ```ruby
144
+ config.async = lambda { |event|
145
+ Thread.new { Sentry.send_event(event) }
146
+ }
147
+ ```
148
+
149
+ Using a thread to send events will be adequate for truly parallel Ruby platforms such as JRuby, though the benefit on MRI/CRuby will be limited. If the async callback raises an exception, Sentry will attempt to send synchronously.
150
+
151
+ Note that the naive example implementation has a major drawback - it can create an infinite number of threads. We recommend creating a background job, using your background job processor, that will send Sentry notifications in the background.
10
152
 
11
153
  ```ruby
12
- gem 'sentry-ruby'
154
+ config.async = lambda { |event| SentryJob.perform_later(event) }
155
+
156
+ class SentryJob < ActiveJob::Base
157
+ queue_as :default
158
+
159
+ def perform(event)
160
+ Sentry.send_event(event)
161
+ end
162
+ end
13
163
  ```
14
164
 
15
- And then execute:
165
+ #### Contexts
16
166
 
17
- $ bundle install
167
+ In sentry-ruby, every event will inherit their contextual data from the current scope. So you can enrich the event's data by configuring the current scope like:
18
168
 
19
- Or install it yourself as:
169
+ ```ruby
170
+ Sentry.configure_scope do |scope|
171
+ scope.set_user(id: 1, email: "test@example.com")
20
172
 
21
- $ gem install sentry-ruby
173
+ scope.set_tag(:tag, "foo")
174
+ scope.set_tags(tag_1: "foo", tag_2: "bar")
22
175
 
23
- ## Usage
176
+ scope.set_extra(:order_number, 1234)
177
+ scope.set_extras(order_number: 1234, tickets_count: 4)
178
+ end
24
179
 
25
- TODO: Write usage instructions here
180
+ Sentry.capture_exception(exception) # the event will carry all those information now
181
+ ```
26
182
 
27
- ## Development
183
+ Or use top-level setters
28
184
 
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
185
 
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).
186
+ ```ruby
187
+ Sentry.set_user(id: 1, email: "test@example.com")
188
+ Sentry.set_tags(tag_1: "foo", tag_2: "bar")
189
+ Sentry.set_extras(order_number: 1234, tickets_count: 4)
32
190
 
33
- ## Contributing
191
+ ```
192
+
193
+ Or build up a temporary scope for local information:
194
+
195
+ ```ruby
196
+ Sentry.configure_scope do |scope|
197
+ scope.set_tags(tag_1: "foo")
198
+ end
34
199
 
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).
200
+ Sentry.with_scope do |scope|
201
+ scope.set_tags(tag_1: "bar", tag_2: "baz")
36
202
 
203
+ Sentry.capture_message("message") # this event will have 2 tags: tag_1 => "bar" and tag_2 => "baz"
204
+ end
37
205
 
38
- ## License
206
+ Sentry.capture_message("another message") # this event will have 1 tag: tag_1 => "foo"
207
+ ```
208
+
209
+ Of course, you can always assign the information on a per-event basis:
39
210
 
40
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
211
+ ```ruby
212
+ Sentry.capture_exception(exception, tags: {foo: "bar"})
213
+ ```
41
214
 
42
- ## Code of Conduct
215
+ ## More Information
43
216
 
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).
217
+ * [Documentation](https://docs.sentry.io/platforms/ruby/)
218
+ * [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues)
219
+ * [Forum](https://forum.sentry.io/)
220
+ - [Discord](https://discord.gg/ez5KZN7)
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new(:spec).tap do |task|
5
+ task.rspec_opts = "--order rand"
6
+ end
5
7
 
6
8
  task :default => :spec
@@ -1,8 +1,13 @@
1
+ require "forwardable"
2
+
1
3
  require "sentry/version"
2
4
  require "sentry/core_ext/object/deep_dup"
3
5
  require "sentry/configuration"
4
6
  require "sentry/logger"
5
7
  require "sentry/event"
8
+ require "sentry/transaction_event"
9
+ require "sentry/span"
10
+ require "sentry/transaction"
6
11
  require "sentry/hub"
7
12
  require "sentry/rack"
8
13
 
@@ -20,7 +25,15 @@ module Sentry
20
25
  META
21
26
  end
22
27
 
28
+ def self.utc_now
29
+ Time.now.utc
30
+ end
31
+
23
32
  class << self
33
+ extend Forwardable
34
+
35
+ def_delegators :get_current_scope, :set_tags, :set_extras, :set_user
36
+
24
37
  def init(&block)
25
38
  config = Configuration.new
26
39
  yield(config)
@@ -39,8 +52,8 @@ module Sentry
39
52
  configuration.logger
40
53
  end
41
54
 
42
- def breadcrumbs
43
- get_current_scope.breadcrumbs
55
+ def add_breadcrumb(breadcrumb, &block)
56
+ get_current_scope.breadcrumbs.record(breadcrumb, &block)
44
57
  end
45
58
 
46
59
  def configuration
@@ -52,7 +65,12 @@ module Sentry
52
65
  end
53
66
 
54
67
  def get_current_hub
55
- Thread.current[THREAD_LOCAL]
68
+ # we need to assign a hub to the current thread if it doesn't have one yet
69
+ #
70
+ # ideally, we should do this proactively whenever a new thread is created
71
+ # but it's impossible for the SDK to keep track every new thread
72
+ # so we need to use this rather passive way to make sure the app doesn't crash
73
+ Thread.current[THREAD_LOCAL] || clone_hub_to_current_thread
56
74
  end
57
75
 
58
76
  def clone_hub_to_current_thread
@@ -71,6 +89,10 @@ module Sentry
71
89
  get_current_hub.configure_scope(&block)
72
90
  end
73
91
 
92
+ def send_event(event)
93
+ get_current_client.send_event(event)
94
+ end
95
+
74
96
  def capture_event(event)
75
97
  get_current_hub.capture_event(event)
76
98
  end
@@ -83,6 +105,10 @@ module Sentry
83
105
  get_current_hub.capture_message(message, **options, &block)
84
106
  end
85
107
 
108
+ def start_transaction(**options)
109
+ get_current_hub.start_transaction(**options)
110
+ end
111
+
86
112
  def last_event_id
87
113
  get_current_hub.last_event_id
88
114
  end
@@ -0,0 +1,14 @@
1
+ module Sentry
2
+ class BenchmarkTransport < Transport
3
+ attr_accessor :events
4
+
5
+ def initialize(*)
6
+ super
7
+ @events = []
8
+ end
9
+
10
+ def send_event(event)
11
+ @events << encode(event.to_hash)
12
+ end
13
+ end
14
+ end
@@ -2,13 +2,13 @@ module Sentry
2
2
  class Breadcrumb
3
3
  attr_accessor :category, :data, :message, :level, :timestamp, :type
4
4
 
5
- def initialize
6
- @category = nil
7
- @data = {}
8
- @level = nil
9
- @message = nil
10
- @timestamp = Time.now.to_i
11
- @type = nil
5
+ def initialize(category: nil, data: nil, message: nil, timestamp: nil, level: nil, type: nil)
6
+ @category = category
7
+ @data = data || {}
8
+ @level = level
9
+ @message = message
10
+ @timestamp = timestamp || Sentry.utc_now.to_i
11
+ @type = type
12
12
  end
13
13
 
14
14
  def to_hash
@@ -58,17 +58,15 @@ module Sentry
58
58
  last_crumb = current_breadcrumbs.peek
59
59
  # try to avoid dupes from logger broadcasts
60
60
  if last_crumb.nil? || last_crumb.message != message
61
- current_breadcrumbs.record do |crumb|
62
- crumb.level = Sentry::Breadcrumb::SentryLogger::LEVELS.fetch(severity, nil)
63
- crumb.category = category
64
- crumb.message = message
65
- crumb.type =
66
- if severity >= 3
67
- "error"
68
- else
69
- crumb.level
70
- end
71
- end
61
+ level = Sentry::Breadcrumb::SentryLogger::LEVELS.fetch(severity, nil)
62
+ crumb = Sentry::Breadcrumb.new(
63
+ level: level,
64
+ category: category,
65
+ message: message,
66
+ type: severity >= 3 ? "error" : level
67
+ )
68
+
69
+ Sentry.add_breadcrumb(crumb)
72
70
  end
73
71
  end
74
72
 
@@ -80,21 +78,7 @@ module Sentry
80
78
  end
81
79
 
82
80
  def current_breadcrumbs
83
- Sentry.breadcrumbs
84
- end
85
- end
86
- module OldBreadcrumbsSentryLogger
87
- def self.included(base)
88
- base.class_eval do
89
- include Sentry::Breadcrumbs::SentryLogger
90
- alias_method :add_without_sentry, :add
91
- alias_method :add, :add_with_sentry
92
- end
93
- end
94
-
95
- def add_with_sentry(*args)
96
- add_breadcrumb(*args)
97
- add_without_sentry(*args)
81
+ Sentry.get_current_scope.breadcrumbs
98
82
  end
99
83
  end
100
84
  end