oopsie-ruby 0.1.0 → 0.2.1

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: 2e85dbb6b0f79d5c507a3946954eb6d8bf0535608511f0acd3d096b610378f8c
4
- data.tar.gz: 67f2bea5aff602e5b740829545a89c4b57ff922dc8ef17e5c773cb844bbb8d9d
3
+ metadata.gz: 5ff40c89fa6516c17e8a5a02ed3f7550cf45ca513dffa9bb26d45c54b0231088
4
+ data.tar.gz: 9cabfe2768c79d863f72baed672b38aa66e9d857643894dbeb8b8811c4d6ac12
5
5
  SHA512:
6
- metadata.gz: 04f073013567b2a8568592f868eb2b76b8ea60bb35b28bf6edb7612d5272552d3ffa3e20a6f771505a9242212f6d760f8fb8fa950f62c9840531704ce4fb9b3d
7
- data.tar.gz: 4d903125f43c396cf03c50a07977862058b306b7a424ae0138e074b75bd1530d07d25964e72c244cbd5e1d0317b1b98a3b60a3ea947a2f0a1049940d99fb4e51
6
+ metadata.gz: '048030135d4f548c5760fd7db50dead43cdd2da14c8369af570a5bc69a6e6e9aa5022b14bf43746afc5212f1e82718cdb6183b4e2b0b8d23a31092e6c9eb0813'
7
+ data.tar.gz: cceeacdd7d1acb7360f1ff21c2e98db35e538bfc950cd982c7c4da4966afb715b3b0eb32dfe268f4b557c16166720a1b86bd314f7e862db49901047fdf78a7bd
data/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  Lightweight Ruby gem that reports exceptions to an [Oopsie](https://github.com/jacobespersen/oopsie) instance.
4
4
 
5
5
  - Zero runtime dependencies (uses Ruby stdlib)
6
- - Rack middleware for automatic error capture
6
+ - Automatic error capture in Rails and Rack apps
7
+ - Sidekiq integration for background job errors
7
8
  - Manual `Oopsie.report(e)` API
8
9
  - Silent failures with optional `on_error` callback
9
10
 
@@ -28,6 +29,9 @@ Oopsie.configure do |config|
28
29
  config.api_key = ENV["OOPSIE_API_KEY"]
29
30
  config.endpoint = "https://your-oopsie-instance.com"
30
31
 
32
+ # Optional: exceptions to ignore (subclasses are also ignored)
33
+ config.ignored_exceptions = [ActiveRecord::RecordNotFound, ActionController::RoutingError]
34
+
31
35
  # Optional: called when error reporting itself fails
32
36
  config.on_error = ->(e) { Rails.logger.warn("Oopsie error: #{e.message}") }
33
37
  end
@@ -44,22 +48,39 @@ Oopsie.configure do |config|
44
48
  end
45
49
  ```
46
50
 
51
+ ## Rails
52
+
53
+ In Rails apps, the gem automatically:
54
+
55
+ - Inserts Rack middleware to capture unhandled exceptions
56
+ - Subscribes to `process_action.action_controller` notifications to capture errors handled by `rescue_from` in controllers and GraphQL schemas
57
+
58
+ No manual middleware setup needed — just add the gem and configure it.
59
+
47
60
  ## Rack Middleware
48
61
 
49
- Add the middleware to automatically capture unhandled exceptions:
62
+ For non-Rails Rack apps, add the middleware manually:
50
63
 
51
64
  ```ruby
52
65
  # config.ru
53
66
  use Oopsie::Middleware
54
67
  ```
55
68
 
56
- In Rails, add to `config/application.rb`:
69
+ The middleware reports the error and re-raises it, so your existing error handling is unaffected.
70
+
71
+ ## Sidekiq
72
+
73
+ To capture Sidekiq job errors, add the error handler in your Sidekiq server config:
57
74
 
58
75
  ```ruby
59
- config.middleware.use Oopsie::Middleware
76
+ require "oopsie/sidekiq"
77
+
78
+ Sidekiq.configure_server do |config|
79
+ config.error_handlers << Oopsie::Sidekiq::ErrorHandler.new
80
+ end
60
81
  ```
61
82
 
62
- The middleware reports the error and re-raises it, so your existing error handling is unaffected.
83
+ This reports on every job failure attempt, not just when retries are exhausted. Requires Sidekiq 7+.
63
84
 
64
85
  ## Manual Reporting
65
86
 
@@ -4,9 +4,13 @@ module Oopsie
4
4
  class ConfigurationError < StandardError; end
5
5
 
6
6
  class Configuration
7
- attr_accessor :api_key, :on_error
7
+ attr_accessor :api_key, :on_error, :ignored_exceptions
8
8
  attr_reader :endpoint
9
9
 
10
+ def initialize
11
+ @ignored_exceptions = []
12
+ end
13
+
10
14
  def endpoint=(value)
11
15
  @endpoint = value&.chomp('/')
12
16
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+ require 'active_support/isolated_execution_state'
5
+ require 'active_support/notifications'
6
+
7
+ module Oopsie
8
+ class Railtie < Rails::Railtie
9
+ initializer 'oopsie.middleware' do |app|
10
+ unless app.middleware.include?(Oopsie::Middleware)
11
+ app.middleware.insert_before ActionDispatch::ShowExceptions, Oopsie::Middleware
12
+ end
13
+ end
14
+
15
+ initializer 'oopsie.subscribe' do
16
+ ActiveSupport::Notifications.subscribe('process_action.action_controller') do |event|
17
+ if (exception = event.payload[:exception_object])
18
+ Oopsie.report(exception)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'oopsie'
4
+
5
+ module Oopsie
6
+ module Sidekiq
7
+ class ErrorHandler
8
+ def call(exception, *)
9
+ Oopsie.report(exception)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Oopsie
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "oopsie"
data/lib/oopsie.rb CHANGED
@@ -4,6 +4,7 @@ require_relative 'oopsie/version'
4
4
  require_relative 'oopsie/configuration'
5
5
  require_relative 'oopsie/client'
6
6
  require_relative 'oopsie/middleware'
7
+ require_relative 'oopsie/railtie' if defined?(Rails::Railtie)
7
8
 
8
9
  module Oopsie
9
10
  class << self
@@ -20,6 +21,9 @@ module Oopsie
20
21
  end
21
22
 
22
23
  def report(exception)
24
+ return if skip_report?(exception)
25
+
26
+ tag_reported(exception)
23
27
  configuration.validate!
24
28
  Client.new(configuration).send_error(
25
29
  error_class: exception.class.name,
@@ -32,6 +36,17 @@ module Oopsie
32
36
 
33
37
  private
34
38
 
39
+ def skip_report?(exception)
40
+ configuration.ignored_exceptions.any? { |klass| exception.is_a?(klass) } ||
41
+ exception.instance_variable_get(:@_oopsie_reported)
42
+ end
43
+
44
+ def tag_reported(exception)
45
+ exception.instance_variable_set(:@_oopsie_reported, true)
46
+ rescue FrozenError
47
+ # Frozen exceptions can't be tagged — skip dedup, proceed with reporting
48
+ end
49
+
35
50
  def safely_notify_error(error)
36
51
  configuration.on_error&.call(error)
37
52
  rescue StandardError
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oopsie-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oopsie
@@ -9,6 +9,34 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: actionpack
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '7.1'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '7.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.1'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '7.1'
12
40
  - !ruby/object:Gem::Dependency
13
41
  name: bundler
14
42
  requirement: !ruby/object:Gem::Requirement
@@ -37,6 +65,20 @@ dependencies:
37
65
  - - "~>"
38
66
  - !ruby/object:Gem::Version
39
67
  version: '2.1'
68
+ - !ruby/object:Gem::Dependency
69
+ name: railties
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '7.1'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '7.1'
40
82
  - !ruby/object:Gem::Dependency
41
83
  name: rake
42
84
  requirement: !ruby/object:Gem::Requirement
@@ -101,10 +143,13 @@ extra_rdoc_files: []
101
143
  files:
102
144
  - LICENSE
103
145
  - README.md
146
+ - lib/oopsie-ruby.rb
104
147
  - lib/oopsie.rb
105
148
  - lib/oopsie/client.rb
106
149
  - lib/oopsie/configuration.rb
107
150
  - lib/oopsie/middleware.rb
151
+ - lib/oopsie/railtie.rb
152
+ - lib/oopsie/sidekiq.rb
108
153
  - lib/oopsie/version.rb
109
154
  homepage: https://github.com/jacobespersen/oopsie-ruby
110
155
  licenses: