bitfab 0.78.5 → 0.78.6

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: e04206fd104ce3004142355495e4258b104fc2ffc09108c87705e0cf964c1723
4
- data.tar.gz: c1ee11bf687ab36b0ede9a3cf02dbeb5074922382506c4bbf64f539f66a4184c
3
+ metadata.gz: 30b30cced58b74dc213085883e05b7ada29717a73087b83d88a17c26035e5e73
4
+ data.tar.gz: d706e26a62d7bd1420d91e72fd5b1a36c7ec96ffd028cf75bcb46b00bb2c96b9
5
5
  SHA512:
6
- metadata.gz: ccbbcdc722cb9d7a37d59571f896d493e85a542301dbeb21e339a0632edd30fda987c1cde5551f0be6c67de04935129b1ce32b621c67e1117a05db7cff04e5d3
7
- data.tar.gz: 006606f3c5c749d82fe6aaa7df105cf90d301fd5eb428df94f02ed3d3ade2a36b57b579512168e4c5520df8dc3152e69d056b0d422896e3b22695c3f901794e8
6
+ metadata.gz: 71d3c0a29349ef82abdeee9873be2fce9a31986e139ed5bc798cdcfae79ea77c566a65df1a1ac1a450f4c2019ecb59646bf10c38d7a0e6a05dbe3150ba609354
7
+ data.tar.gz: 2cdfabb73708b2d9015cba62cc10c721c9ec940a367f96ade420d9e4b6240e7354ab0fd1b8794482ac1579bb3eea9269ec972f30b0b774f6404ab176d07bded4
data/lib/bitfab/client.rb CHANGED
@@ -51,7 +51,13 @@ module Bitfab
51
51
  @verdicts
52
52
  end
53
53
 
54
- def initialize(api_key: nil, service_url: nil, capture_enabled: nil, enabled: nil, strict: false, simulation_plan: true, timeout: 120, trace_across_threads: nil, env_vars: nil, baml_client: nil, db_snapshot: nil)
54
+ # @param include_packages [Array<String>, nil] gem names whose calls beneath
55
+ # every bitfab_trace root are recorded like first-party calls. A root's own
56
+ # include_packages adds to this list. Only the named gem's own code is
57
+ # recorded, not the gems it depends on. Naming the bitfab gem raises
58
+ # ArgumentError; a name with no loaded gem warns once and is ignored.
59
+ def initialize(api_key: nil, service_url: nil, capture_enabled: nil, enabled: nil, strict: false, simulation_plan: true, timeout: 120, trace_across_threads: nil, env_vars: nil, baml_client: nil, db_snapshot: nil, include_packages: nil)
60
+ @include_packages = Subtree.library_names(include_packages)
55
61
  @db_snapshot = DbSnapshot.normalize_config(db_snapshot)
56
62
  @env_vars = env_vars || ENV.to_h
57
63
  @baml_client = baml_client
@@ -810,6 +816,8 @@ module Bitfab
810
816
 
811
817
  private
812
818
 
819
+ attr_reader :include_packages
820
+
813
821
  def validate_trace_id(trace_id)
814
822
  raise ArgumentError, "trace_id must be a valid Bitfab trace ID" unless trace_id.is_a?(String) && UUID_PATTERN.match?(trace_id)
815
823
  end
@@ -1397,11 +1405,17 @@ module Bitfab
1397
1405
  # has recorded this much, its later calls beneath that root call are not
1398
1406
  # recorded, so a helper called in a loop with a large argument cannot fill
1399
1407
  # memory. Nodes declared with bitfab_node and LLM calls do not count toward it.
1408
+ # @param include_packages [Array<String>] gem names whose calls beneath this
1409
+ # root are recorded like first-party calls, in addition to the client's
1410
+ # include_packages. Only the named gem's own code is recorded, not the gems
1411
+ # it depends on. Limits and exclude apply to these calls too. Naming the
1412
+ # bitfab gem raises ArgumentError; a name with no loaded gem warns once and
1413
+ # is ignored.
1400
1414
  def trace(klass, method_name, name: nil, type: "custom",
1401
1415
  max_depth: Subtree::DEFAULT_MAX_DEPTH,
1402
1416
  max_captured_subtree_spans: Subtree::DEFAULT_MAX_CAPTURED_SUBTREE_SPANS,
1403
1417
  max_payload_bytes_per_function: Subtree::DEFAULT_MAX_PAYLOAD_BYTES_PER_FUNCTION,
1404
- exclude: [], include_wrappers: false, mock_on_replay_default: false)
1418
+ exclude: [], include_packages: [], include_wrappers: false, mock_on_replay_default: false)
1405
1419
  Bitfab::Traceable.trace(
1406
1420
  klass, method_name,
1407
1421
  trace_function_key: @trace_function_key,
@@ -1411,6 +1425,7 @@ module Bitfab
1411
1425
  max_captured_subtree_spans:,
1412
1426
  max_payload_bytes_per_function:,
1413
1427
  exclude:,
1428
+ include_packages:,
1414
1429
  include_wrappers:,
1415
1430
  mock_on_replay_default:,
1416
1431
  client: @client
@@ -20,7 +20,9 @@ module Bitfab
20
20
  REALPATH_MUTEX = Mutex.new
21
21
  SDK_PREFIX = "#{File.realpath(File.expand_path("..", __dir__))}#{File::SEPARATOR}".freeze
22
22
 
23
- CaptureConfig = Struct.new(:root, :root_path, :exclude)
23
+ BITFAB_GEM_NAMES = %w[bitfab].freeze
24
+
25
+ CaptureConfig = Struct.new(:root, :root_path, :exclude, :include_packages)
24
26
  FiberContext = Struct.new(:session, :fiber, :thread, :span_stack, :inherited_span, :parent)
25
27
 
26
28
  Boundary = Struct.new(
@@ -174,16 +176,52 @@ module Bitfab
174
176
  end
175
177
  end
176
178
 
177
- def prepare(root_source:, exclude:)
178
- path = root_source[0]
179
- root = first_party_root(path)
180
- CaptureConfig.new(
181
- root: root && with_separator(realpath(root)),
182
- root_path: path,
183
- exclude: exclude.to_h { |name| [name.to_s, true] }.freeze
184
- ).freeze
185
- rescue
186
- CaptureConfig.new(root: nil, root_path: nil, exclude: {}.freeze).freeze
179
+ def prepare(root_source:, exclude:, include_packages: [])
180
+ include_packages = library_names(include_packages)
181
+ begin
182
+ path = root_source[0]
183
+ root = first_party_root(path)
184
+ CaptureConfig.new(
185
+ root: root && with_separator(realpath(root)),
186
+ root_path: path,
187
+ exclude: exclude.to_h { |name| [name.to_s, true] }.freeze,
188
+ include_packages:
189
+ ).freeze
190
+ rescue
191
+ CaptureConfig.new(root: nil, root_path: nil, exclude: {}.freeze, include_packages:).freeze
192
+ end
193
+ end
194
+
195
+ def library_names(names)
196
+ list = Array(names).map { |name| name.to_s.strip }.reject(&:empty?).uniq
197
+ named_sdk = list.find { |name| BITFAB_GEM_NAMES.include?(name) }
198
+ if named_sdk
199
+ raise ArgumentError,
200
+ "include_packages cannot name '#{named_sdk}': the Bitfab SDK's own calls are never recorded."
201
+ end
202
+ list.freeze
203
+ end
204
+
205
+ def library_roots(names)
206
+ names.uniq.filter_map { |name| library_root(name) }.freeze
207
+ end
208
+
209
+ def library_root(name)
210
+ spec = defined?(Gem) && Gem.loaded_specs[name]
211
+ unless spec
212
+ Bitfab.warn_once("include-packages-missing:#{name}",
213
+ "include_packages names '#{name}', but no loaded gem has that name, so its calls are not recorded.")
214
+ return nil
215
+ end
216
+ if spec.respond_to?(:default_gem?) && spec.default_gem?
217
+ Bitfab.warn_once("include-packages-default-gem:#{name}",
218
+ "include_packages names '#{name}', which is part of the Ruby standard library, so its calls are not recorded.")
219
+ return nil
220
+ end
221
+ root = with_separator(realpath(spec.full_gem_path))
222
+ return nil if root.nil? || SDK_PREFIX.start_with?(root) || root.start_with?(SDK_PREFIX)
223
+
224
+ root
187
225
  end
188
226
 
189
227
  def capture(client:, trace_function_key:, config:, max_depth:, include_wrappers:,
@@ -210,7 +248,8 @@ module Bitfab
210
248
  include_wrappers:,
211
249
  mock_on_replay_default:,
212
250
  root_receiver:,
213
- root_method_name:
251
+ root_method_name:,
252
+ library_roots: library_roots(client_libraries(client) + Array(config.include_packages))
214
253
  )
215
254
  rescue Exception # rubocop:disable Lint/RescueException
216
255
  return yield
@@ -219,6 +258,12 @@ module Bitfab
219
258
  result.is_a?(Enumerator) ? session.wrap_enumerator(result) : result
220
259
  end
221
260
 
261
+ def client_libraries(client)
262
+ Array(client.send(:include_packages))
263
+ rescue NoMethodError
264
+ []
265
+ end
266
+
222
267
  def current_session
223
268
  Thread.current[SESSION_KEY] || fiber_context&.session
224
269
  end
@@ -432,8 +477,10 @@ module Bitfab
432
477
  def initialize(client:, trace_function_key:, trace_id:, root_span_id:, experiment_id:,
433
478
  input_source_span_id:, config:, max_depth:, include_wrappers:,
434
479
  root_receiver:, root_method_name:, max_captured_subtree_spans: DEFAULT_MAX_CAPTURED_SUBTREE_SPANS,
435
- max_payload_bytes_per_function: DEFAULT_MAX_PAYLOAD_BYTES_PER_FUNCTION, mock_on_replay_default: false)
480
+ max_payload_bytes_per_function: DEFAULT_MAX_PAYLOAD_BYTES_PER_FUNCTION, mock_on_replay_default: false,
481
+ library_roots: [])
436
482
  @mock_on_replay_default = mock_on_replay_default
483
+ @library_roots = library_roots
437
484
  @client = client
438
485
  @trace_function_key = trace_function_key
439
486
  @trace_id = trace_id
@@ -928,11 +975,8 @@ module Bitfab
928
975
  def owned_path(path)
929
976
  @owned_paths.fetch(path) do
930
977
  resolved = Subtree.realpath(path)
931
- # The selected application may itself be installed under Gem.path.
932
- # Its own boundary wins over ancestor exclusions, never the SDK's.
933
- @owned_paths[path] = if resolved&.start_with?(@root) &&
934
- !resolved.start_with?(SDK_PREFIX) &&
935
- !Subtree.library_prefixes.any? { |prefix| resolved.start_with?(prefix) && !@root.start_with?(prefix) }
978
+ @owned_paths[path] = if resolved && !resolved.start_with?(SDK_PREFIX) &&
979
+ (named_library_path?(resolved) || first_party_path?(resolved))
936
980
  resolved
937
981
  else
938
982
  false
@@ -940,6 +984,15 @@ module Bitfab
940
984
  end
941
985
  end
942
986
 
987
+ def named_library_path?(resolved)
988
+ @library_roots.any? { |root| resolved.start_with?(root) }
989
+ end
990
+
991
+ def first_party_path?(resolved)
992
+ resolved.start_with?(@root) &&
993
+ Subtree.library_prefixes.none? { |prefix| resolved.start_with?(prefix) && !@root.start_with?(prefix) }
994
+ end
995
+
943
996
  def current_stack(fiber_id)
944
997
  @stacks[fiber_id] ||= []
945
998
  end
@@ -88,12 +88,18 @@ module Bitfab
88
88
  # has recorded this much, its later calls beneath that root call are not
89
89
  # recorded, so a helper called in a loop with a large argument cannot fill
90
90
  # memory. Nodes declared with bitfab_node and LLM calls do not count toward it.
91
+ # @param include_packages [Array<String>] gem names whose calls beneath this
92
+ # root are recorded like first-party calls, in addition to the client's
93
+ # include_packages. Only the named gem's own code is recorded, not the gems
94
+ # it depends on. Limits and exclude apply to these calls too. Naming the
95
+ # bitfab gem raises ArgumentError; a name with no loaded gem warns once and
96
+ # is ignored.
91
97
  def self.trace(klass, method_name, trace_function_key:, name: nil, type: "custom",
92
98
  max_depth: Subtree::DEFAULT_MAX_DEPTH,
93
99
  max_captured_subtree_spans: Subtree::DEFAULT_MAX_CAPTURED_SUBTREE_SPANS,
94
100
  max_payload_bytes_per_function: Subtree::DEFAULT_MAX_PAYLOAD_BYTES_PER_FUNCTION,
95
- exclude: [], include_wrappers: false, mock_on_replay_default: false, client: nil)
96
- capture_config = Subtree.prepare(root_source: source_of(klass, method_name), exclude:)
101
+ exclude: [], include_packages: [], include_wrappers: false, mock_on_replay_default: false, client: nil)
102
+ capture_config = Subtree.prepare(root_source: source_of(klass, method_name), exclude:, include_packages:)
97
103
  method_name_str = method_name.to_s
98
104
  bound_client = client
99
105
  wrapper = Module.new do
@@ -363,11 +369,17 @@ module Bitfab
363
369
  # has recorded this much, its later calls beneath that root call are not
364
370
  # recorded, so a helper called in a loop with a large argument cannot fill
365
371
  # memory. Nodes declared with bitfab_node and LLM calls do not count toward it.
372
+ # @param include_packages [Array<String>] gem names whose calls beneath this
373
+ # root are recorded like first-party calls, in addition to the client's
374
+ # include_packages. Only the named gem's own code is recorded, not the gems
375
+ # it depends on. Limits and exclude apply to these calls too. Naming the
376
+ # bitfab gem raises ArgumentError; a name with no loaded gem warns once and
377
+ # is ignored.
366
378
  def bitfab_trace(method_name, trace_function_key: nil, name: nil, type: "custom",
367
379
  max_depth: Subtree::DEFAULT_MAX_DEPTH,
368
380
  max_captured_subtree_spans: Subtree::DEFAULT_MAX_CAPTURED_SUBTREE_SPANS,
369
381
  max_payload_bytes_per_function: Subtree::DEFAULT_MAX_PAYLOAD_BYTES_PER_FUNCTION,
370
- exclude: [], include_wrappers: false, mock_on_replay_default: false)
382
+ exclude: [], include_packages: [], include_wrappers: false, mock_on_replay_default: false)
371
383
  trace_function_key ||= @bitfab_function_key
372
384
  unless trace_function_key
373
385
  raise "No trace function key provided. Pass `trace_function_key:` to `bitfab_trace` " \
@@ -382,6 +394,7 @@ module Bitfab
382
394
  max_captured_subtree_spans:,
383
395
  max_payload_bytes_per_function:,
384
396
  exclude:,
397
+ include_packages: Subtree.library_names(include_packages),
385
398
  include_wrappers:,
386
399
  mock_on_replay_default:
387
400
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.78.5"
4
+ VERSION = "0.78.6"
5
5
  end
data/lib/bitfab.rb CHANGED
@@ -101,12 +101,14 @@ module Bitfab
101
101
  #
102
102
  # @param api_key [String] API key for authentication
103
103
  # @param service_url [String, nil] base URL (default: https://bitfab.ai)
104
+ # @param include_packages [Array<String>, nil] gem names whose calls beneath
105
+ # every bitfab_trace root are recorded like first-party calls
104
106
  #
105
107
  # @example
106
108
  # Bitfab.configure(api_key: ENV["BITFAB_API_KEY"])
107
109
  #
108
- def configure(api_key: nil, service_url: nil, capture_enabled: nil, enabled: nil, strict: false, simulation_plan: true, timeout: 120, trace_across_threads: nil, env_vars: nil, baml_client: nil, db_snapshot: nil)
109
- @client = Client.new(api_key:, service_url:, capture_enabled:, enabled:, strict:, simulation_plan:, timeout:, trace_across_threads:, env_vars:, baml_client:, db_snapshot:)
110
+ def configure(api_key: nil, service_url: nil, capture_enabled: nil, enabled: nil, strict: false, simulation_plan: true, timeout: 120, trace_across_threads: nil, env_vars: nil, baml_client: nil, db_snapshot: nil, include_packages: nil)
111
+ @client = Client.new(api_key:, service_url:, capture_enabled:, enabled:, strict:, simulation_plan:, timeout:, trace_across_threads:, env_vars:, baml_client:, db_snapshot:, include_packages:)
110
112
  end
111
113
 
112
114
  # Returns the global client, raising if not configured.
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.78.5
4
+ version: 0.78.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team