bugwatch-ruby 0.3.0 → 0.4.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 +59 -0
- data/lib/bugwatch/active_job_handler.rb +26 -0
- data/lib/bugwatch/error_subscriber.rb +17 -0
- data/lib/bugwatch/railtie.rb +15 -0
- data/lib/bugwatch/version.rb +1 -1
- data/lib/bugwatch.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a9d4ff0ad03b9ab70f5f37f3a4656f7b1746a86c22ee33e429242c08c0527036
|
|
4
|
+
data.tar.gz: 0a9c5bc904036439926f2e7097d07db78d8e5139ed3d2df81a57c98836661a97
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59abfb1a125beba2a9aff1676e0299625e6b352cb4b71005b6e4a2854cff3d19758578ce6a91addadbd64f8a7656449e3766da0b3edc5659dc6f49a3953ce733
|
|
7
|
+
data.tar.gz: 579309e1a64318f07275fc4139481021d94cd01fb816f36b42cd5b8f8a0eac273d6e690b920649cd8787eee59b555b371592fe308f16396b91c84c118b2925df
|
data/README.md
CHANGED
|
@@ -62,6 +62,65 @@ rescue => e
|
|
|
62
62
|
end
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
## Deploy tracking
|
|
66
|
+
|
|
67
|
+
Track deploys so BugWatch can correlate new errors with releases.
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
Bugwatch.track_deploy(
|
|
71
|
+
version: "abc1234",
|
|
72
|
+
environment: "production", # defaults to config.release_stage
|
|
73
|
+
description: "Deployed abc1234",
|
|
74
|
+
deployed_by: "ci"
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Heroku
|
|
79
|
+
|
|
80
|
+
On Heroku, `SOURCE_VERSION` (the git SHA) is available during the **build** phase but not during the **release** phase. The recommended approach is to bake the SHA into a `REVISION` file at build time, then read it at release time.
|
|
81
|
+
|
|
82
|
+
**1. Create a Rake task** in `lib/tasks/bugwatch.rake`:
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
namespace :bugwatch do
|
|
86
|
+
task write_revision: :environment do
|
|
87
|
+
revision = ENV["SOURCE_VERSION"] || `git rev-parse HEAD 2>/dev/null`.strip
|
|
88
|
+
if revision.present?
|
|
89
|
+
File.write(Rails.root.join("REVISION"), revision)
|
|
90
|
+
puts "Bugwatch: wrote REVISION #{revision[0..6]}"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
task track_deploy: :environment do
|
|
95
|
+
revision_file = Rails.root.join("REVISION")
|
|
96
|
+
version = ENV["SOURCE_VERSION"] \
|
|
97
|
+
|| (File.read(revision_file).strip if File.exist?(revision_file)).presence \
|
|
98
|
+
|| Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
99
|
+
|
|
100
|
+
thread = Bugwatch.track_deploy(
|
|
101
|
+
version: version,
|
|
102
|
+
description: "Deployed #{version[0..6]}",
|
|
103
|
+
deployed_by: ENV["BUGWATCH_DEPLOYED_BY"] || "heroku"
|
|
104
|
+
)
|
|
105
|
+
thread&.join(5)
|
|
106
|
+
puts "Bugwatch: tracked deploy #{version[0..6]}"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Bake the SHA into the slug during assets:precompile
|
|
111
|
+
if Rake::Task.task_defined?("assets:precompile")
|
|
112
|
+
Rake::Task["assets:precompile"].enhance(["bugwatch:write_revision"])
|
|
113
|
+
end
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**2. Add the deploy task to your `Procfile`** release phase:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
release: bundle exec rails db:migrate && bundle exec rails bugwatch:track_deploy
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The build will write the commit SHA to `REVISION`, and the release phase will read it back and report the deploy to BugWatch.
|
|
123
|
+
|
|
65
124
|
## How it works
|
|
66
125
|
|
|
67
126
|
1. `Bugwatch::Middleware` wraps your entire Rack stack.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Bugwatch
|
|
2
|
+
class ActiveJobHandler
|
|
3
|
+
def call(job, exception)
|
|
4
|
+
return if Bugwatch.configuration.ignore?(exception)
|
|
5
|
+
return unless Bugwatch.configuration.notify_for_release_stage?
|
|
6
|
+
|
|
7
|
+
payload = ErrorBuilder.new(exception).build
|
|
8
|
+
payload[:context] = {
|
|
9
|
+
job_class: job.class.name,
|
|
10
|
+
job_id: job.job_id,
|
|
11
|
+
queue_name: job.queue_name,
|
|
12
|
+
arguments: safe_arguments(job.arguments)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Notification.new(payload).deliver
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def safe_arguments(args)
|
|
21
|
+
args.map { |arg| arg.is_a?(GlobalID::Identification) ? arg.to_global_id.to_s : arg }
|
|
22
|
+
rescue StandardError
|
|
23
|
+
["[unserializable]"]
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Bugwatch
|
|
2
|
+
class ErrorSubscriber
|
|
3
|
+
def report(error, handled:, severity:, context: {}, source: nil)
|
|
4
|
+
return if Bugwatch.configuration.ignore?(error)
|
|
5
|
+
return unless Bugwatch.configuration.notify_for_release_stage?
|
|
6
|
+
|
|
7
|
+
payload = ErrorBuilder.new(error).build
|
|
8
|
+
payload[:context] = context.merge(
|
|
9
|
+
handled: handled,
|
|
10
|
+
severity: severity,
|
|
11
|
+
source: source
|
|
12
|
+
).compact
|
|
13
|
+
|
|
14
|
+
Notification.new(payload).deliver
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/bugwatch/railtie.rb
CHANGED
|
@@ -9,6 +9,21 @@ module Bugwatch
|
|
|
9
9
|
include Bugwatch::ControllerMethods
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
initializer "bugwatch.active_job" do
|
|
14
|
+
ActiveSupport.on_load(:active_job) do
|
|
15
|
+
rescue_from(Exception) do |exception|
|
|
16
|
+
Bugwatch::ActiveJobHandler.new.call(self, exception)
|
|
17
|
+
raise exception
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
initializer "bugwatch.error_subscriber" do
|
|
23
|
+
if defined?(Rails.error) && Rails.error.respond_to?(:subscribe)
|
|
24
|
+
Rails.error.subscribe(Bugwatch::ErrorSubscriber.new)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
12
27
|
end
|
|
13
28
|
|
|
14
29
|
module ControllerMethods
|
data/lib/bugwatch/version.rb
CHANGED
data/lib/bugwatch.rb
CHANGED
|
@@ -12,6 +12,8 @@ require_relative "bugwatch/notification"
|
|
|
12
12
|
require_relative "bugwatch/transaction_sender"
|
|
13
13
|
require_relative "bugwatch/transaction_buffer"
|
|
14
14
|
require_relative "bugwatch/middleware"
|
|
15
|
+
require_relative "bugwatch/active_job_handler"
|
|
16
|
+
require_relative "bugwatch/error_subscriber"
|
|
15
17
|
require_relative "bugwatch/railtie" if defined?(Rails::Railtie)
|
|
16
18
|
|
|
17
19
|
module Bugwatch
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bugwatch-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- BugWatch
|
|
@@ -48,10 +48,12 @@ files:
|
|
|
48
48
|
- README.md
|
|
49
49
|
- lib/bugwatch-ruby.rb
|
|
50
50
|
- lib/bugwatch.rb
|
|
51
|
+
- lib/bugwatch/active_job_handler.rb
|
|
51
52
|
- lib/bugwatch/backtrace_cleaner.rb
|
|
52
53
|
- lib/bugwatch/breadcrumb_collector.rb
|
|
53
54
|
- lib/bugwatch/configuration.rb
|
|
54
55
|
- lib/bugwatch/error_builder.rb
|
|
56
|
+
- lib/bugwatch/error_subscriber.rb
|
|
55
57
|
- lib/bugwatch/middleware.rb
|
|
56
58
|
- lib/bugwatch/notification.rb
|
|
57
59
|
- lib/bugwatch/railtie.rb
|