bugwatch-ruby 0.8.2 → 0.9.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 +4 -4
- data/README.md +1 -1
- data/lib/bugwatch/configuration.rb +3 -1
- data/lib/bugwatch/error_subscriber.rb +1 -1
- data/lib/bugwatch/middleware.rb +24 -0
- data/lib/bugwatch/railtie.rb +6 -0
- data/lib/bugwatch/request_context.rb +17 -0
- data/lib/bugwatch/rescued_exception_tracker.rb +33 -0
- data/lib/bugwatch/version.rb +1 -1
- data/lib/bugwatch.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 16b9f0663124f395ce3f847b174384f20ae2a6eebafecaa8b9d29e86c5f29a57
|
|
4
|
+
data.tar.gz: '0528308ae35c383abb64ca3fce2234cdd770d07506eb21e4345727db5fe12dcd'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '018452ddc1525fe5cb05cf791fab88189124840bb465ff37a5458655f4a1a5d6c0e8c563326edf58751f5278324c6caa15d5ebe46b6b493da0818a8ab75c4c41'
|
|
7
|
+
data.tar.gz: 3e47cdf1fca8789b36ccbee6df15b22935f685d25ffa71bef2664d531715d251aeefbcd77e385563d9cc3ec88a2961d15d5e3769cb208022a409ff74efe12215
|
data/README.md
CHANGED
|
@@ -16,7 +16,8 @@ module Bugwatch
|
|
|
16
16
|
:max_queries_per_request,
|
|
17
17
|
:enable_http_tracking,
|
|
18
18
|
:http_sample_rate,
|
|
19
|
-
:max_http_calls_per_request
|
|
19
|
+
:max_http_calls_per_request,
|
|
20
|
+
:enable_rescued_exception_tracking
|
|
20
21
|
|
|
21
22
|
def initialize
|
|
22
23
|
@endpoint = nil
|
|
@@ -34,6 +35,7 @@ module Bugwatch
|
|
|
34
35
|
@enable_http_tracking = true
|
|
35
36
|
@http_sample_rate = 1.0
|
|
36
37
|
@max_http_calls_per_request = 100
|
|
38
|
+
@enable_rescued_exception_tracking = false
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
def notify_for_release_stage?
|
|
@@ -5,7 +5,7 @@ module Bugwatch
|
|
|
5
5
|
return unless Bugwatch.configuration.notify_for_release_stage?
|
|
6
6
|
return if ReportedExceptions.reported?(error)
|
|
7
7
|
|
|
8
|
-
payload = ErrorBuilder.new(error).build
|
|
8
|
+
payload = ErrorBuilder.new(error, RequestContext.get).build
|
|
9
9
|
payload[:context] = context.merge(
|
|
10
10
|
handled: handled,
|
|
11
11
|
severity: severity,
|
data/lib/bugwatch/middleware.rb
CHANGED
|
@@ -13,6 +13,7 @@ module Bugwatch
|
|
|
13
13
|
BreadcrumbCollector.clear
|
|
14
14
|
UserContext.clear
|
|
15
15
|
ReportedExceptions.clear
|
|
16
|
+
RequestContext.set(env)
|
|
16
17
|
|
|
17
18
|
config = Bugwatch.configuration
|
|
18
19
|
collecting = config.enable_db_tracking && (rand < config.db_sample_rate)
|
|
@@ -21,8 +22,12 @@ module Bugwatch
|
|
|
21
22
|
collecting_http = config.enable_http_tracking && (rand < config.http_sample_rate)
|
|
22
23
|
HttpTracker.start_request(collecting: collecting_http)
|
|
23
24
|
|
|
25
|
+
tracking_rescued = config.enable_rescued_exception_tracking
|
|
26
|
+
RescuedExceptionTracker.start_request if tracking_rescued
|
|
27
|
+
|
|
24
28
|
begin
|
|
25
29
|
status, headers, body = @app.call(env)
|
|
30
|
+
report_rescued_exceptions(env) if tracking_rescued
|
|
26
31
|
record_transaction(env, status, start)
|
|
27
32
|
[status, headers, body]
|
|
28
33
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
@@ -42,6 +47,8 @@ module Bugwatch
|
|
|
42
47
|
record_transaction(env, 500, start)
|
|
43
48
|
raise
|
|
44
49
|
ensure
|
|
50
|
+
RescuedExceptionTracker.clear if tracking_rescued
|
|
51
|
+
RequestContext.clear
|
|
45
52
|
DbTracker.clear
|
|
46
53
|
HttpTracker.clear
|
|
47
54
|
end
|
|
@@ -49,6 +56,23 @@ module Bugwatch
|
|
|
49
56
|
|
|
50
57
|
private
|
|
51
58
|
|
|
59
|
+
def report_rescued_exceptions(env)
|
|
60
|
+
seen = {}
|
|
61
|
+
RescuedExceptionTracker.collected.each do |exc|
|
|
62
|
+
next if seen[exc.object_id]
|
|
63
|
+
seen[exc.object_id] = true
|
|
64
|
+
next if Bugwatch.configuration.ignore?(exc)
|
|
65
|
+
next if ReportedExceptions.reported?(exc)
|
|
66
|
+
|
|
67
|
+
payload = ErrorBuilder.new(exc, env).build
|
|
68
|
+
payload[:context] = { handled: true, rescued_inline: true }
|
|
69
|
+
Notification.new(payload).deliver
|
|
70
|
+
ReportedExceptions.mark(exc)
|
|
71
|
+
end
|
|
72
|
+
rescue StandardError
|
|
73
|
+
# Never let tracking break the app
|
|
74
|
+
end
|
|
75
|
+
|
|
52
76
|
def skip_path?(env)
|
|
53
77
|
path = env["PATH_INFO"].to_s
|
|
54
78
|
Bugwatch.configuration.ignore_request_paths.any? { |pattern| path.match?(pattern) }
|
data/lib/bugwatch/railtie.rb
CHANGED
|
@@ -46,6 +46,12 @@ module Bugwatch
|
|
|
46
46
|
prepend Bugwatch::ControllerRescueHook
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
|
+
|
|
50
|
+
initializer "bugwatch.rescued_exception_tracking" do
|
|
51
|
+
if Bugwatch.configuration.enable_rescued_exception_tracking
|
|
52
|
+
Bugwatch::RescuedExceptionTracker.enable!
|
|
53
|
+
end
|
|
54
|
+
end
|
|
49
55
|
end
|
|
50
56
|
|
|
51
57
|
module ControllerMethods
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Bugwatch
|
|
2
|
+
module RequestContext
|
|
3
|
+
THREAD_KEY = :bugwatch_rack_env
|
|
4
|
+
|
|
5
|
+
def self.set(env)
|
|
6
|
+
Thread.current[THREAD_KEY] = env
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.get
|
|
10
|
+
Thread.current[THREAD_KEY]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.clear
|
|
14
|
+
Thread.current[THREAD_KEY] = nil
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Bugwatch
|
|
2
|
+
class RescuedExceptionTracker
|
|
3
|
+
THREAD_KEY = :bugwatch_rescued_exceptions
|
|
4
|
+
|
|
5
|
+
@tracepoint = TracePoint.new(:raise) do |_tp|
|
|
6
|
+
list = Thread.current[THREAD_KEY]
|
|
7
|
+
if list
|
|
8
|
+
exc = _tp.raised_exception
|
|
9
|
+
list << exc if exc.is_a?(StandardError)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.enable!
|
|
14
|
+
@tracepoint.enable unless @tracepoint.enabled?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.disable!
|
|
18
|
+
@tracepoint.disable if @tracepoint.enabled?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.start_request
|
|
22
|
+
Thread.current[THREAD_KEY] = []
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.collected
|
|
26
|
+
Thread.current[THREAD_KEY] || []
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.clear
|
|
30
|
+
Thread.current[THREAD_KEY] = nil
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/bugwatch/version.rb
CHANGED
data/lib/bugwatch.rb
CHANGED
|
@@ -7,6 +7,7 @@ require_relative "bugwatch/user_context"
|
|
|
7
7
|
require_relative "bugwatch/breadcrumb_collector"
|
|
8
8
|
require_relative "bugwatch/backtrace_cleaner"
|
|
9
9
|
require_relative "bugwatch/reported_exceptions"
|
|
10
|
+
require_relative "bugwatch/request_context"
|
|
10
11
|
require_relative "bugwatch/error_builder"
|
|
11
12
|
require_relative "bugwatch/report_builder"
|
|
12
13
|
require_relative "bugwatch/notification"
|
|
@@ -24,6 +25,7 @@ require_relative "bugwatch/middleware"
|
|
|
24
25
|
require_relative "bugwatch/active_job_handler"
|
|
25
26
|
require_relative "bugwatch/error_subscriber"
|
|
26
27
|
require_relative "bugwatch/controller_rescue_hook"
|
|
28
|
+
require_relative "bugwatch/rescued_exception_tracker"
|
|
27
29
|
require_relative "bugwatch/railtie" if defined?(Rails::Railtie)
|
|
28
30
|
|
|
29
31
|
module Bugwatch
|
|
@@ -41,7 +43,7 @@ module Bugwatch
|
|
|
41
43
|
return unless configuration.notify_for_release_stage?
|
|
42
44
|
return if ReportedExceptions.reported?(exception)
|
|
43
45
|
|
|
44
|
-
payload = ErrorBuilder.new(exception).build
|
|
46
|
+
payload = ErrorBuilder.new(exception, RequestContext.get).build
|
|
45
47
|
payload.merge!(context)
|
|
46
48
|
Notification.new(payload).deliver
|
|
47
49
|
ReportedExceptions.mark(exception)
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bugwatch-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- BugWatch
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-06-18 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: railties
|
|
@@ -68,6 +68,8 @@ files:
|
|
|
68
68
|
- lib/bugwatch/railtie.rb
|
|
69
69
|
- lib/bugwatch/report_builder.rb
|
|
70
70
|
- lib/bugwatch/reported_exceptions.rb
|
|
71
|
+
- lib/bugwatch/request_context.rb
|
|
72
|
+
- lib/bugwatch/rescued_exception_tracker.rb
|
|
71
73
|
- lib/bugwatch/transaction_buffer.rb
|
|
72
74
|
- lib/bugwatch/transaction_sender.rb
|
|
73
75
|
- lib/bugwatch/user_context.rb
|