bitfab 0.36.11 → 0.38.0

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: 0d23fea40d370a085bd028fbf7b605a6b66bc0732a1580683b3f027b5b2082e9
4
- data.tar.gz: a477ee5856fc6fb25a39a6088f820337cd2bcb327c3b028c9051d0b0f84edd5d
3
+ metadata.gz: e4bb59de5ab0ec989d85e8be14ee08ad935ada5145e01826b34657fc8c9e6623
4
+ data.tar.gz: 78b0255c5a3062470f4149baf632c94a5b18b430567485a1ba58f5b9cf9b9534
5
5
  SHA512:
6
- metadata.gz: bb155e9ec03187b1f9f80a918b8df651bab41e181afcdd5c068c9645ab6b9c94884d7f8c41cab43bd50e878226e3d075962c02ac27e2b33ed2729e979b4e4464
7
- data.tar.gz: 1da28622e46e44b40f5296ed699ee13e897e7bd0a54177e32f3c629fb8004ea5f87a86546a37d608541ff771ba648fffb128bd613d7aefea300c8898038c7e47
6
+ metadata.gz: e127f198a39372bebaff5a0cf395b4b6b00f2ede4bf9768b8e3a4556ee00271ddf44fe4a40f16fcffac72d3def4d3c83c3f756801ba156edbe58ecbfd189f2e5
7
+ data.tar.gz: ca803b3df3783f6bb01d5eb5a518300334d0ccd4f31d43f3870c981779cd69710d076a1ded3f058c3b9e8aa65f643b3872dd60f99ac8e4394cd5f97855ec1970
data/lib/bitfab/client.rb CHANGED
@@ -424,7 +424,12 @@ module Bitfab
424
424
  # Deprecated wire alias, kept so this SDK still reports usage
425
425
  # against servers that predate the rename.
426
426
  source_trace_id: replay_ctx[:source_bitfab_trace_id],
427
- accessed: replay_ctx[:db_snapshot_accessed] == true
427
+ accessed: replay_ctx[:db_snapshot_accessed] == true,
428
+ # Echoed verbatim (camelCase inside) rather than re-cased into
429
+ # this record's snake_case: it is the server's own object
430
+ # coming back, and a translation layer here is one more thing
431
+ # to drift.
432
+ timings: replay_ctx[:db_branch_timings]
428
433
  }
429
434
  end
430
435
 
@@ -617,6 +622,9 @@ module Bitfab
617
622
  usage["source_trace_id"] = db_snapshot_usage[:original_trace_id]
618
623
  end
619
624
  usage["accessed"] = db_snapshot_usage[:accessed]
625
+ if db_snapshot_usage[:timings]
626
+ usage["timings"] = db_snapshot_usage[:timings]
627
+ end
620
628
  raw_trace["db_snapshot_usage"] = usage
621
629
  end
622
630
 
data/lib/bitfab/replay.rb CHANGED
@@ -74,7 +74,7 @@ module Bitfab
74
74
  # thread. Child threads and processes intentionally do not inherit it.
75
75
  def with_context(test_run_id:, input_source_span_id: nil, input_source_trace_id: nil, trace_id: nil,
76
76
  mock_tree: nil, mock_strategy: nil, mock_overrides: nil, fetch_span_output: nil,
77
- db_branch_lease: nil, source_bitfab_trace_id: nil)
77
+ db_branch_lease: nil, db_branch_timings: nil, source_bitfab_trace_id: nil)
78
78
  previous = Thread.current.thread_variable_get(REPLAY_CONTEXT_KEY)
79
79
  ctx = {
80
80
  test_run_id:,
@@ -113,6 +113,10 @@ module Bitfab
113
113
  # accessed for free, and the flag would stop separating "branch was
114
114
  # used" from "branch was offered".
115
115
  ctx[:db_branch_lease] = db_branch_lease if db_branch_lease
116
+ # Kept off ReplayBranch: customer code reads that mid-replay to reach the
117
+ # branch, and provisioning latency is a property of the run, not of the
118
+ # connection. It rides the context only to be echoed on the completion.
119
+ ctx[:db_branch_timings] = db_branch_timings if db_branch_timings
116
120
  ctx[:source_bitfab_trace_id] = source_bitfab_trace_id if source_bitfab_trace_id
117
121
  Thread.current.thread_variable_set(REPLAY_CONTEXT_KEY, ctx)
118
122
  yield
@@ -765,9 +769,13 @@ module Bitfab
765
769
  trace_error: result[:trace_error],
766
770
  replay_error: result[:replay_error],
767
771
  duration_ms: result[:duration_ms],
772
+ original_duration_ms: result[:original_duration_ms],
773
+ original_tokens: result[:original_tokens],
774
+ original_model: result[:original_model],
768
775
  tokens: result[:tokens],
769
776
  model: result[:model],
770
- db_snapshot_ref: result[:db_snapshot_ref]
777
+ db_snapshot_ref: result[:db_snapshot_ref],
778
+ db_branch_timings: result[:db_branch_timings]
771
779
  }
772
780
  })
773
781
  rescue => e
@@ -836,6 +844,9 @@ module Bitfab
836
844
  # result that looks valid and is not. Fail the item instead, loudly.
837
845
  lease_error = include_db_branch_lease ? server_item["dbBranchLeaseError"] : nil
838
846
  db_snapshot_ref = server_item["dbSnapshotRef"]
847
+ # Reported whichever way the resolve went, so it is tracked separately
848
+ # from both the lease and the error rather than hanging off either.
849
+ db_branch_timings = include_db_branch_lease ? server_item["dbBranchTimings"] : nil
839
850
  if include_db_branch_lease && lease.nil? && lease_error.nil?
840
851
  begin
841
852
  resolved = http_client.resolve_db_branch_lease(test_run_id, original_trace_id, db_branch_settings)
@@ -850,6 +861,7 @@ module Bitfab
850
861
  lease = resolved["lease"]
851
862
  lease_error = resolved["leaseError"]
852
863
  db_snapshot_ref = resolved["dbSnapshotRef"] || db_snapshot_ref
864
+ db_branch_timings = resolved["timings"] || db_branch_timings
853
865
  end
854
866
  if lease_error
855
867
  raise DbBranchReplayError.new(
@@ -923,6 +935,7 @@ module Bitfab
923
935
  adapt_inputs:,
924
936
  adapt_ctx:,
925
937
  db_branch_lease: lease,
938
+ db_branch_timings:,
926
939
  source_bitfab_trace_id: original_trace_id,
927
940
  db_snapshot_ref:,
928
941
  http_client:
@@ -936,16 +949,20 @@ module Bitfab
936
949
  error: replay_item_error_message(e),
937
950
  trace_error: nil,
938
951
  replay_error: e,
939
- duration_ms: metrics&.dig(:duration_ms),
952
+ duration_ms: nil,
953
+ original_duration_ms: metrics&.dig(:original_duration_ms),
954
+ original_tokens: metrics&.dig(:original_tokens),
955
+ original_model: metrics&.dig(:original_model),
940
956
  tokens: metrics&.dig(:tokens),
941
- model: metrics&.dig(:model),
957
+ model: metrics&.dig(:original_model),
942
958
  trace_id: nil,
943
959
  original_trace_id:,
944
960
  original_span_id:,
945
961
  # Deprecated aliases for original_trace_id/original_span_id.
946
962
  source_trace_id: original_trace_id,
947
963
  source_span_id: original_span_id,
948
- db_snapshot_ref:
964
+ db_snapshot_ref:,
965
+ db_branch_timings:
949
966
  }
950
967
  ensure
951
968
  release_db_branch_lease(http_client, lease) if lease
@@ -1059,11 +1076,15 @@ module Bitfab
1059
1076
  # the ORIGINAL trace's tokens); the replayed run's tokens are filled in by
1060
1077
  # run() from the complete-replay response once spans are aggregated
1061
1078
  # server-side, and stay nil here and on older servers.
1079
+ # The original trace's measurements, falling back to the unprefixed keys a
1080
+ # server that predates the rename sends. :tokens stays nil here: it is the
1081
+ # REPLAYED run's, filled in from the complete-replay response.
1062
1082
  def extract_server_item_metrics(server_item)
1063
1083
  {
1064
- duration_ms: server_item["durationMs"],
1065
- tokens: nil,
1066
- model: server_item["model"]
1084
+ original_duration_ms: server_item["originalDurationMs"] || server_item["durationMs"],
1085
+ original_tokens: server_item["originalTokens"] || server_item["tokens"],
1086
+ original_model: server_item["originalModel"] || server_item["model"],
1087
+ tokens: nil
1067
1088
  }
1068
1089
  end
1069
1090
 
@@ -1144,13 +1165,15 @@ module Bitfab
1144
1165
  # Execute a single replay item: deserialize inputs, call method with replay context.
1145
1166
  def execute_item(item, receiver, method_name, test_run_id, input_source_span_id = nil, metrics = {},
1146
1167
  input_source_trace_id: nil, mock_strategy: "marked", mock_tree: nil, mock_overrides: nil,
1147
- fetch_span_output: nil, adapt_inputs: nil, adapt_ctx: nil, db_branch_lease: nil, source_bitfab_trace_id: nil,
1148
- db_snapshot_ref: nil, http_client: nil)
1168
+ fetch_span_output: nil, adapt_inputs: nil, adapt_ctx: nil, db_branch_lease: nil, db_branch_timings: nil,
1169
+ source_bitfab_trace_id: nil, db_snapshot_ref: nil, http_client: nil)
1149
1170
  args, kwargs = Serialize.deserialize_inputs(item)
1150
1171
 
1151
1172
  fn_result = nil
1152
1173
  fn_error = nil
1153
1174
  replay_error = nil
1175
+ replay_duration_ms = nil
1176
+ replay_started = nil
1154
1177
  # Client-side correlation id that tags this item's replay spans so the
1155
1178
  # server can echo back the row id it minted (resolved in run()'s
1156
1179
  # complete-replay loop). Carried on the item under :_sdk_trace_id, never
@@ -1172,6 +1195,7 @@ module Bitfab
1172
1195
  mock_overrides:,
1173
1196
  fetch_span_output:,
1174
1197
  db_branch_lease:,
1198
+ db_branch_timings:,
1175
1199
  source_bitfab_trace_id:
1176
1200
  ) do
1177
1201
  begin
@@ -1190,17 +1214,26 @@ module Bitfab
1190
1214
  end
1191
1215
  if replay_error.nil?
1192
1216
  begin
1217
+ replay_started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
1193
1218
  fn_result = if kwargs.empty?
1194
1219
  receiver.send(method_name, *args)
1195
1220
  else
1196
1221
  receiver.send(method_name, *args, **kwargs)
1197
1222
  end
1223
+ replay_duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - replay_started) * 1000).round
1198
1224
  rescue => e
1225
+ # The method ran and raised, so it still has a duration.
1226
+ if replay_started
1227
+ replay_duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - replay_started) * 1000).round
1228
+ end
1199
1229
  fn_error = e
1200
1230
  end
1201
1231
  end
1202
1232
  end
1203
1233
  rescue => e
1234
+ if replay_started
1235
+ replay_duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - replay_started) * 1000).round
1236
+ end
1204
1237
  replay_error = e
1205
1238
  end
1206
1239
 
@@ -1212,9 +1245,12 @@ module Bitfab
1212
1245
  error: item_error&.message,
1213
1246
  trace_error: fn_error,
1214
1247
  replay_error:,
1215
- duration_ms: metrics[:duration_ms],
1248
+ duration_ms: replay_duration_ms,
1249
+ original_duration_ms: metrics[:original_duration_ms],
1250
+ original_tokens: metrics[:original_tokens],
1251
+ original_model: metrics[:original_model],
1216
1252
  tokens: metrics[:tokens],
1217
- model: metrics[:model],
1253
+ model: metrics[:original_model],
1218
1254
  # Written in by run() from the complete-replay response once the server
1219
1255
  # has minted this replay trace's row. Nil until then: the client-side
1220
1256
  # correlation id (below) is never surfaced as the public :trace_id.
@@ -1225,7 +1261,8 @@ module Bitfab
1225
1261
  # Deprecated aliases for original_trace_id/original_span_id.
1226
1262
  source_trace_id: source_bitfab_trace_id,
1227
1263
  source_span_id: input_source_span_id,
1228
- db_snapshot_ref:
1264
+ db_snapshot_ref:,
1265
+ db_branch_timings:
1229
1266
  }
1230
1267
  end
1231
1268
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.36.11"
4
+ VERSION = "0.38.0"
5
5
  end
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.36.11
4
+ version: 0.38.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team