bitfab 0.51.7 → 0.51.9

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: 64f734e03ef657b17437062d8827ba0ab1532cb244f0c2bc7ae46e1f599015a0
4
- data.tar.gz: bef9e05e622daada74cf66907f6fe6f9cc3ecac4447af7b6590936c4dc85ba39
3
+ metadata.gz: f468d991f207bab17dbf93e1d8336e293aa2d759a83a31a8eee7631f1e93daa8
4
+ data.tar.gz: 4ab69ab42011952d9611a3708ed9f4308760aeb839eaa109ba413a798d5c59d4
5
5
  SHA512:
6
- metadata.gz: 979725c68118f1bd070da152c1d4ec607957dc771d3c39d021c68b2bc5f06d1315c49d33c13eae1ce99a1f16e6e0f7b2486dd3051286d3d8016bb552c3f0d14c
7
- data.tar.gz: 2a71770f9f72528093ed229bd2505dcc7a515fc5ffa9c682933fb5802e65ffa7cc46de7538f077e896f8ad01ea13820253fe781ed2b92477ad8ab8c9cadabeeb
6
+ metadata.gz: fcd27044d500aa10fb278940b3665cd54e27c2732e011e828bdd778dc598807960ae84686968957d48fd279f26dc93e2ff72cc1c8ccfa8a91824235548f0b394
7
+ data.tar.gz: 5c3c831e7c6e30e5ea9f8aaa2a5d63f55f561c831e57caa87504a86b7d73cfc62a98260c943f4024b664c9d6a419bb0b2727e83952dc10f0f62ba4bdb3b496ad
data/README.md CHANGED
@@ -72,7 +72,7 @@ Bitfab.configure(
72
72
 
73
73
  ### Disabling Span Sending
74
74
 
75
- The `enabled` option controls whether spans are sent to Bitfab. When disabled, your code executes normally but no spans are created or sent.
75
+ The `enabled` option controls whether spans are sent to Bitfab. When disabled, your code executes normally but no spans are created or sent. Leave it out and `BITFAB_CAPTURE_ENABLED` decides: `1`, `true`, or `yes` sends spans, `0`, `false`, or `no` stops them, and sending stays on when the variable is unset.
76
76
 
77
77
  ```ruby
78
78
  # Disable tracing (useful for development/test environments)
@@ -91,10 +91,10 @@ Bitfab.configure(
91
91
  enabled: Rails.env.production?
92
92
  )
93
93
 
94
- # Environment variable control
94
+ # Environment variable control: leave enabled: out and set BITFAB_CAPTURE_ENABLED
95
+ # to 0 or 1 in the environment. Anything passed here wins over it.
95
96
  Bitfab.configure(
96
- api_key: ENV.fetch('BITFAB_API_KEY', 'dummy-key'),
97
- enabled: ENV.fetch('BITFAB_ENABLED', 'false') == 'true'
97
+ api_key: ENV.fetch('BITFAB_API_KEY', 'dummy-key')
98
98
  )
99
99
 
100
100
  # Multi-environment control
data/lib/bitfab/client.rb CHANGED
@@ -4,6 +4,7 @@ require "securerandom"
4
4
  require "time"
5
5
 
6
6
  require_relative "constants"
7
+ require_relative "env"
7
8
  require_relative "http_client"
8
9
  require_relative "replay"
9
10
  require_relative "span_context"
@@ -37,11 +38,12 @@ module Bitfab
37
38
  # Trace lookup operations for the authenticated organization.
38
39
  attr_reader :traces
39
40
 
40
- def initialize(api_key: nil, service_url: nil, enabled: true, strict: false)
41
+ def initialize(api_key: nil, service_url: nil, enabled: nil, strict: false)
41
42
  @api_key_config = api_key
42
43
  @service_url = service_url || DEFAULT_SERVICE_URL
43
44
  # The user's on/off intent; effective enabled also requires a resolved key.
44
- @explicitly_enabled = enabled
45
+ @enabled_in_code = enabled
46
+ @capture_configured_from_env = nil
45
47
  @strict = strict
46
48
  # Cached only once a non-empty key is found, so an early resolve (before
47
49
  # env loaded) can't poison a later one.
@@ -654,17 +656,25 @@ module Bitfab
654
656
  "Bitfab.configure. If a script loads env later, load it before the first " \
655
657
  "traced call, or pass api_key: -> { ENV[\"BITFAB_API_KEY\"] }."
656
658
  end
657
- if @explicitly_enabled && !@api_key_warned
659
+ if capture_configured? && !@api_key_warned
658
660
  @api_key_warned = true
659
661
  warn("Bitfab: api_key is empty: tracing is disabled. Provide a valid API key to enable tracing.")
660
662
  end
661
663
  nil
662
664
  end
663
665
 
666
+ def capture_configured?
667
+ return @enabled_in_code unless @enabled_in_code.nil?
668
+ return @capture_configured_from_env unless @capture_configured_from_env.nil?
669
+
670
+ from_env = Bitfab.read_boolean_env(CAPTURE_ENABLED_ENV)
671
+ @capture_configured_from_env = from_env.nil? || from_env
672
+ end
673
+
664
674
  # Whether tracing should run, decided lazily at call time. An explicit
665
675
  # `enabled: false` short-circuits without ever touching the key.
666
676
  def tracing_enabled?
667
- return false unless @explicitly_enabled
677
+ return false unless capture_configured?
668
678
 
669
679
  !resolve_api_key.nil?
670
680
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Bitfab
4
4
  DEFAULT_SERVICE_URL = "https://bitfab.ai"
5
+ CAPTURE_ENABLED_ENV = "BITFAB_CAPTURE_ENABLED"
5
6
  REPLAY_CONTEXT_KEY = :__bitfab_replay_context
6
7
 
7
8
  # Wire prefix the Bitfab plugin scans for on stderr to report live progress
data/lib/bitfab/env.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "warn_once"
4
+
5
+ module Bitfab
6
+ TRUE_ENV_VALUES = %w[1 true yes].freeze
7
+ FALSE_ENV_VALUES = %w[0 false no].freeze
8
+ private_constant :TRUE_ENV_VALUES, :FALSE_ENV_VALUES
9
+
10
+ class << self
11
+ def read_boolean_env(name)
12
+ raw = ENV[name]
13
+ return nil if raw.nil?
14
+
15
+ value = raw.strip.downcase
16
+ return nil if value.empty?
17
+ return true if TRUE_ENV_VALUES.include?(value)
18
+ return false if FALSE_ENV_VALUES.include?(value)
19
+
20
+ warn_once(
21
+ "unrecognized-boolean-env:#{name}",
22
+ "#{name}=\"#{raw}\" is not 0 or 1; ignoring it."
23
+ )
24
+ nil
25
+ end
26
+ end
27
+ end
data/lib/bitfab/traces.rb CHANGED
@@ -7,10 +7,11 @@ module Bitfab
7
7
  @http_client = http_client
8
8
  end
9
9
 
10
- # Search by up to 10 exact, case-insensitive caller metadata pairs. Every
11
- # pair must match. Pass nextCursor from the result as cursor: for another page.
12
- def search(caller_metadata:, trace_function_key: nil, cursor: nil, limit: nil)
13
- payload = {"callerMetadata" => caller_metadata}
10
+ def search(caller_metadata: nil, name: nil, name_contains: nil, trace_function_key: nil, cursor: nil, limit: nil)
11
+ payload = {}
12
+ payload["callerMetadata"] = caller_metadata unless caller_metadata.nil?
13
+ payload["name"] = name unless name.nil?
14
+ payload["nameContains"] = name_contains unless name_contains.nil?
14
15
  payload["traceFunctionKey"] = trace_function_key unless trace_function_key.nil?
15
16
  payload["cursor"] = cursor unless cursor.nil?
16
17
  payload["limit"] = limit unless limit.nil?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.51.7"
4
+ VERSION = "0.51.9"
5
5
  end
data/lib/bitfab.rb CHANGED
@@ -79,7 +79,7 @@ module Bitfab
79
79
  # @example
80
80
  # Bitfab.configure(api_key: ENV["BITFAB_API_KEY"])
81
81
  #
82
- def configure(api_key: nil, service_url: nil, enabled: true, strict: false)
82
+ def configure(api_key: nil, service_url: nil, enabled: nil, strict: false)
83
83
  @client = Client.new(api_key:, service_url:, enabled:, strict:)
84
84
  end
85
85
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitfab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.7
4
+ version: 0.51.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team
@@ -145,6 +145,7 @@ files:
145
145
  - lib/bitfab/constants.rb
146
146
  - lib/bitfab/datasets.rb
147
147
  - lib/bitfab/db_snapshot.rb
148
+ - lib/bitfab/env.rb
148
149
  - lib/bitfab/git_command.rb
149
150
  - lib/bitfab/git_state.rb
150
151
  - lib/bitfab/http_client.rb