brainzlab 0.1.28 → 0.1.31

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: d9fdb52091b2fd8dc2da465cda4b4dc3f37f9b0bef3319f6b1bc6795a1a49c5d
4
- data.tar.gz: 866b90f99c3f099618cb0cb981da3e75068824b89998adecad0edd5f89f9db68
3
+ metadata.gz: 5c7573fc851c73fe6b684611c10fb6799369c4817cc48b2fa7b18c6e84ac2188
4
+ data.tar.gz: 792060817bb43eafa993a0a34206d7fd53b30d94ebb861205b02775243f9292d
5
5
  SHA512:
6
- metadata.gz: 3268bd499dfa2ae01e25bc18d57110ba45516d2a6971bca24158be6fd43d8c928ffb51f816946b7c3c084a8928d61c54b8507760deb78dec5a6f2288b5299db1
7
- data.tar.gz: c7fd19b498c1d193f885ff0c0bddd86047006101195fe3a7f1a545ba3fa4e251691ce30ddf9589fbdd5b63dd5d98ab100527612b4c34e83c38d1fde8189b5211
6
+ metadata.gz: a16f37708f020bdfa8f3aaf3131ef7cbb572b086cea2ec1567eb56e2d810042ed90b2ff8f17c1d84401b50bbe1a66f1fb221b1ad8948c2df8d28b44aecf1f605
7
+ data.tar.gz: 3dd6909b4dc67fa7cb47767f6ca001e7df4547ebe5c1a99f08efe12f8d0285da58f62ef99f9ad9a9884b7526a12cd7a6018be45993b0dee131dda696fa37fb47
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.1.31] - 2026-06-18
6
+
7
+ ### Fixed
8
+
9
+ - **Health-check Engine no longer auto-draws routes at all.** Any `routes.draw` (class-body in ≤0.1.29, or an initializer in 0.1.30) triggers Devise's `RouteSet#finalize!` patch → `Devise.configure_warden!`. When that runs before Warden's middleware is configured, apps with `devise_scope` routes crash with `NoMethodError: undefined method 'failure_app=' for nil`. The engine's routes were unused (consumers use their own `/up` probe), so the auto-draw is removed entirely. The health logic remains available via `HealthCheck.run`; apps can expose HTTP endpoints from their own routes (see the comment in `health_check.rb`).
10
+
11
+ ## [0.1.30] - 2026-06-18
12
+
13
+ ### Fixed
14
+
15
+ - **Health-check Engine route draw deferred to an initializer** (superseded by 0.1.31 — deferring wasn't enough, since the initializer still ran before Warden middleware).
16
+
5
17
  ## [0.1.25] - 2026-06-07
6
18
 
7
19
  ### Added
@@ -20,6 +20,13 @@ module BrainzLab
20
20
  def send_trace(payload)
21
21
  return unless @config.pulse_enabled && @config.pulse_valid?
22
22
 
23
+ # Per-trace sampling — the single chokepoint every trace path funnels
24
+ # through (request middleware, jobs, sidekiq, delayed_job, grape, manual
25
+ # traces). Decided once per complete trace (spans travel inline in the
26
+ # payload, so they never orphan) and BEFORE buffering, so dropped traces
27
+ # never reach the buffer/batch. Error traces are always kept.
28
+ return unless keep_trace?(payload)
29
+
23
30
  if @config.pulse_buffer_size > 1
24
31
  buffer_trace(payload)
25
32
  else
@@ -61,6 +68,15 @@ module BrainzLab
61
68
 
62
69
  private
63
70
 
71
+ # Keep error traces always; otherwise keep with probability = the
72
+ # effective per-tier sample rate (internal=0.1, standard=0.5, client=1.0).
73
+ def keep_trace?(payload)
74
+ return true if payload[:error] == true || payload['error'] == true
75
+
76
+ rate = @config.effective_pulse_sample_rate
77
+ rate >= 1.0 || rand < rate
78
+ end
79
+
64
80
  def buffer_trace(payload)
65
81
  should_flush = false
66
82
 
@@ -17,7 +17,6 @@ module BrainzLab
17
17
  end
18
18
 
19
19
  def start_trace(name, kind: 'custom', **attributes)
20
- sample_rate = @config.effective_pulse_sample_rate
21
20
  trace = {
22
21
  trace_id: SecureRandom.uuid,
23
22
  name: name,
@@ -26,10 +25,6 @@ module BrainzLab
26
25
  environment: @config.environment,
27
26
  commit: @config.commit,
28
27
  host: @config.host,
29
- sample_rate: sample_rate,
30
- # Per-trace sampling decision (atomic, so spans never orphan). Errors
31
- # override this at finish_trace and are always kept.
32
- sampled: sample_rate >= 1.0 || rand < sample_rate,
33
28
  **attributes
34
29
  }
35
30
 
@@ -43,14 +38,8 @@ module BrainzLab
43
38
  trace = current_trace
44
39
  return unless trace
45
40
 
46
- # Drop unsampled successful traces entirely (skip payload build + send);
47
- # error traces are always kept regardless of the sampling decision.
48
- unless error || trace.fetch(:sampled, true)
49
- Thread.current[:brainzlab_pulse_trace] = nil
50
- Thread.current[:brainzlab_pulse_spans] = nil
51
- return
52
- end
53
-
41
+ # Sampling is applied at the single send chokepoint (Pulse::Client#send_trace),
42
+ # which every trace path funnels through so finish_trace just builds + sends.
54
43
  ended_at = Time.now.utc
55
44
  duration_ms = ((ended_at - trace[:started_at]) * 1000).round(2)
56
45
 
@@ -254,16 +254,26 @@ module BrainzLab
254
254
  end
255
255
  end
256
256
 
257
- # Rails Engine for mounting health endpoints
257
+ # Rails Engine for the health endpoints.
258
+ #
259
+ # Routes are intentionally NOT auto-drawn at boot. Any `routes.draw`
260
+ # triggers Devise's RouteSet#finalize! patch, which calls
261
+ # Devise.configure_warden!; if that runs before Warden's middleware is
262
+ # configured (e.g. while another engine draws routes during early boot),
263
+ # apps with `devise_scope` routes crash with
264
+ # `NoMethodError: undefined method 'failure_app=' for nil`.
265
+ #
266
+ # The health logic is available directly via `HealthCheck.run`. To expose
267
+ # HTTP endpoints, draw them in your app's own routes (loaded at the correct
268
+ # boot phase), e.g.:
269
+ # namespace :health, module: "brain_z_lab/utilities/health_check" do
270
+ # get "/", to: "health#show"
271
+ # get "/live", to: "health#live"
272
+ # get "/ready", to: "health#ready"
273
+ # end
258
274
  if defined?(::Rails::Engine)
259
275
  class Engine < ::Rails::Engine
260
276
  isolate_namespace BrainzLab::Utilities::HealthCheck
261
-
262
- routes.draw do
263
- get '/', to: 'health#show'
264
- get '/live', to: 'health#live'
265
- get '/ready', to: 'health#ready'
266
- end
267
277
  end
268
278
  end
269
279
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrainzLab
4
- VERSION = '0.1.28'
4
+ VERSION = '0.1.31'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brainzlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.28
4
+ version: 0.1.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - BrainzLab