bitfab 0.76.0 → 0.76.2
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 +4 -4
- data/lib/bitfab/client.rb +13 -3
- data/lib/bitfab/experiments.rb +6 -3
- data/lib/bitfab/http_client.rb +4 -1
- data/lib/bitfab/replay.rb +7 -1
- data/lib/bitfab/replay_registry.rb +5 -2
- data/lib/bitfab/span_context.rb +17 -0
- data/lib/bitfab/spans.rb +28 -1
- data/lib/bitfab/subtree.rb +4 -1
- data/lib/bitfab/version.rb +1 -1
- data/lib/bitfab.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c5942fdb14d1fbffd77e851fdef0ca8352b3815b236ce984733732ddefae688f
|
|
4
|
+
data.tar.gz: b94626cada8efc2b017c471f0b9ebd977c6f42d0c70fe83945547ee0d826f7eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 133fb765afdd0a9441e4e894019e96992ec2dff1dbbb84ca6e8b07e7750612f27c6f9dc0851ba0eb31502d989b3d5778e4839cc55d14ab3b11042aa9c70c837d
|
|
7
|
+
data.tar.gz: 3dd647921a6fa3799f4a3574476776e4b7a9743028d1adca7ae55530050950b7267fd5f569679ef67593bb0a6a6732c25adc7ee901a303fd7dfdc3b0f618079f
|
data/lib/bitfab/client.rb
CHANGED
|
@@ -170,6 +170,11 @@ module Bitfab
|
|
|
170
170
|
# experiment group, applied when this replay creates the group or the group
|
|
171
171
|
# has no name yet. A group that already has a name keeps it. Requires
|
|
172
172
|
# experiment_group_id; passing it alone raises ArgumentError
|
|
173
|
+
# @param baseline_experiment_id [String, nil] optional UUID of an earlier
|
|
174
|
+
# experiment this run is compared against. It takes precedence over the
|
|
175
|
+
# first finished experiment in the group and over the original traces.
|
|
176
|
+
# It must belong to the caller's organization or the server rejects the
|
|
177
|
+
# replay
|
|
173
178
|
# @param dataset_ids [Array<String>, nil] optional UUIDs of the datasets this
|
|
174
179
|
# replay runs against, for benchmarking one method against several corpora
|
|
175
180
|
# in a single run; mutually exclusive with dataset_id. Passing trace_ids
|
|
@@ -234,7 +239,7 @@ module Bitfab
|
|
|
234
239
|
# @return [Hash] with :items, :experiment_id, :experiment_url, and the
|
|
235
240
|
# deprecated aliases :test_run_id and :test_run_url carrying the same values
|
|
236
241
|
def replay(receiver, method_name = nil, trace_function_key:, limit: nil, trace_ids: nil, concurrency: nil, max_concurrency: ReplayConcurrency::UNSET,
|
|
237
|
-
name: nil, notes: nil, metadata: nil, code_change: nil, code_change_description: nil, code_change_files: nil, code_change_base: nil, experiment_group_id: nil, experiment_group_name: nil, dataset_id: nil, dataset_ids: nil, grader_ids: nil, mock: "marked", attempts: ReplayConcurrency::UNSET, only_with_assertions: false, category_ids: nil, skip_assertion_judging: false, judge_assertions: nil, dry_run: false,
|
|
242
|
+
name: nil, notes: nil, metadata: nil, code_change: nil, code_change_description: nil, code_change_files: nil, code_change_base: nil, experiment_group_id: nil, experiment_group_name: nil, baseline_experiment_id: nil, dataset_id: nil, dataset_ids: nil, grader_ids: nil, mock: "marked", attempts: ReplayConcurrency::UNSET, only_with_assertions: false, category_ids: nil, skip_assertion_judging: false, judge_assertions: nil, dry_run: false,
|
|
238
243
|
adapt_inputs: nil, mock_override: nil, db_branch: nil, on_item_start: nil, on_item_finish: nil, on_progress: nil,
|
|
239
244
|
on_experiment_start: nil, experimental_selective_replay: nil)
|
|
240
245
|
Replay.run(
|
|
@@ -261,6 +266,7 @@ module Bitfab
|
|
|
261
266
|
code_change_base:,
|
|
262
267
|
experiment_group_id:,
|
|
263
268
|
experiment_group_name:,
|
|
269
|
+
baseline_experiment_id:,
|
|
264
270
|
dataset_id:,
|
|
265
271
|
dataset_ids:,
|
|
266
272
|
grader_ids:,
|
|
@@ -601,6 +607,7 @@ module Bitfab
|
|
|
601
607
|
error = nil
|
|
602
608
|
span_contexts = nil
|
|
603
609
|
span_prompt = nil
|
|
610
|
+
span_metadata = nil
|
|
604
611
|
completed = false
|
|
605
612
|
@http_client.trace_completion.start(trace_id, span_id)
|
|
606
613
|
recording_override = managed_root ? {} : nil
|
|
@@ -638,7 +645,7 @@ module Bitfab
|
|
|
638
645
|
end
|
|
639
646
|
|
|
640
647
|
on_complete&.call(result: recorded_result, error: recorded_error, ended_at:,
|
|
641
|
-
contexts: span_contexts, prompt: span_prompt)
|
|
648
|
+
contexts: span_contexts, prompt: span_prompt, metadata: span_metadata)
|
|
642
649
|
|
|
643
650
|
span_data = span_data.merge("replay_reusable" => replay_reusable)
|
|
644
651
|
output_json = finalize.nil? && !result.is_a?(Enumerator) && SelectiveReplay.fingerprint(final_result)
|
|
@@ -662,6 +669,7 @@ module Bitfab
|
|
|
662
669
|
function_name: recording_override&.dig(:function_name) || function_name,
|
|
663
670
|
contexts: span_contexts,
|
|
664
671
|
prompt: span_prompt,
|
|
672
|
+
metadata: span_metadata,
|
|
665
673
|
args:,
|
|
666
674
|
kwargs:,
|
|
667
675
|
result: recorded_result,
|
|
@@ -740,6 +748,7 @@ module Bitfab
|
|
|
740
748
|
# Capture contexts before the span context is popped
|
|
741
749
|
span_contexts = SpanContext.current&.dig(:contexts)
|
|
742
750
|
span_prompt = SpanContext.current&.dig(:prompt)
|
|
751
|
+
span_metadata = SpanContext.current&.dig(:metadata)
|
|
743
752
|
end
|
|
744
753
|
end
|
|
745
754
|
rescue => e
|
|
@@ -1049,7 +1058,7 @@ module Bitfab
|
|
|
1049
1058
|
|
|
1050
1059
|
def send_span(trace_function_key:, trace_id:, span_id:, parent_span_id:,
|
|
1051
1060
|
span_name:, span_type:, function_name:, contexts:, prompt:, args:, kwargs:, result:, error:,
|
|
1052
|
-
started_at:, ended_at:, experiment_id: nil, input_source_span_id: nil, mocked: false,
|
|
1061
|
+
started_at:, ended_at:, metadata: nil, experiment_id: nil, input_source_span_id: nil, mocked: false,
|
|
1053
1062
|
mock_target: nil, mock_source: nil, span_data: {}, instrumentation: "span", declared_node: false,
|
|
1054
1063
|
nearest_captured_ancestor_span_id: nil)
|
|
1055
1064
|
extra_span_data = span_data
|
|
@@ -1100,6 +1109,7 @@ module Bitfab
|
|
|
1100
1109
|
end
|
|
1101
1110
|
span_data["contexts"] = contexts if contexts&.any?
|
|
1102
1111
|
span_data["prompt"] = prompt if prompt && !content_off
|
|
1112
|
+
span_data["metadata"] = metadata if metadata&.any?
|
|
1103
1113
|
|
|
1104
1114
|
raw_span = {
|
|
1105
1115
|
"id" => span_id,
|
data/lib/bitfab/experiments.rb
CHANGED
|
@@ -30,6 +30,8 @@ module Bitfab
|
|
|
30
30
|
@http_client.get(query.empty? ? PATH : "#{PATH}?#{query}")
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
# Reads one experiment as a Hash. "baselineExperimentId" and "baselineExperimentName" name the earlier
|
|
34
|
+
# experiment set as this run's baseline, and are nil when none was set.
|
|
33
35
|
def get(id)
|
|
34
36
|
@http_client.get("#{PATH}/#{encode(id)}")["experiment"]
|
|
35
37
|
end
|
|
@@ -47,9 +49,10 @@ module Bitfab
|
|
|
47
49
|
|
|
48
50
|
# Reads one run's written summary. "status" is "pending" while the run has not finished or its verdicts are
|
|
49
51
|
# still arriving; the summary is written once every verdict is in. "unavailable" means the run ended failed or
|
|
50
|
-
# interrupted and no summary will be written. "ready" carries the summary, compared against the
|
|
51
|
-
# run
|
|
52
|
-
#
|
|
52
|
+
# interrupted and no summary will be written. "ready" carries the summary, compared against the experiment set
|
|
53
|
+
# as this run's baseline (baseline kind "chosen_experiment"), else the first finished run in the same
|
|
54
|
+
# experiment group for the same traced function ("group_experiment"), else the run's original traces
|
|
55
|
+
# ("original_traces").
|
|
53
56
|
def get_summary(id)
|
|
54
57
|
@http_client.get("#{PATH}/#{encode(id)}/summary")
|
|
55
58
|
end
|
data/lib/bitfab/http_client.rb
CHANGED
|
@@ -265,6 +265,8 @@ module Bitfab
|
|
|
265
265
|
# @param experiment_group_name [String, nil] optional display name for the
|
|
266
266
|
# experiment group, applied when this replay creates the group or the group
|
|
267
267
|
# has no name yet; only sent together with experiment_group_id
|
|
268
|
+
# @param baseline_experiment_id [String, nil] optional UUID of an earlier
|
|
269
|
+
# experiment this run is compared against, sent as baselineExperimentId
|
|
268
270
|
# @param name [String, nil] optional display name for the resulting
|
|
269
271
|
# experiment
|
|
270
272
|
# @param dataset_ids [Array<String>, nil] optional UUIDs of the datasets this
|
|
@@ -283,7 +285,7 @@ module Bitfab
|
|
|
283
285
|
# ArgumentError when empty or passed without a trace ID or dataset
|
|
284
286
|
# selection.
|
|
285
287
|
def start_replay(trace_function_key, limit, trace_ids: nil, code_change_type: nil, code_change_description: nil,
|
|
286
|
-
code_change_files: nil, experiment_group_id: nil, experiment_group_name: nil, name: nil, notes: nil, metadata: nil, include_db_branch_lease: false, dataset_ids: nil,
|
|
288
|
+
code_change_files: nil, experiment_group_id: nil, experiment_group_name: nil, baseline_experiment_id: nil, name: nil, notes: nil, metadata: nil, include_db_branch_lease: false, dataset_ids: nil,
|
|
287
289
|
grader_ids: nil, db_branch_settings: nil, attempts: 1, only_with_assertions: false, category_ids: nil, skip_assertion_judging: false, include_original_metadata: false, experimental_selective_replay: nil, dry_run: false, invocation: nil)
|
|
288
290
|
payload = {
|
|
289
291
|
"traceFunctionKey" => trace_function_key
|
|
@@ -300,6 +302,7 @@ module Bitfab
|
|
|
300
302
|
payload["codeChangeFiles"] = normalize_code_change_files(code_change_files) unless code_change_files.nil?
|
|
301
303
|
payload["experimentGroupId"] = experiment_group_id unless experiment_group_id.nil?
|
|
302
304
|
payload["experimentGroupName"] = experiment_group_name unless experiment_group_name.nil?
|
|
305
|
+
payload["baselineExperimentId"] = baseline_experiment_id unless baseline_experiment_id.nil?
|
|
303
306
|
payload["includeDbBranchLease"] = true if include_db_branch_lease
|
|
304
307
|
payload["lazyDbBranchLease"] = true if include_db_branch_lease
|
|
305
308
|
unless dataset_ids.nil?
|
data/lib/bitfab/replay.rb
CHANGED
|
@@ -256,6 +256,11 @@ module Bitfab
|
|
|
256
256
|
# experiment group, applied when this replay creates the group or the group
|
|
257
257
|
# has no name yet. A group that already has a name keeps it. Requires
|
|
258
258
|
# experiment_group_id; passing it alone raises ArgumentError
|
|
259
|
+
# @param baseline_experiment_id [String, nil] optional UUID of an earlier
|
|
260
|
+
# experiment this run is compared against. It takes precedence over the
|
|
261
|
+
# first finished experiment in the group and over the original traces.
|
|
262
|
+
# It must belong to the caller's organization or the server rejects the
|
|
263
|
+
# replay
|
|
259
264
|
# @param dataset_id [String, nil] optional UUID of the dataset this replay
|
|
260
265
|
# runs against, stored on the resulting experiment for durable attribution;
|
|
261
266
|
# mutually exclusive with dataset_ids. Alone it replays the dataset's full
|
|
@@ -321,7 +326,7 @@ module Bitfab
|
|
|
321
326
|
# The experiment fields are nil for a dry run, which creates no experiment,
|
|
322
327
|
# and progress events then carry a nil :experiment_id too.
|
|
323
328
|
def run(client, receiver, method_name, trace_function_key:, limit: nil, trace_ids: nil, name: nil, notes: nil, metadata: nil,
|
|
324
|
-
concurrency: nil, max_concurrency: ReplayConcurrency::UNSET, code_change: nil, code_change_description: nil, code_change_files: nil, code_change_base: nil, experiment_group_id: nil, experiment_group_name: nil,
|
|
329
|
+
concurrency: nil, max_concurrency: ReplayConcurrency::UNSET, code_change: nil, code_change_description: nil, code_change_files: nil, code_change_base: nil, experiment_group_id: nil, experiment_group_name: nil, baseline_experiment_id: nil,
|
|
325
330
|
dataset_id: nil, dataset_ids: nil, grader_ids: nil, mock: "marked", attempts: ReplayConcurrency::UNSET, only_with_assertions: false, category_ids: nil, skip_assertion_judging: false, judge_assertions: nil, dry_run: false,
|
|
326
331
|
adapt_inputs: nil, mock_override: nil, db_branch: nil, on_item_start: nil, on_item_finish: nil, on_progress: nil,
|
|
327
332
|
on_experiment_start: nil, experimental_selective_replay: nil)
|
|
@@ -420,6 +425,7 @@ module Bitfab
|
|
|
420
425
|
code_change_files:,
|
|
421
426
|
experiment_group_id:,
|
|
422
427
|
experiment_group_name:,
|
|
428
|
+
baseline_experiment_id:,
|
|
423
429
|
include_db_branch_lease:,
|
|
424
430
|
dataset_ids: resolved_dataset_ids,
|
|
425
431
|
grader_ids:,
|
|
@@ -19,7 +19,7 @@ module Bitfab
|
|
|
19
19
|
# Project-owned registry of production replay roots.
|
|
20
20
|
class ReplayRegistry
|
|
21
21
|
OPTION_NAMES = %i[
|
|
22
|
-
limit trace_ids name notes metadata concurrency max_concurrency experiment_group_id experiment_group_name dataset_id dataset_ids grader_ids mock
|
|
22
|
+
limit trace_ids name notes metadata concurrency max_concurrency experiment_group_id experiment_group_name baseline_experiment_id dataset_id dataset_ids grader_ids mock
|
|
23
23
|
mock_override adapt_inputs db_branch attempts only_with_assertions category_ids skip_assertion_judging judge_assertions dry_run on_item_finish
|
|
24
24
|
].freeze
|
|
25
25
|
|
|
@@ -206,7 +206,7 @@ module Bitfab
|
|
|
206
206
|
options[:limit] = bound || 10
|
|
207
207
|
end
|
|
208
208
|
|
|
209
|
-
%i[name notes metadata max_concurrency experiment_group_id experiment_group_name dataset_ids grader_ids mock attempts only_with_assertions category_ids skip_assertion_judging dry_run].each do |key|
|
|
209
|
+
%i[name notes metadata max_concurrency experiment_group_id experiment_group_name baseline_experiment_id dataset_ids grader_ids mock attempts only_with_assertions category_ids skip_assertion_judging dry_run].each do |key|
|
|
210
210
|
options[key] = args[key] unless args[key].nil?
|
|
211
211
|
end
|
|
212
212
|
|
|
@@ -375,6 +375,9 @@ module Bitfab
|
|
|
375
375
|
options.on("--experiment-group-name NAME",
|
|
376
376
|
"Name the experiment group when this run creates it or it has no name yet. " \
|
|
377
377
|
"A group that already has a name keeps it. Requires --experiment-group-id.") { |value| args[:experiment_group_name] = value }
|
|
378
|
+
options.on("--baseline-experiment-id UUID",
|
|
379
|
+
"Compare this run against an earlier experiment instead of the group's first finished run " \
|
|
380
|
+
"or the original traces.") { |value| args[:baseline_experiment_id] = value }
|
|
378
381
|
options.on("--dataset-ids IDS", "--dataset-id IDS") { |value| args[:dataset_ids] = comma_separated("--dataset-ids", value) }
|
|
379
382
|
options.on("--grader-ids IDS") { |value| args[:grader_ids] = comma_separated("--grader-ids", value) }
|
|
380
383
|
options.on("--attempts N", Integer) { |value| args[:attempts] = positive_integer("--attempts", value) }
|
data/lib/bitfab/span_context.rb
CHANGED
|
@@ -55,6 +55,23 @@ module Bitfab
|
|
|
55
55
|
rescue
|
|
56
56
|
# Silently ignore - never crash the host app
|
|
57
57
|
end
|
|
58
|
+
|
|
59
|
+
# Merge metadata into this span, with later values for a key winning. Use
|
|
60
|
+
# it to label what the span did, for example { "delivery" => "blocked" } on
|
|
61
|
+
# a message that was drafted but never sent. Values must be strings,
|
|
62
|
+
# numbers, or booleans; keys are 1 to 40 of A-Z a-z 0-9 _ . : -. Bitfab
|
|
63
|
+
# stores keys and values lowercased, returns them on spans.list, and
|
|
64
|
+
# narrows that list with its metadata filter. Sent even when content
|
|
65
|
+
# capture is off, like trace metadata.
|
|
66
|
+
#
|
|
67
|
+
# @param metadata [Hash] key-value pairs to merge into the span's metadata
|
|
68
|
+
def set_metadata(metadata)
|
|
69
|
+
return unless metadata.is_a?(Hash)
|
|
70
|
+
|
|
71
|
+
@span_state[:metadata] = (@span_state[:metadata] || {}).merge(metadata)
|
|
72
|
+
rescue
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
58
75
|
end
|
|
59
76
|
|
|
60
77
|
# Handle to the current active trace, allowing trace-level context to be set.
|
data/lib/bitfab/spans.rb
CHANGED
|
@@ -2,18 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
module Bitfab
|
|
4
4
|
class Spans
|
|
5
|
+
MAX_PAGE_SIZE = 200
|
|
6
|
+
MAX_PAGE_SIZE_WITH_FIELDS = 50
|
|
7
|
+
private_constant :MAX_PAGE_SIZE, :MAX_PAGE_SIZE_WITH_FIELDS
|
|
8
|
+
|
|
5
9
|
def initialize(http_client)
|
|
6
10
|
@http_client = http_client
|
|
7
11
|
end
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
# One page of a trace's spans in the order they ran. Each span carries its
|
|
14
|
+
# "metadata" Hash, keys and values lowercased, empty when none was set.
|
|
15
|
+
# metadata: keeps only spans whose metadata holds every given key with that
|
|
16
|
+
# value, matched exactly and case-insensitively, up to 10 keys. limit is 1
|
|
17
|
+
# to 200, or at most 50 when fields are requested; a larger value raises
|
|
18
|
+
# with the server's reason. Use list_all to read every span.
|
|
19
|
+
def list(trace_id, span_type: nil, span_name: nil, metadata: nil, fields: nil, cursor: nil, limit: nil)
|
|
10
20
|
payload = {"traceId" => trace_id}
|
|
11
21
|
payload["spanType"] = span_type unless span_type.nil?
|
|
12
22
|
payload["spanName"] = span_name unless span_name.nil?
|
|
23
|
+
payload["metadata"] = metadata unless metadata.nil?
|
|
13
24
|
payload["fields"] = fields unless fields.nil?
|
|
14
25
|
payload["cursor"] = cursor unless cursor.nil?
|
|
15
26
|
payload["limit"] = limit unless limit.nil?
|
|
16
27
|
@http_client.request("/api/sdk/spans/list", payload)
|
|
17
28
|
end
|
|
29
|
+
|
|
30
|
+
# Every span of one trace in the order they ran, fetched page by page until
|
|
31
|
+
# none are left. Takes the same filters as list. Pages hold 200 spans, or 50
|
|
32
|
+
# when fields are requested.
|
|
33
|
+
def list_all(trace_id, span_type: nil, span_name: nil, metadata: nil, fields: nil)
|
|
34
|
+
limit = (fields.nil? || fields.empty?) ? MAX_PAGE_SIZE : MAX_PAGE_SIZE_WITH_FIELDS
|
|
35
|
+
spans = []
|
|
36
|
+
cursor = nil
|
|
37
|
+
loop do
|
|
38
|
+
page = list(trace_id, span_type:, span_name:, metadata:, fields:, cursor:, limit:)
|
|
39
|
+
spans.concat(page["spans"] || [])
|
|
40
|
+
cursor = page["hasMore"] ? page["nextCursor"] : nil
|
|
41
|
+
break if cursor.nil?
|
|
42
|
+
end
|
|
43
|
+
spans
|
|
44
|
+
end
|
|
18
45
|
end
|
|
19
46
|
end
|
data/lib/bitfab/subtree.rb
CHANGED
|
@@ -54,6 +54,7 @@ module Bitfab
|
|
|
54
54
|
:declared_node,
|
|
55
55
|
:contexts,
|
|
56
56
|
:prompt,
|
|
57
|
+
:metadata,
|
|
57
58
|
:jev_started_at,
|
|
58
59
|
:jev_recorded_below
|
|
59
60
|
)
|
|
@@ -152,7 +153,7 @@ module Bitfab
|
|
|
152
153
|
span_id: @owner.current_parent_span_id, surface: :trace, &body)
|
|
153
154
|
end
|
|
154
155
|
|
|
155
|
-
def complete(result:, error:, ended_at:, contexts: nil, prompt: nil)
|
|
156
|
+
def complete(result:, error:, ended_at:, contexts: nil, prompt: nil, metadata: nil)
|
|
156
157
|
return if @completed
|
|
157
158
|
|
|
158
159
|
@completed = true
|
|
@@ -162,6 +163,7 @@ module Bitfab
|
|
|
162
163
|
entry.error = error
|
|
163
164
|
entry.contexts = contexts
|
|
164
165
|
entry.prompt = prompt
|
|
166
|
+
entry.metadata = metadata
|
|
165
167
|
session.emit_configured(entry, result:)
|
|
166
168
|
end
|
|
167
169
|
end
|
|
@@ -767,6 +769,7 @@ module Bitfab
|
|
|
767
769
|
function_name: entry.name,
|
|
768
770
|
contexts: entry.contexts,
|
|
769
771
|
prompt: entry.prompt,
|
|
772
|
+
metadata: entry.metadata,
|
|
770
773
|
args: entry.args,
|
|
771
774
|
kwargs: entry.kwargs,
|
|
772
775
|
result:,
|
data/lib/bitfab/version.rb
CHANGED
data/lib/bitfab.rb
CHANGED