dontbugme 0.1.0 → 0.1.2
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 +129 -18
- data/lib/dontbugme/railtie.rb +8 -12
- data/lib/dontbugme/recorder.rb +3 -3
- data/lib/dontbugme/version.rb +1 -1
- data/lib/dontbugme.rb +1 -1
- metadata +29 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f54f514d06627f29c5f89eecf392fd8c5df427acaa219a97ca70ca682274b2c0
|
|
4
|
+
data.tar.gz: 404c4e20b7f5c447bdc20d2460b2bdd2c788aba50e9b9069c3a5d0b62c4466a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 831ee2ea0ab588831a94adb96ed8970bdb05da393e30128c95d1f6daa2355331894edf22b0397a96630e6bada528625bd5fbcf3f86aa76fa76f0fd4af265f6ae
|
|
7
|
+
data.tar.gz: f7041c8ea3abb6e2ce3570f6d09e0812055354af6a8e0ece2ce7b089be381d0c7de6fe9618bf9f1ef43edb011fc9e713039c87339eb73034d29d17f54a88d250
|
data/README.md
CHANGED
|
@@ -2,6 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
A flight recorder for Rails applications. Reconstruct the full execution story of Sidekiq jobs and HTTP requests — see exactly what database queries ran, what HTTP services were called, what exceptions were raised, with source locations pointing to your code.
|
|
4
4
|
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
Get up and running in under 2 minutes:
|
|
8
|
+
|
|
9
|
+
**1. Add the gem and install**
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
# Gemfile
|
|
13
|
+
gem 'dontbugme'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bundle install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**2. Run the installer** (creates config and mounts the Web UI)
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
rails g dontbugme:install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
This adds `config/initializers/dontbugme.rb` and mounts the engine at `/inspector` in your routes.
|
|
27
|
+
|
|
28
|
+
**3. Start your app and generate traffic**
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
rails s # Start the server
|
|
32
|
+
# In another terminal, if you use Sidekiq:
|
|
33
|
+
bundle exec sidekiq
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Make an HTTP request (visit a page, hit an API) or run a Sidekiq job. Dontbugme records automatically in development.
|
|
37
|
+
|
|
38
|
+
**4. View traces**
|
|
39
|
+
|
|
40
|
+
**Option A — Web UI (easiest):** Open [http://localhost:3000/inspector](http://localhost:3000/inspector) in your browser. Browse, search, and compare traces.
|
|
41
|
+
|
|
42
|
+
**Option B — CLI:** From your Rails app root (so it finds the SQLite DB):
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
bundle exec dontbugme list # List recent traces
|
|
46
|
+
bundle exec dontbugme show <trace_id> # Show a trace
|
|
47
|
+
bundle exec dontbugme search --status=error # Find failed traces
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
That's it. No database migrations needed — SQLite is used by default in development (`tmp/inspector/inspector.db`).
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
5
54
|
## Installation
|
|
6
55
|
|
|
7
56
|
Add to your Gemfile:
|
|
@@ -14,6 +63,7 @@ Then run:
|
|
|
14
63
|
|
|
15
64
|
```bash
|
|
16
65
|
bundle install
|
|
66
|
+
rails g dontbugme:install
|
|
17
67
|
```
|
|
18
68
|
|
|
19
69
|
## Usage
|
|
@@ -113,29 +163,20 @@ bundle exec dontbugme trace tr_request_id --follow
|
|
|
113
163
|
|
|
114
164
|
Shows all traces (request + enqueued jobs) with the same correlation ID. Correlation IDs are automatically propagated from HTTP requests to Sidekiq jobs (and from job to child job) when using the Rails integration.
|
|
115
165
|
|
|
116
|
-
### Web UI
|
|
166
|
+
### Web UI
|
|
117
167
|
|
|
118
|
-
A lightweight web interface to browse traces. **
|
|
168
|
+
A lightweight web interface to browse traces. The installer mounts it at `/inspector`. It's **enabled by default in development** and **disabled in production**.
|
|
119
169
|
|
|
120
|
-
|
|
121
|
-
# config/initializers/dontbugme.rb
|
|
122
|
-
Dontbugme.configure do |config|
|
|
123
|
-
config.enable_web_ui = true # default: true in dev, false in prod
|
|
124
|
-
config.web_ui_mount_path = '/inspector'
|
|
125
|
-
end
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Add to `config/routes.rb`:
|
|
170
|
+
Visit `/inspector` to browse traces, search, and compare. Tweak in `config/initializers/dontbugme.rb`:
|
|
129
171
|
|
|
130
172
|
```ruby
|
|
131
|
-
|
|
173
|
+
config.enable_web_ui = true
|
|
174
|
+
config.web_ui_mount_path = '/inspector'
|
|
132
175
|
```
|
|
133
176
|
|
|
134
|
-
Then visit `/inspector` to browse traces, search, and compare.
|
|
135
|
-
|
|
136
177
|
### Configuration
|
|
137
178
|
|
|
138
|
-
|
|
179
|
+
Edit `config/initializers/dontbugme.rb` (created by the installer):
|
|
139
180
|
|
|
140
181
|
```ruby
|
|
141
182
|
Dontbugme.configure do |config|
|
|
@@ -153,15 +194,85 @@ end
|
|
|
153
194
|
- **PostgreSQL**: Uses your Rails DB. Set `config.store = :postgresql`
|
|
154
195
|
- **Memory**: For tests. Traces lost on process exit.
|
|
155
196
|
|
|
156
|
-
##
|
|
197
|
+
## Production
|
|
157
198
|
|
|
158
|
-
|
|
199
|
+
In production, Dontbugme uses safer defaults: PostgreSQL storage, async writes, selective recording, and the Web UI disabled. No extra setup is required if you use PostgreSQL — the gem creates the `dontbugme_traces` table automatically.
|
|
200
|
+
|
|
201
|
+
### Default production behavior
|
|
202
|
+
|
|
203
|
+
- **Store**: PostgreSQL (uses your Rails DB connection)
|
|
204
|
+
- **Web UI**: Disabled — enable only if you add authentication
|
|
205
|
+
- **Recording**: Selective — always records failures (`record_on_error`), samples successful traces
|
|
206
|
+
- **Async writes**: Enabled to avoid blocking requests/jobs
|
|
207
|
+
|
|
208
|
+
### Recommended configuration
|
|
159
209
|
|
|
160
210
|
```ruby
|
|
211
|
+
# config/initializers/dontbugme.rb
|
|
212
|
+
Dontbugme.configure do |config|
|
|
213
|
+
config.store = :postgresql
|
|
214
|
+
config.async_store = true
|
|
215
|
+
|
|
216
|
+
# Sample 5% of successful traces to limit storage
|
|
217
|
+
config.recording_mode = :selective
|
|
218
|
+
config.sample_rate = 0.05
|
|
219
|
+
config.record_on_error = true # Always capture failures
|
|
220
|
+
|
|
221
|
+
# Optional: record only specific jobs
|
|
222
|
+
# config.record_jobs = %w[SendInvoiceJob ProcessPaymentJob]
|
|
223
|
+
# config.record_requests = :all # or a proc for custom logic
|
|
224
|
+
end
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### Enabling the Web UI in production
|
|
228
|
+
|
|
229
|
+
If you need the Web UI in production (e.g. for on-call debugging), **protect it with authentication**:
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
# config/initializers/dontbugme.rb
|
|
233
|
+
Dontbugme.configure do |config|
|
|
234
|
+
config.enable_web_ui = true
|
|
235
|
+
config.web_ui_mount_path = '/inspector'
|
|
236
|
+
end
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Then add authentication in your routes (e.g. with Devise, `authenticate` before the mount, or HTTP basic auth via a constraint).
|
|
240
|
+
|
|
241
|
+
### Cleanup and retention
|
|
242
|
+
|
|
243
|
+
Production defaults to 24-hour retention. Schedule cleanup to enforce it:
|
|
244
|
+
|
|
245
|
+
```ruby
|
|
246
|
+
# config/schedule.rb (whenever) or a Sidekiq cron job
|
|
161
247
|
Dontbugme::CleanupJob.perform
|
|
162
248
|
```
|
|
163
249
|
|
|
164
|
-
|
|
250
|
+
Example with Sidekiq:
|
|
251
|
+
|
|
252
|
+
```ruby
|
|
253
|
+
# app/jobs/dontbugme_cleanup_job.rb
|
|
254
|
+
class DontbugmeCleanupJob < ApplicationJob
|
|
255
|
+
queue_as :low
|
|
256
|
+
|
|
257
|
+
def perform
|
|
258
|
+
Dontbugme::CleanupJob.perform
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
# Schedule daily via sidekiq-cron, whenever, or similar
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### CLI in production
|
|
265
|
+
|
|
266
|
+
Run the CLI from your production app directory (or a deploy host with DB access). It uses your Rails DB config:
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
RAILS_ENV=production bundle exec dontbugme list
|
|
270
|
+
RAILS_ENV=production bundle exec dontbugme search --status=error --limit=50
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Cleanup
|
|
274
|
+
|
|
275
|
+
Traces are ephemeral. Run `Dontbugme::CleanupJob.perform` to enforce retention. See [Production](#production) for scheduling via Sidekiq or cron.
|
|
165
276
|
|
|
166
277
|
## Requirements
|
|
167
278
|
|
data/lib/dontbugme/railtie.rb
CHANGED
|
@@ -8,12 +8,14 @@ module Dontbugme
|
|
|
8
8
|
config.dontbugme = ActiveSupport::OrderedOptions.new
|
|
9
9
|
|
|
10
10
|
initializer 'dontbugme.configure' do |app|
|
|
11
|
-
# Configuration defaults are applied in Configuration#initialize
|
|
12
|
-
# Merge any app-level config (e.g. config.dontbugme.store = :sqlite)
|
|
13
11
|
config = Dontbugme.config
|
|
14
12
|
app.config.dontbugme.each { |k, v| config.send("#{k}=", v) }
|
|
15
13
|
end
|
|
16
14
|
|
|
15
|
+
initializer 'dontbugme.middleware' do |app|
|
|
16
|
+
app.middleware.insert 0, Dontbugme::Middleware::Rack
|
|
17
|
+
end
|
|
18
|
+
|
|
17
19
|
initializer 'dontbugme.subscribers' do
|
|
18
20
|
Dontbugme::Subscribers::ActiveRecord.subscribe
|
|
19
21
|
Dontbugme::Subscribers::NetHttp.subscribe
|
|
@@ -24,24 +26,18 @@ module Dontbugme
|
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
config.after_initialize do
|
|
27
|
-
# Sidekiq middleware
|
|
28
29
|
if defined?(Sidekiq)
|
|
29
|
-
Sidekiq.configure_server do |
|
|
30
|
-
|
|
30
|
+
Sidekiq.configure_server do |cfg|
|
|
31
|
+
cfg.server_middleware do |chain|
|
|
31
32
|
chain.add Dontbugme::Middleware::Sidekiq
|
|
32
33
|
end
|
|
33
34
|
end
|
|
34
|
-
Sidekiq.configure_client do |
|
|
35
|
-
|
|
35
|
+
Sidekiq.configure_client do |cfg|
|
|
36
|
+
cfg.client_middleware do |chain|
|
|
36
37
|
chain.add Dontbugme::Middleware::SidekiqClient
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
|
-
|
|
41
|
-
# Rack middleware
|
|
42
|
-
if defined?(Rails::Application)
|
|
43
|
-
Rails.application.config.middleware.insert 0, Dontbugme::Middleware::Rack
|
|
44
|
-
end
|
|
45
41
|
end
|
|
46
42
|
end
|
|
47
43
|
end
|
data/lib/dontbugme/recorder.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Dontbugme
|
|
4
4
|
class Recorder
|
|
5
5
|
class << self
|
|
6
|
-
def record(kind:, identifier:, metadata: {}, &block)
|
|
6
|
+
def record(kind:, identifier:, metadata: {}, return_trace: false, &block)
|
|
7
7
|
return yield unless Dontbugme.config.recording?
|
|
8
8
|
return yield unless should_sample?
|
|
9
9
|
|
|
@@ -14,10 +14,10 @@ module Dontbugme
|
|
|
14
14
|
trace = Trace.new(kind: kind, identifier: identifier, metadata: metadata)
|
|
15
15
|
Context.current = trace
|
|
16
16
|
|
|
17
|
-
yield
|
|
17
|
+
result = yield
|
|
18
18
|
trace.finish!
|
|
19
19
|
persist(trace)
|
|
20
|
-
trace
|
|
20
|
+
return_trace ? trace : result
|
|
21
21
|
rescue StandardError => e
|
|
22
22
|
trace&.finish!(error: e)
|
|
23
23
|
persist(trace) if trace && Dontbugme.config.record_on_error
|
data/lib/dontbugme/version.rb
CHANGED
data/lib/dontbugme.rb
CHANGED
|
@@ -21,7 +21,7 @@ module Dontbugme
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def trace(identifier, metadata: {}, &block)
|
|
24
|
-
Recorder.record(kind: :custom, identifier: identifier, metadata: metadata, &block)
|
|
24
|
+
Recorder.record(kind: :custom, identifier: identifier, metadata: metadata, return_trace: true, &block)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def span(name, payload: {}, &block)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dontbugme
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Inspector Contributors
|
|
@@ -52,6 +52,34 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '2.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rack
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '2.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '2.0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rack-test
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.0'
|
|
55
83
|
- !ruby/object:Gem::Dependency
|
|
56
84
|
name: rake
|
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|