wat_catcher 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +156 -1
- data/lib/wat_catcher/report.rb +1 -0
- data/lib/wat_catcher/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aa334c6634706d075857044218ed559877c0dc6
|
4
|
+
data.tar.gz: 9f7a7c8af3e7c3a34a4cc490b7e6907253f56b1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7fced4c2bc850dee9bb309be2f0bd82a4add929e1f6a958df1c1eda1ffd2a0c979ef79e8baa2db6c75fa40da6769dd01e13c37fc6a47f96c8ad39b346cbb08c
|
7
|
+
data.tar.gz: e7e5ad54fc6e647d53dd7e608857d858693ae85ec3fcee80129ac602efbbf0475cef2e10cbc194e6e50123929671fdafc54688658ddae102da9c9566e578f5ae
|
data/README.md
CHANGED
@@ -18,7 +18,162 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
### Configuration
|
22
|
+
You can configure the wat_catcher in 2 ways; 1) via a config/wat_catcher.yml file or in ruby.
|
23
|
+
|
24
|
+
Currently there are only 2 configuration options:
|
25
|
+
host: This is the beginning of the url used to post wats to wattle. It should look something like "https://yourwattleserver.com".
|
26
|
+
disabled: If truthy this will stop any wats from being posted.
|
27
|
+
|
28
|
+
Here are 2 identical configs specified in the yml and in ruby.
|
29
|
+
|
30
|
+
config/wat_catcher.yml
|
31
|
+
```yml
|
32
|
+
production: &default
|
33
|
+
host: "https://wattle.yourhost.com"
|
34
|
+
|
35
|
+
development:
|
36
|
+
<<: *default
|
37
|
+
disabled: true
|
38
|
+
|
39
|
+
test:
|
40
|
+
<<: *default
|
41
|
+
disabled: true
|
42
|
+
```
|
43
|
+
|
44
|
+
OR
|
45
|
+
|
46
|
+
config/application.rb
|
47
|
+
```ruby
|
48
|
+
module YourApp
|
49
|
+
class Application < Rails::Application
|
50
|
+
WatCatcher.configuration.host = "https://wattle.yourhost.com"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
config/environments/development.rb
|
56
|
+
```ruby
|
57
|
+
YourApp::Application.configure do
|
58
|
+
WatCatcher.configuration.disabled = true
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
config/environments/test.rb
|
63
|
+
```ruby
|
64
|
+
YourApp::Application.configure do
|
65
|
+
WatCatcher.configuration.disabled = true
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
### Mount the engine in your app for javascript errors
|
71
|
+
To get around cross-origin issues, an engine was created that accepts POSTs of client exceptions and puts a sidekiq
|
72
|
+
job in to post the wat to wattle.
|
73
|
+
|
74
|
+
In your routes.rb:
|
75
|
+
```ruby
|
76
|
+
YourApp::Application.routes.draw do
|
77
|
+
mount WatCatcher::Engine => '/wat_catcher'
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
### Integrating with a controller
|
82
|
+
|
83
|
+
Posting errors from a controller action is done by simply including the CatcherOfWats concern into your controller
|
84
|
+
```ruby
|
85
|
+
class ApplicationController < ActionController::Base
|
86
|
+
include WatCatcher::CatcherOfWats
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
That will install an around_filter that reports and re-raises anything raised in an action.
|
91
|
+
|
92
|
+
If you want to record some info about what user saw the error simply implement a 'wat_user' method on the controller
|
93
|
+
```ruby
|
94
|
+
class ApplicationController < ActionController::Base
|
95
|
+
|
96
|
+
def wat_user
|
97
|
+
{id: logged_in? ? "account_#{current_user.id}" : nil }
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
The wat_user will be turned into a json object. You may put any field in the wat_user, but the 'id' field will be used
|
104
|
+
by wattle to decide how many unique users have seen an exception.
|
105
|
+
|
106
|
+
### Integrating with sidekiq
|
107
|
+
|
108
|
+
To have sidekiq post exceptions from sidekiq jobs you must install the sidekiq middleware:
|
109
|
+
```ruby
|
110
|
+
::Sidekiq.configure_server do |config|
|
111
|
+
config.server_middleware do |chain|
|
112
|
+
chain.add ::WatCatcher::SidekiqMiddleware
|
113
|
+
end
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
117
|
+
If you want to some info about what user saw the error you need to implement a 'wat_user' method on the worker. The user
|
118
|
+
object returned by this wat_user follows the same rules as the wat_user on a controller, but the way it's called is
|
119
|
+
more complicated.
|
120
|
+
|
121
|
+
Whatever method is being called by sidekiq to start the job, make sure it implements a wat_user method that accepts
|
122
|
+
the same arguments.
|
123
|
+
|
124
|
+
Here are some ways that a wat_user method could be implemented:
|
125
|
+
```ruby
|
126
|
+
class SomeModel < ActiveRecord::Base
|
127
|
+
belongs_to :account
|
128
|
+
class << self
|
129
|
+
def notify(some_model_id)
|
130
|
+
SomeModel.find(some_model_id).some_delayed_method
|
131
|
+
end
|
132
|
+
|
133
|
+
def wat_user(some_model_id)
|
134
|
+
{ id: "some_model_#{some_model_id}" }
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
def wat_user(*args)
|
140
|
+
{ id: "some_model_#{id}" }
|
141
|
+
end
|
142
|
+
|
143
|
+
def some_delayed_method
|
144
|
+
raise 'herp'
|
145
|
+
end
|
146
|
+
|
147
|
+
def some_other_delayed_method(an_arg)
|
148
|
+
raise 'derp'
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
# Queuing on SomeModel like the following should generate a wat_user with a reasonable id.
|
154
|
+
SomeModel.last.delay.some_delayed_method
|
155
|
+
SomeModel.last.delay.some_other_delayed_method('blarg')
|
156
|
+
SomeModel.delay.notify(12)
|
157
|
+
|
158
|
+
|
159
|
+
class SomeWorker
|
160
|
+
include Sidekiq::Worker
|
161
|
+
|
162
|
+
def perform(some_arg)
|
163
|
+
raise "wat? #{some_arg}"
|
164
|
+
end
|
165
|
+
|
166
|
+
def wat_user(some_arg)
|
167
|
+
{ id: "SomeWorker: #{some_arg}" }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# The queued job will raise an error and register a wat with the user "SomeWorker: derp"
|
172
|
+
SomeWorker.perform_async("derp")
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
When in doubt, check out the cconstantine/wattle. It uses itself to report errors and uses all of the above features.
|
22
177
|
|
23
178
|
## Contributing
|
24
179
|
|
data/lib/wat_catcher/report.rb
CHANGED
data/lib/wat_catcher/version.rb
CHANGED