brainzlab 0.1.27 → 0.1.29

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: 6b57a1a89ace36a6d6529526de7fbe3830959bd18d874052689a02baf21d2aae
4
- data.tar.gz: cc0b0e99695dbd64ff561206df0e6e45ac619f666a04424e6b99633577c77e13
3
+ metadata.gz: 66b1827b6976d4cc3f0b16536eda54ac36ebc3fdba1f49369d93089198a99d73
4
+ data.tar.gz: 6a5d234eb169b6401ff226fe0944006fc3fea60df64a574aeb86f98466fd7c7d
5
5
  SHA512:
6
- metadata.gz: 190513dceb2037e41a274b6e930735c8d918b674effbed07cb8077321eb9ebf6ffac328acaa050d18d80f4e488db58ccf8b60ac96687eb650a98c055804ad9e5
7
- data.tar.gz: 6a51f042aedafa0e7995e6f17e2c17b2551fbd0415fb5b3b60d54980974e9c03f11b59ce3a696368042ac99faaa1387163122d7bcb4b01e9de0c7d7fc1cc02c2
6
+ metadata.gz: 2e958e58fdf83b5b472e3353a3f14b5b8d8a39315942eb74668735a2faefef9413d561b06b511bfff63fe2f633e8261320d3a8a7a25cf269ff0454283bfe6e36
7
+ data.tar.gz: 7601dbd331048b5fc8dd184c218ce9605ef010efd47d5b51fbeee52506f692bd4bad768219a4b8ad95562e9e28a006696886643c492fae303008ae8ca8c2795f
@@ -42,6 +42,7 @@ module BrainzLab
42
42
  :pulse_buffer_size,
43
43
  :pulse_flush_interval,
44
44
  :pulse_sample_rate,
45
+ :pulse_sample_tier,
45
46
  :pulse_excluded_paths,
46
47
  :flux_enabled,
47
48
  :flux_url,
@@ -254,7 +255,12 @@ module BrainzLab
254
255
  @pulse_auto_provision = true
255
256
  @pulse_buffer_size = 50
256
257
  @pulse_flush_interval = 5
257
- @pulse_sample_rate = nil
258
+ # Trace sampling. Explicit rate (0.0–1.0) wins; otherwise derived from the
259
+ # tier. Defaults to the "internal" tier so the Brainz fleet samples ~10%
260
+ # (error traces are always kept). Client-facing apps set
261
+ # BRAINZLAB_PULSE_TIER=client (or PULSE_SAMPLE_RATE) to keep everything.
262
+ @pulse_sample_rate = (v = ENV['PULSE_SAMPLE_RATE'] || ENV['BRAINZLAB_PULSE_SAMPLE_RATE']).nil? || v.to_s.strip.empty? ? nil : v.to_f
263
+ @pulse_sample_tier = (ENV['BRAINZLAB_PULSE_TIER'] || 'internal').to_s.strip.downcase
258
264
  @pulse_excluded_paths = %w[/health /ping /up /assets]
259
265
 
260
266
  # Flux settings
@@ -509,6 +515,23 @@ module BrainzLab
509
515
  pulse_api_key || secret_key
510
516
  end
511
517
 
518
+ # Per-tier default trace sample rates. Internal (the Brainz fleet's own
519
+ # telemetry) samples aggressively; client/critical keep everything. Error
520
+ # traces are always kept regardless (see Pulse::Tracer).
521
+ PULSE_TIER_SAMPLE_RATES = {
522
+ 'internal' => 0.1,
523
+ 'standard' => 0.5,
524
+ 'client' => 1.0,
525
+ 'critical' => 1.0
526
+ }.freeze
527
+
528
+ # Effective 0.0–1.0 trace sample rate: explicit rate wins, else the tier's
529
+ # default, else 1.0 (sample everything) for unknown tiers.
530
+ def effective_pulse_sample_rate
531
+ rate = pulse_sample_rate || PULSE_TIER_SAMPLE_RATES.fetch(pulse_sample_tier, 1.0)
532
+ rate.to_f.clamp(0.0, 1.0)
533
+ end
534
+
512
535
  def flux_valid?
513
536
  key = flux_ingest_key || flux_api_key || secret_key
514
537
  !key.nil? && !key.empty?
@@ -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
 
@@ -38,6 +38,8 @@ module BrainzLab
38
38
  trace = current_trace
39
39
  return unless trace
40
40
 
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.
41
43
  ended_at = Time.now.utc
42
44
  duration_ms = ((ended_at - trace[:started_at]) * 1000).round(2)
43
45
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BrainzLab
4
- VERSION = '0.1.27'
4
+ VERSION = '0.1.29'
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.27
4
+ version: 0.1.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - BrainzLab
@@ -246,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  - !ruby/object:Gem::Version
247
247
  version: '0'
248
248
  requirements: []
249
- rubygems_version: 4.0.3
249
+ rubygems_version: 3.6.9
250
250
  specification_version: 4
251
251
  summary: Ruby SDK for BrainzLab observability
252
252
  test_files: []