brainzlab 0.1.27 → 0.1.28

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: d9fdb52091b2fd8dc2da465cda4b4dc3f37f9b0bef3319f6b1bc6795a1a49c5d
4
+ data.tar.gz: 866b90f99c3f099618cb0cb981da3e75068824b89998adecad0edd5f89f9db68
5
5
  SHA512:
6
- metadata.gz: 190513dceb2037e41a274b6e930735c8d918b674effbed07cb8077321eb9ebf6ffac328acaa050d18d80f4e488db58ccf8b60ac96687eb650a98c055804ad9e5
7
- data.tar.gz: 6a51f042aedafa0e7995e6f17e2c17b2551fbd0415fb5b3b60d54980974e9c03f11b59ce3a696368042ac99faaa1387163122d7bcb4b01e9de0c7d7fc1cc02c2
6
+ metadata.gz: 3268bd499dfa2ae01e25bc18d57110ba45516d2a6971bca24158be6fd43d8c928ffb51f816946b7c3c084a8928d61c54b8507760deb78dec5a6f2288b5299db1
7
+ data.tar.gz: c7fd19b498c1d193f885ff0c0bddd86047006101195fe3a7f1a545ba3fa4e251691ce30ddf9589fbdd5b63dd5d98ab100527612b4c34e83c38d1fde8189b5211
@@ -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?
@@ -17,6 +17,7 @@ module BrainzLab
17
17
  end
18
18
 
19
19
  def start_trace(name, kind: 'custom', **attributes)
20
+ sample_rate = @config.effective_pulse_sample_rate
20
21
  trace = {
21
22
  trace_id: SecureRandom.uuid,
22
23
  name: name,
@@ -25,6 +26,10 @@ module BrainzLab
25
26
  environment: @config.environment,
26
27
  commit: @config.commit,
27
28
  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,
28
33
  **attributes
29
34
  }
30
35
 
@@ -38,6 +43,14 @@ module BrainzLab
38
43
  trace = current_trace
39
44
  return unless trace
40
45
 
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
54
  ended_at = Time.now.utc
42
55
  duration_ms = ((ended_at - trace[:started_at]) * 1000).round(2)
43
56
 
@@ -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.28'
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.28
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: []