bugwatch-ruby 0.6.0 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4cb56c42da0cab5b2e855deca671231a744b1624b5fcbd6dbef365f30bc9d08
4
- data.tar.gz: 92889ce7b6cec458ee2c75c15759756acbaa32981051704c9a3534a42e58fe1d
3
+ metadata.gz: 6d6a47f1c5176ec17f87160b5ab4a273e6ef68e76dee98f6e60ee5da474a61fd
4
+ data.tar.gz: 713ab0b06839f57c473a98c8f3e1cd46f2f43b2c9ccfef2b18d7ba0e3abb1076
5
5
  SHA512:
6
- metadata.gz: 479c753810d0c158b339281f7f7c5c083134bfe4321cfe7739a28d24d14fc3c82fb26e17330de1bc92f13e41e66e2726c4fe0b42b2d5110301c3410e566fc564
7
- data.tar.gz: 6b2a55bf2cdd3a01fd82bd96a51c75f50fbbc48a373b8102c7c6a301ab748c75f7434084402d56cbf3b2009a838648205fa95c4706eb07655a423ef290f35d49
6
+ metadata.gz: cb255c2fcfe9562b06320de183bc1ee141f394eacb327eb6ad71739a662aaeb435f5da3248404a7074b45e6a397612d86fe8d243918284196cb7e3892c193f8a
7
+ data.tar.gz: 9ce11bcc466b319298cb788f51cdb1c89f00f6b3126189d02c9a7838eeb6f087291bb0864bc5115734849a1af966f2995385a627a057befbf815c63354e122ee
data/README.md CHANGED
@@ -181,6 +181,55 @@ Bugwatch.send_feedback(
181
181
  )
182
182
  ```
183
183
 
184
+ ## Database query tracking
185
+
186
+ The gem automatically subscribes to `sql.active_record` notifications and reports query performance data to your BugWatch instance. DB tracking is **enabled by default** — no extra setup required.
187
+
188
+ ### Configuration
189
+
190
+ ```ruby
191
+ # config/initializers/bugwatch.rb
192
+ Bugwatch.configure do |c|
193
+ # ... existing config ...
194
+
195
+ c.enable_db_tracking = true # default: true — set false to disable
196
+ c.db_sample_rate = 1.0 # 0.0–1.0 — fraction of requests to track (default: 1.0)
197
+ c.db_query_threshold_ms = 0 # only collect queries slower than this (default: 0 = all)
198
+ c.max_queries_per_request = 200 # cap per request to limit overhead (default: 200)
199
+ end
200
+ ```
201
+
202
+ | Option | Default | Description |
203
+ |--------|---------|-------------|
204
+ | `enable_db_tracking` | `true` | Master switch for DB tracking |
205
+ | `db_sample_rate` | `1.0` | Fraction of requests whose queries are collected (0.0–1.0) |
206
+ | `db_query_threshold_ms` | `0` | Minimum query duration (ms) to collect — set higher to focus on slow queries |
207
+ | `max_queries_per_request` | `200` | Maximum queries stored per request |
208
+
209
+ Schema operations and transaction bookkeeping (`BEGIN`, `COMMIT`, `ROLLBACK`) are automatically excluded. SQL literals are sanitized before sending, so no user data leaves your app.
210
+
211
+ ### Skipping tracking
212
+
213
+ Wrap any code block with `Bugwatch.without_tracking` to suppress all performance tracking (DB queries and transaction recording) for queries executed inside it. This is useful when BugWatch monitors itself, or for any internal bookkeeping queries you don't want tracked.
214
+
215
+ ```ruby
216
+ Bugwatch.without_tracking do
217
+ SomeModel.insert_all(records) # not tracked
218
+ end
219
+ ```
220
+
221
+ In a controller:
222
+
223
+ ```ruby
224
+ around_action :skip_tracking
225
+
226
+ private
227
+
228
+ def skip_tracking(&block)
229
+ Bugwatch.without_tracking(&block)
230
+ end
231
+ ```
232
+
184
233
  ## How it works
185
234
 
186
235
  1. `Bugwatch::Middleware` wraps your entire Rack stack.
@@ -36,6 +36,8 @@ module Bugwatch
36
36
  end
37
37
 
38
38
  def handle_event(event)
39
+ return if Bugwatch.skip_tracking?
40
+
39
41
  state = Thread.current[THREAD_KEY]
40
42
  return unless state
41
43
 
@@ -5,6 +5,8 @@ module Bugwatch
5
5
  end
6
6
 
7
7
  def call(env)
8
+ return @app.call(env) if Bugwatch.skip_tracking?
9
+
8
10
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
9
11
  BreadcrumbCollector.clear
10
12
  UserContext.clear
@@ -1,3 +1,3 @@
1
1
  module Bugwatch
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/bugwatch.rb CHANGED
@@ -120,6 +120,17 @@ module Bugwatch
120
120
  end
121
121
  end
122
122
 
123
+ def without_tracking
124
+ Thread.current[:bugwatch_skip_tracking] = true
125
+ yield
126
+ ensure
127
+ Thread.current[:bugwatch_skip_tracking] = false
128
+ end
129
+
130
+ def skip_tracking?
131
+ Thread.current[:bugwatch_skip_tracking] == true
132
+ end
133
+
123
134
  def transaction_buffer
124
135
  @transaction_buffer ||= TransactionBuffer.new(config: configuration)
125
136
  end
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.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BugWatch